Skip to content

Commit

Permalink
remove unneeded logging, pr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anyoussefinia committed Dec 13, 2024
1 parent 4d16d78 commit 8a3debe
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 26 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions services/admin/handlers/batchUpdateCognitoUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ async function updateUserAttribute(userPoolId, username, roles) {

async function processCognitoUsers() {
const userPoolId = process.env.USER_POOL_ID;
// const userPoolId = process.env.USER_POOL_ID | "us-east-1_B3uR9r4cC";
console.log("user pool id: ", userPoolId)
let paginationToken = null;
let counter = 0;
Expand All @@ -33,15 +32,16 @@ async function processCognitoUsers() {
};

const listUsersResponse = await cognito.listUsers(params).promise();

console.log(listUsersResponse.Users.length + " users found")

for (const user of listUsersResponse.Users) {
const emailAttribute = user.Attributes.find(attr => attr.Name === 'email');
if (emailAttribute) {
const userEmail = emailAttribute.Value;

try {
const externalUser = await getUser(userEmail);
let roles = [];
let roles = [""];
if (externalUser.roleList) {
roles = externalUser.roleList.map(role => role.role);
hasRolesCounter ++;
Expand Down
4 changes: 2 additions & 2 deletions services/admin/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ functions:
handler: ./handlers/batchUpdateCognitoUsers.main
timeout: 360

addPropertyToJWT:
handler: ./handlers/addPropertyToJWT.handler
addRolesToJWT:
handler: ./handlers/addRolesToJWT.handler
timeout: 360

resetData:
Expand Down
3 changes: 1 addition & 2 deletions services/ui-src/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const DEFAULT_AUTH_STATE: Omit<
userProfile: {},
userRole: null,
userStatus: null,
activeTerritories: null,
myUserList: []
activeTerritories: null
};

const App = () => {
Expand Down
26 changes: 17 additions & 9 deletions services/ui-src/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,29 @@ const isAdminUser = ()=> {
return false;
}

let userRoles;
//authenticated users will have idToken in Local Storage
const idTokenKey: string[] = Object.keys(localStorage).filter((k) =>
k.includes(ID_TOKEN_KEY)
);
const idToken: string | null =
idTokenKey && localStorage.getItem(idTokenKey[0]);
if (!idToken) return false;
const decodedIdToken: any = jwt_decode(idToken);
let userRoles = decodedIdToken["custom:user_roles"];
try{
const idTokenKey: string[] = Object.keys(localStorage).filter((k) =>
k.includes(ID_TOKEN_KEY)
);
const idToken: string | null =
idTokenKey && localStorage.getItem(idTokenKey[0]);
if (!idToken) return false;
const decodedIdToken: any = jwt_decode(idToken);
userRoles = decodedIdToken["custom:user_roles"];
} catch (error) {
console.error("error decoding idToken", error);
return false;
}

const allowedRoles = [
"cmsroleapprover",
"systemadmin",
"statesystemadmin",
"helpdesk"
"helpdesk",
"cmsreviewer",
// "defaultcmsuser"
];

// only passes admin check if roles from jwt one of the "allowed roles"
Expand Down
7 changes: 0 additions & 7 deletions services/ui-src/src/containers/UserManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const alertCodes = {
revoked: RESPONSE_CODE.SUCCESS_USER_REVOKED,
};



/**
* User Management "Dashboard"
*/
Expand All @@ -94,8 +92,6 @@ const UserManagement = () => {
].includes(userRole),
[userRole]
);


const updateList = useCallback(() => {
if (userStatus !== USER_STATUS.ACTIVE) return;
UserDataApi.getMyUserList(userProfile.email)
Expand All @@ -104,7 +100,6 @@ const UserManagement = () => {
if (userStatus !== USER_STATUS.PENDING) setAlertCode(ul);
ul = [];
}

setUserList(ul);
})
.catch((error) => {
Expand All @@ -114,8 +109,6 @@ const UserManagement = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userProfile.email, userStatus]);



// Load the data from the backend.
useEffect(() => {
let mounted = true;
Expand Down
1 change: 0 additions & 1 deletion services/ui-src/src/containers/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
import { useLocation, useParams, useHistory } from "react-router-dom";
import { Button, Review } from "@cmsgov/design-system";


import {
APPROVING_USER_ROLE,
RESPONSE_CODE,
Expand Down
1 change: 0 additions & 1 deletion services/ui-src/src/domain-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export type AppContextValue = {
userRole: USER_ROLE | null;
userStatus: USER_STATUS | null;
activeTerritories: string[] | null;
myUserList: string[] | null;
setUserInfo: (isDeveloper?: boolean) => Promise<void>;
updatePhoneNumber: (phoneNumber: string) => Promise<void>;
confirmAction: (
Expand Down
1 change: 0 additions & 1 deletion services/ui-src/src/libs/testDataAppContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const stateSubmitterInitialAuthState = {
setUserInfo: () => Promise.resolve(),
updatePhoneNumber: () => Promise.resolve(),
confirmAction: () => Promise.resolve(),
myUserList: [],
userProfile: {
cmsRoles: "onemac-state-user",
email: "[email protected]",
Expand Down

0 comments on commit 8a3debe

Please sign in to comment.