Skip to content

Commit

Permalink
fix up role logic.. user helper could probably go for some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f committed Nov 17, 2023
1 parent 65cad99 commit 86566a7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 33 deletions.
7 changes: 2 additions & 5 deletions src/packages/shared-types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ export const CMS_ROLES = [
UserRoles.HELPDESK,
];

export const CMS_WRITE_ROLES = [
UserRoles.CMS_READ_ONLY,
UserRoles.CMS_REVIEWER,
];
export const CMS_WRITE_ROLES = [UserRoles.CMS_REVIEWER];

export const CMS_READ_ONLY_ROLES = [
UserRoles.CMS_READ_ONLY,
UserRoles.CMS_REVIEWER,
UserRoles.HELPDESK,
];

export const STATE_ROLES = [UserRoles.STATE_SUBMITTER];
3 changes: 1 addition & 2 deletions src/packages/shared-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./is-cms-user";
export * from "./is-cms-write-user";
export * from "./user-helper";
export * from "./s3-url-parser";
export * from "./rai-helper"
12 changes: 0 additions & 12 deletions src/packages/shared-utils/is-cms-user.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/packages/shared-utils/is-cms-write-user.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/packages/shared-utils/user-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { CMS_ROLES, CMS_WRITE_ROLES, CMS_READ_ONLY_ROLES, CognitoUserAttributes, STATE_ROLES } from "../shared-types";

export const isCmsUser = (user: CognitoUserAttributes) => {
const userRoles = user["custom:cms-roles"];

for (const cmsRole of CMS_ROLES) {
if (userRoles.includes(cmsRole)) {
return true;
}
}
return false;
};

export const isCmsWriteUser = (user: CognitoUserAttributes) => {
const userRoles = user["custom:cms-roles"];

for (const role of CMS_WRITE_ROLES) {
if (userRoles.includes(role)) {
return true;
}
}
return false;
};

export const isCmsReadonlyUser = (user: CognitoUserAttributes) => {
const userRoles = user["custom:cms-roles"];

for (const role of CMS_READ_ONLY_ROLES) {
if (userRoles.includes(role)) {
return true;
}
}
return false;
}

export const isStateUser = (user: CognitoUserAttributes) => {
const userRoles = user["custom:cms-roles"];

for (const role of STATE_ROLES) {
if (userRoles.includes(role)) {
return true;
}
}
return false;

}
9 changes: 7 additions & 2 deletions src/services/api/handlers/getPackageActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { APIGatewayEvent } from "aws-lambda";
import { Action, CognitoUserAttributes, ItemResult } from "shared-types";
import { isCmsUser, getActiveRai, isCmsWriteUser } from "shared-utils";
import {
isCmsUser,

Check warning on line 4 in src/services/api/handlers/getPackageActions.ts

View workflow job for this annotation

GitHub Actions / lint

'isCmsUser' is defined but never used
getActiveRai,
isCmsWriteUser,
isStateUser,
} from "shared-utils";
import { getPackage } from "../libs/package/getPackage";
import {
getAuthDetails,
Expand Down Expand Up @@ -47,7 +52,7 @@ export const packageActionsForResult = (
actions.push(Action.DISABLE_RAI_WITHDRAW);
}
}
} else {
} else if (isStateUser(user)) {
switch (result._source.seatoolStatus) {
case SEATOOL_STATUS.PENDING_RAI:
if (activeRai) {
Expand Down

0 comments on commit 86566a7

Please sign in to comment.