Skip to content

Commit

Permalink
feat: role manage super user
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmagnus committed Feb 26, 2024
1 parent 91ab1ee commit 5b924b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions frontend/src/app/core/pages/roles-manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export const RolesManage: React.FC = () => {
updateRole,
deleteRole,
getProfile,
getUserPermissions,
creatingRole,
updatingRole,
roles,
loadingRoles,
deletingRole,
userPermissions
} = useAuth()

const toast = useToast()
Expand All @@ -33,6 +35,10 @@ export const RolesManage: React.FC = () => {
getRoles()
}, [getRoles])

useEffect(() => {
getUserPermissions()
}, [getUserPermissions])

const handleRole = async (name: string, id?: number): Promise<boolean> => {
try {
const profile = await getProfile()
Expand Down Expand Up @@ -124,6 +130,7 @@ export const RolesManage: React.FC = () => {
updatingRole={updatingRole}
deletingRole={deletingRole}
loadingRoles={loadingRoles}
userPermissions={userPermissions}
handleDeleteRole={handleDeleteRole}
handleRole={handleRole}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IRolesManageTemplate {
creatingRole: boolean
updatingRole: boolean
deletingRole: boolean
userPermissions: Hooks.UseAuthTypes.IUserPermission | undefined
handleRole(name: string, id?: number): Promise<boolean>
handleDeleteRole(id: number, idNewUsersRole: number): Promise<boolean>
}
Expand All @@ -38,6 +39,7 @@ export const RolesManageTemplate: React.FC<IRolesManageTemplate> = ({
updatingRole,
deletingRole,
loadingRoles,
userPermissions,
handleRole,
handleDeleteRole,
}) => {
Expand Down Expand Up @@ -114,6 +116,7 @@ export const RolesManageTemplate: React.FC<IRolesManageTemplate> = ({
loading={creatingRole || updatingRole || deletingRole}
roles={roles}
loadingRoles={loadingRoles}
userPermissions={userPermissions}
handleRole={handleRole}
handleDeleteRole={handleDeleteRole}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IItemRole {
roles: Hooks.UseAuthTypes.IRole[] | undefined
loading: boolean
loadingRoles: boolean
userPermissions: Hooks.UseAuthTypes.IUserPermission | undefined
handleRole(name: string, id?: number): Promise<boolean>
handleDeleteRole(id: number, idNewUsersRole: number): Promise<boolean>
}
Expand All @@ -22,6 +23,7 @@ export const ItemRole: React.FC<IItemRole> = ({
roles,
loading,
loadingRoles,
userPermissions,
handleRole,
handleDeleteRole,
}) => {
Expand All @@ -38,7 +40,10 @@ export const ItemRole: React.FC<IItemRole> = ({
} = useDisclosure()

const isDisabled = (role: Hooks.UseAuthTypes.IRole): boolean => {
return role.admin === 1 || role.created_by != Authentication.getUser()?.id
if (userPermissions?.admin) {
return false
}
return role.created_by != Authentication.getUser()?.id
}

return (
Expand Down

0 comments on commit 5b924b1

Please sign in to comment.