Skip to content

Commit

Permalink
fix(hide issue rai): Hide Issue RAI based on username prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f committed Mar 6, 2024
1 parent 3b2c1a6 commit 5e99b23
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/packages/shared-types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type CognitoUserAttributes = {
given_name: string;
family_name: string;
email: string;
username: string;
};

export const CMS_ROLES = [
Expand Down
2 changes: 2 additions & 0 deletions src/packages/shared-utils/package-actions/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { isStateUser, isCmsWriteUser } from "../user-helper";
const arIssueRai: ActionRule = {
action: Action.ISSUE_RAI,
check: (checker, user) =>
// User is not an IDM user
!user.username.startsWith("IDM_") &&
checker.isInActivePendingStatus &&
// Doesn't have any RAIs
(!checker.hasLatestRai ||
Expand Down
1 change: 1 addition & 0 deletions src/services/api/libs/auth/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function userAttrDict(cognitoUser: CognitoUserType): CognitoUserAttributes {
}
});
}
attributes["username"] = cognitoUser.Username;

return attributes as CognitoUserAttributes;
}
Expand Down
1 change: 1 addition & 0 deletions src/services/ui/src/api/submissionService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const mockGeorge: OneMacUser = {
family_name: "Harrison",
"custom:state": "VA,OH,SC,CO,GA,MD",
email: "[email protected]",
username: "IDM_a853eb41-f5fc-48af-911d-4f478e4da3a2 ",
},
};

Expand Down
6 changes: 5 additions & 1 deletion src/services/ui/src/api/useGetUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { Auth } from "aws-amplify";
import { CognitoUserAttributes } from "shared-types";
import { isCmsUser } from "shared-utils";

export type OneMacUser = { isCms?: boolean, user: CognitoUserAttributes | null }
export type OneMacUser = {
isCms?: boolean;
user: CognitoUserAttributes | null;
};

export const getUser = async (): Promise<OneMacUser> => {
try {
Expand All @@ -17,6 +20,7 @@ export const getUser = async (): Promise<OneMacUser> => {
if (!user["custom:cms-roles"]) {
user["custom:cms-roles"] = "";
}
user["username"] = authenticatedUser.username;

const isCms = isCmsUser(user);
return { user, isCms } satisfies OneMacUser;
Expand Down

0 comments on commit 5e99b23

Please sign in to comment.