Skip to content

Commit

Permalink
store required user roles for feature access in REQUIRED_USER_ROLES_F…
Browse files Browse the repository at this point in the history
…OR variable

Centralize the roles required for accessing different views, user profiles, and features within the REQUIRED_USER_ROLES_FOR variable. This allows for easier maintenance and role-checking across the application.

Signed-off-by: nncluzu <ngamenichaka@yahoo.fr>
  • Loading branch information
kmer2016 authored and RomainValls committed Oct 28, 2024
1 parent 509ec01 commit fe6a292
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions front/src/applications/stdcm/components/StdcmHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cx from 'classnames';
import { useTranslation } from 'react-i18next';

import RoleBasedContent from 'common/authorization/components/RoleBasedContent';
import { REQUIRED_USER_ROLES_FOR } from 'common/authorization/roleBaseAccessControl';

type StdcmHeaderProps = {
isDebugMode: boolean;
Expand All @@ -20,8 +21,8 @@ const StdcmHeader = ({ isDebugMode, onDebugModeToggle }: StdcmHeaderProps) => {
{t('notificationTitle')}
</span>
</div>
<RoleBasedContent requiredRoles={['Superuser']}>
<div className="stdcm-header_debug">
<RoleBasedContent requiredRoles={REQUIRED_USER_ROLES_FOR.FEATURES.ACCESS_STDCM_DEBUG}>
<div className="stdcm-v2-header_debug">
<button
type="button"
aria-label="stdcm-debug"
Expand Down
6 changes: 5 additions & 1 deletion front/src/common/AddNewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import { FaPlus } from 'react-icons/fa';

import RoleBasedContent from './authorization/components/RoleBasedContent';
import { REQUIRED_USER_ROLES_FOR } from './authorization/roleBaseAccessControl';
import { useModal } from './BootstrapSNCF/ModalSNCF';

type AddNewCardProps = {
Expand All @@ -25,7 +26,10 @@ const AddNewCard = ({
const { openModal } = useModal();

return (
<RoleBasedContent requiredRoles={['OpsWrite']} disableIfUnauthorized>
<RoleBasedContent
requiredRoles={REQUIRED_USER_ROLES_FOR.FEATURES.CREATE_NEW_PROJECT_STUDY_SCENARIO}
disableIfUnauthorized
>
<div
data-testid={testId}
className={className}
Expand Down
8 changes: 8 additions & 0 deletions front/src/common/authorization/roleBaseAccessControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export type RequiredUserRolesFor = {
STDCM: BuiltinRole[];
OPERATIONAL_STUDIES: BuiltinRole[];
};
FEATURES: {
ACCESS_STDCM_DEBUG: BuiltinRole[];
CREATE_NEW_PROJECT_STUDY_SCENARIO: BuiltinRole[];
};
};

export const REQUIRED_USER_ROLES_FOR: RequiredUserRolesFor = {
Expand Down Expand Up @@ -47,4 +51,8 @@ export const REQUIRED_USER_ROLES_FOR: RequiredUserRolesFor = {
'DocumentWrite',
],
},
FEATURES: {
ACCESS_STDCM_DEBUG: ['Superuser'],
CREATE_NEW_PROJECT_STUDY_SCENARIO: ['OpsWrite'],
},
};

0 comments on commit fe6a292

Please sign in to comment.