Skip to content

Conversation

@potter-sun
Copy link

@potter-sun potter-sun commented Nov 13, 2025

#220
Non-admin users encounter errors when viewing roles and users after logging in.

Should non-admin users have their viewing permissions controlled via the UI?

Fixed by AI

@vercel
Copy link

vercel bot commented Nov 13, 2025

@potter-sun is attempting to deploy a commit to the Anto Subash's projects Team on Vercel.

A member of the Team first needs to authorize it.

@potter-sun potter-sun changed the title this project lacks different UI elements to display based on user permissions feature: add permission control to navbar Nov 13, 2025
@antosubash antosubash requested a review from Copilot November 20, 2025 20:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements permission-based access control for navigation menu items to prevent non-admin users from encountering errors when accessing restricted pages like roles and users.

Key Changes:

  • Added permission policies to menu configuration items with automatic filtering based on user permissions
  • Integrated permission checking in both desktop and mobile navigation components
  • Removed unused import from RoleList component

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/src/config.ts Added policy fields to AdminMenus configuration with specific permissions for each menu item
src/src/components/role/RoleList.tsx Removed unused RolePermission import
src/src/components/navbar/side-nav-bar.tsx Implemented permission filtering logic for desktop navigation menu
src/src/components/navbar/side-nav-bar-mobile.tsx Implemented permission filtering logic for mobile navigation menu

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Menu without policy or with permission is visible
return true
})
}, [can])
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useMemo dependency array is incomplete. It should include 'AdminMenus' to recompute when the menu configuration changes. Add AdminMenus to the dependencies: }, [can, AdminMenus])

Suggested change
}, [can])
}, [can, AdminMenus])

Copilot uses AI. Check for mistakes.
// Menu without policy or with permission is visible
return true
})
}, [can])
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useMemo dependency array is incomplete. It should include 'AdminMenus' to recompute when the menu configuration changes. Add AdminMenus to the dependencies: }, [can, AdminMenus])

Suggested change
}, [can])
}, [can, AdminMenus])

Copilot uses AI. Check for mistakes.
const pathname = usePathname()
const { can } = useGrantedPolicies()
const currentUser = useCurrentUser()
const isAdmin = currentUser?.roles?.includes(USER_ROLE.ADMIN) ?? false
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isAdmin variable is computed but never used in the component logic. It only appears in the JSX for displaying the admin badge. Consider removing it if the badge is purely cosmetic, or use it in the permission logic if admin users should bypass permission checks.

Suggested change
const isAdmin = currentUser?.roles?.includes(USER_ROLE.ADMIN) ?? false

Copilot uses AI. Check for mistakes.
const sessionData = useSession()
const { can } = useGrantedPolicies()
const currentUser = useCurrentUser()
const isAdmin = currentUser?.roles?.includes(USER_ROLE.ADMIN) ?? false
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isAdmin variable is computed but never used in the component logic. It only appears in the JSX for displaying the admin badge. Consider removing it if the badge is purely cosmetic, or use it in the permission logic if admin users should bypass permission checks.

Suggested change
const isAdmin = currentUser?.roles?.includes(USER_ROLE.ADMIN) ?? false

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant