| import { useMemo } from 'react'; |
| import { PermissionTypes, PrincipalType, Permissions } from 'librechat-data-provider'; |
| import { useHasAccess } from '~/hooks'; |
|
|
| |
| |
| |
| |
| export const usePeoplePickerPermissions = () => { |
| const canViewUsers = useHasAccess({ |
| permissionType: PermissionTypes.PEOPLE_PICKER, |
| permission: Permissions.VIEW_USERS, |
| }); |
|
|
| const canViewGroups = useHasAccess({ |
| permissionType: PermissionTypes.PEOPLE_PICKER, |
| permission: Permissions.VIEW_GROUPS, |
| }); |
|
|
| const canViewRoles = useHasAccess({ |
| permissionType: PermissionTypes.PEOPLE_PICKER, |
| permission: Permissions.VIEW_ROLES, |
| }); |
|
|
| const hasPeoplePickerAccess = canViewUsers || canViewGroups || canViewRoles; |
|
|
| const peoplePickerTypeFilter: Array< |
| PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE |
| > | null = useMemo(() => { |
| const allowedTypes: Array<PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE> = []; |
|
|
| if (canViewUsers) { |
| allowedTypes.push(PrincipalType.USER); |
| } |
| if (canViewGroups) { |
| allowedTypes.push(PrincipalType.GROUP); |
| } |
| if (canViewRoles) { |
| allowedTypes.push(PrincipalType.ROLE); |
| } |
|
|
| |
| |
| if (allowedTypes.length === 0 || allowedTypes.length === 3) { |
| return null; |
| } |
|
|
| return allowedTypes; |
| }, [canViewUsers, canViewGroups, canViewRoles]); |
|
|
| return { |
| canViewUsers, |
| canViewRoles, |
| canViewGroups, |
| hasPeoplePickerAccess, |
| peoplePickerTypeFilter, |
| }; |
| }; |
|
|