Skip to content

Commit

Permalink
ORV2-2124 Add PPC_CLERK as allowed auth group to BCeID routes (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan-aot authored Mar 19, 2024
1 parent 4741593 commit 5082c69
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
12 changes: 6 additions & 6 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,23 @@ export const isIDIR = (identityProvider: string) =>

export const BCeIDAuthWall = ({
requiredRole,
allowedAuthGroups,
allowedIDIRAuthGroups,
}: {
requiredRole?: UserRolesType;
/**
* The collection of auth groups allowed to have access to a page or action.
* IDIR System Admin is assumed to be allowed regardless of it being passed.
* If not provided, only a System Admin will be allowed to access.
*/
allowedAuthGroups?: IDIRUserAuthGroupType[];
allowedIDIRAuthGroups?: IDIRUserAuthGroupType[];
}) => {
const {
isAuthenticated,
isLoading: isAuthLoading,
user: userFromToken,
} = useAuth();

const { userRoles, companyId, isNewBCeIDUser } =
useContext(OnRouteBCContext);
const { userRoles, companyId, isNewBCeIDUser } = useContext(OnRouteBCContext);
const userIDP = userFromToken?.profile?.identity_provider as string;

const location = useLocation();
Expand Down Expand Up @@ -77,7 +76,7 @@ export const BCeIDAuthWall = ({
if (isAuthenticated && isEstablishedUser) {
if (isIDIR(userIDP)) {
if (companyId) {
return <IDIRAuthWall allowedAuthGroups={allowedAuthGroups} />;
return <IDIRAuthWall allowedAuthGroups={allowedIDIRAuthGroups} />;
} else {
return (
<Navigate
Expand Down
62 changes: 55 additions & 7 deletions frontend/src/routes/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ export const AppRoutes = () => {

{/* BCeID Routes */}
{/* Protected Routes */}
<Route element={<BCeIDAuthWall requiredRole={ROLES.READ_VEHICLE} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.READ_VEHICLE}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route path={routes.VEHICLES_ROUTES.MANAGE}>
<Route index={true} element={<ManageVehicles />} />
<Route
Expand Down Expand Up @@ -174,14 +181,28 @@ export const AppRoutes = () => {
</Route>
</Route>

<Route element={<BCeIDAuthWall requiredRole={ROLES.READ_ORG} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.READ_ORG}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route
path={routes.PROFILE_ROUTES.MANAGE}
element={<ManageProfiles />}
/>
</Route>

<Route element={<BCeIDAuthWall requiredRole={ROLES.WRITE_USER} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.WRITE_USER}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route
path={routes.PROFILE_ROUTES.ADD_USER}
element={<AddUserDashboard />}
Expand All @@ -192,7 +213,14 @@ export const AppRoutes = () => {
/>
</Route>

<Route element={<BCeIDAuthWall requiredRole={ROLES.WRITE_PERMIT} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.WRITE_PERMIT}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route
path={`${routes.APPLICATIONS_ROUTES.START_APPLICATION()}`}
element={
Expand All @@ -202,7 +230,14 @@ export const AppRoutes = () => {
}
/>
</Route>
<Route element={<BCeIDAuthWall requiredRole={ROLES.WRITE_PERMIT} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.WRITE_PERMIT}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route path={routes.APPLICATIONS_ROUTES.BASE}>
<Route index={true} element={<PermitDashboard />} />
<Route path={`${routes.APPLICATIONS_ROUTES.DETAILS()}`}>
Expand Down Expand Up @@ -234,14 +269,27 @@ export const AppRoutes = () => {
</Route>
</Route>

<Route element={<BCeIDAuthWall requiredRole={ROLES.WRITE_PERMIT} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.WRITE_PERMIT}
allowedIDIRAuthGroups={[IDIR_USER_AUTH_GROUP.PPC_CLERK]}
/>
}
>
<Route
path={`${routes.PERMITS_ROUTES.SUCCESS()}`}
element={<SuccessPage />}
/>
</Route>

<Route element={<BCeIDAuthWall requiredRole={ROLES.WRITE_PERMIT} />}>
<Route
element={
<BCeIDAuthWall
requiredRole={ROLES.WRITE_PERMIT}
/>
}
>
<Route
path={routes.PAYMENT_ROUTES.PAYMENT_REDIRECT}
element={<PaymentRedirect />}
Expand Down

0 comments on commit 5082c69

Please sign in to comment.