feat: new permission to allow users to see other users requests

closes #840
This commit is contained in:
sct
2021-02-04 12:40:00 +00:00
parent 06e941171a
commit 033ba9d41b
8 changed files with 62 additions and 20 deletions

View File

@@ -1,5 +1,9 @@
import useSwr from 'swr';
import { hasPermission, Permission } from '../../server/lib/permissions';
import {
hasPermission,
Permission,
PermissionCheckOptions,
} from '../../server/lib/permissions';
import { UserType } from '../../server/constants/user';
export { Permission, UserType };
@@ -20,7 +24,10 @@ interface UserHookResponse {
loading: boolean;
error: string;
revalidate: () => Promise<boolean>;
hasPermission: (permission: Permission | Permission[]) => boolean;
hasPermission: (
permission: Permission | Permission[],
options?: PermissionCheckOptions
) => boolean;
}
export const useUser = ({
@@ -37,8 +44,11 @@ export const useUser = ({
}
);
const checkPermission = (permission: Permission | Permission[]): boolean => {
return hasPermission(permission, data?.permissions ?? 0);
const checkPermission = (
permission: Permission | Permission[],
options?: PermissionCheckOptions
): boolean => {
return hasPermission(permission, data?.permissions ?? 0, options);
};
return {