Skip to content

Commit

Permalink
🐛 Update archetype rbac scopes (#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 15, 2023
1 parent 045cc71 commit bd965f1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 26 deletions.
88 changes: 62 additions & 26 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ import { SimplePagination } from "@app/components/SimplePagination";
import { TablePersistenceKeyPrefix } from "@app/Constants";
import { useDeleteAssessmentMutation } from "@app/queries/assessments";
import { useDeleteReviewMutation } from "@app/queries/reviews";
import {
assessmentWriteScopes,
reviewsWriteScopes,
archetypesWriteScopes,
} from "@app/rbac";
import { checkAccess } from "@app/utils/rbac-utils";
import keycloak from "@app/keycloak";

const Archetypes: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -272,6 +279,12 @@ const Archetypes: React.FC = () => {
}
};

const token = keycloak.tokenParsed;
const userScopes: string[] = token?.scope.split(" ") || [],
archetypeWriteAccess = checkAccess(userScopes, archetypesWriteScopes),
assessmentWriteAccess = checkAccess(userScopes, assessmentWriteScopes),
reviewsWriteAccess = checkAccess(userScopes, reviewsWriteScopes);

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down Expand Up @@ -367,26 +380,44 @@ const Archetypes: React.FC = () => {
<Td isActionCell>
<ActionsColumn
items={[
{
title: t("actions.duplicate"),
onClick: () =>
setArchetypeToDuplicate(archetype),
},
{
title: t("actions.assess"),
onClick: () =>
assessSelectedArchetype(archetype),
},
{
title: t("actions.review"),
onClick: () =>
reviewSelectedArchetype(archetype),
},
{
title: t("actions.edit"),
onClick: () => setArchetypeToEdit(archetype),
},
...(archetype?.assessments?.length
...(archetypeWriteAccess
? [
{
title: t("actions.duplicate"),
onClick: () =>
setArchetypeToDuplicate(archetype),
},
]
: []),
...(assessmentWriteAccess
? [
{
title: t("actions.assess"),
onClick: () =>
assessSelectedArchetype(archetype),
},
]
: []),
...(reviewsWriteAccess
? [
{
title: t("actions.review"),
onClick: () =>
reviewSelectedArchetype(archetype),
},
]
: []),
...(archetypeWriteAccess
? [
{
title: t("actions.edit"),
onClick: () =>
setArchetypeToEdit(archetype),
},
]
: []),
...(archetype?.assessments?.length &&
assessmentWriteAccess
? [
{
title: t("actions.discardAssessment"),
Expand All @@ -395,7 +426,7 @@ const Archetypes: React.FC = () => {
},
]
: []),
...(archetype?.review
...(archetype?.review && reviewsWriteAccess
? [
{
title: t("actions.discardReview"),
Expand All @@ -405,11 +436,16 @@ const Archetypes: React.FC = () => {
]
: []),
{ isSeparator: true },
{
title: t("actions.delete"),
onClick: () => setArchetypeToDelete(archetype),
isDanger: true,
},
...(archetypeWriteAccess
? [
{
title: t("actions.delete"),
onClick: () =>
setArchetypeToDelete(archetype),
isDanger: true,
},
]
: []),
]}
/>
</Td>
Expand Down
6 changes: 6 additions & 0 deletions client/src/app/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export const applicationsWriteScopes = [
"applications:delete",
];

export const archetypesWriteScopes = [
"archetypes:put",
"archetypes:post",
"archetypes:delete",
];

export const analysisWriteScopes = [
"applications.analysis:put",
"applications.analysis:post",
Expand Down

0 comments on commit bd965f1

Please sign in to comment.