diff --git a/front/src/common/authorization/components/PermissionBasedContent.tsx b/front/src/common/authorization/components/PermissionBasedContent.tsx index 490f4280b07..55841964953 100644 --- a/front/src/common/authorization/components/PermissionBasedContent.tsx +++ b/front/src/common/authorization/components/PermissionBasedContent.tsx @@ -1,14 +1,24 @@ import useUserPermissionsCheck from '../hooks/useUserPermissionsCheck'; export type PermissionBasedContentProps = { - requiredPermissions: string[]; + minimalPermission: string; + ressourceId: string; + ressourceType: string; children: React.ReactNode; }; -const PermissionBasedContent = ({ requiredPermissions, children }: PermissionBasedContentProps) => { - const hasRequiredPermissions = useUserPermissionsCheck(requiredPermissions); +const PermissionBasedContent = ({ + minimalPermission, + ressourceId, + ressourceType, + children, +}: PermissionBasedContentProps) => { + const hasMinimalPermission = useUserPermissionsCheck( + { id: ressourceId, type: ressourceType }, + minimalPermission + ); - if (hasRequiredPermissions) { + if (hasMinimalPermission) { return children; } diff --git a/front/src/common/authorization/components/ProtectedRoute.tsx b/front/src/common/authorization/components/ProtectedRoute.tsx index 8598c7e56e0..5f690398d55 100644 --- a/front/src/common/authorization/components/ProtectedRoute.tsx +++ b/front/src/common/authorization/components/ProtectedRoute.tsx @@ -2,19 +2,16 @@ import React from 'react'; import { Navigate } from 'react-router-dom'; -import useUserPermissionsCheck from '../hooks/useUserPermissionsCheck'; import useUserRoleCheck from '../hooks/useUserRoleCheck'; type ProtectedRouteProps = { allowedRoles?: string[]; - requiredPermissions?: string[]; children: React.ReactNode; }; -const ProtectedRoute = ({ allowedRoles, requiredPermissions, children }: ProtectedRouteProps) => { +const ProtectedRoute = ({ allowedRoles, children }: ProtectedRouteProps) => { const isRoleAllowed = useUserRoleCheck(allowedRoles); - const hasRequiredPermissions = useUserPermissionsCheck(requiredPermissions); - if (!isRoleAllowed || !hasRequiredPermissions) { + if (!isRoleAllowed) { return ; } diff --git a/front/src/common/authorization/hooks/useUserPermissionsCheck.ts b/front/src/common/authorization/hooks/useUserPermissionsCheck.ts index d72378a76db..4fee26e8837 100644 --- a/front/src/common/authorization/hooks/useUserPermissionsCheck.ts +++ b/front/src/common/authorization/hooks/useUserPermissionsCheck.ts @@ -1,13 +1,14 @@ -const useUserPermissionsCheck = (requiredPermissions: string[] = []) => { - if (requiredPermissions.length === 0) { +const useUserPermissionsCheck = ( + _ressource: { id: string; type: string }, + minimalPermission?: string +) => { + if (!minimalPermission) { return true; } // TODO AUTH: - // - get user permissions when it is implemented - // - uncomment when user roles and permission are implemented - // const userPermissions: string[] = []; - // return requiredPermissions.every((permission) => userPermissions.includes(permission)) + // - get user permissions on ressource when it is implemented + // - check if user has the minimal permission return true; };