Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Update archetype rbac scopes #1624

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Comment on lines +282 to +286
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is what we have to work with right now, but it pains me just a bit.


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),
},
]
: []),
Comment on lines +383 to +391
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternate form would be to drop undefieneds and then .filter(Boolean) at the end...

         [
           archetypeWriteAccess && {
              title: ...
             ...
           },
           assessmentWriteAccess && { ... },
           ...
         ].filter(Boolean)

...(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
Loading