Skip to content

Commit

Permalink
bring in latest develop and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
anyoussefinia committed Dec 11, 2024
2 parents e1ae914 + 78e514f commit 802168e
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 115 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
name: ${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}
url: "https://onemac.cms.gov"
steps:
- name: Check GITHUB_REF
run: echo "GITHUB_REF is $GITHUB_REF"
- name: set branch_name
run: echo "branch_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Check branch name is a legal serverless stage name
Expand Down
17 changes: 9 additions & 8 deletions services/admin/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ plugins:
- serverless-esbuild
- serverless-dotenv-plugin
- serverless-s3-bucket-helper

custom:
stage: ${opt:stage, 'dev'} # Ensure the 'stage' is being passed correctly
stage: ${opt:stage, self:provider.stage}
iamPermissionsBoundaryPolicy: ${ssm:/configuration/${self:custom.stage}/iam/permissionsBoundaryPolicy, ssm:/configuration/default/iam/permissionsBoundaryPolicy, ""}
oneMacTableName: onemac-${self:custom.stage}-one

provider:
name: aws
runtime: nodejs20.x
region: us-east-1
stage: ${self:custom.stage}
stage: dev
iam:
role:
path: ${ssm:/configuration/${self:custom.stage}/iam/path, ssm:/configuration/default/iam/path, "/"}
Expand All @@ -39,13 +37,17 @@ provider:
- arn:aws:dynamodb:*:*:table/onemac-develop-one
- arn:aws:dynamodb:*:*:table/${self:custom.oneMacTableName}
- arn:aws:dynamodb:*:*:table/${self:custom.oneMacTableName}/index/*
# Allow CreateRole for IAM actions
- Effect: Allow
Action:
- iam:CreateRole
Resource: arn:aws:iam::${AWS::AccountId}:role/*

environment:
NODE_OPTIONS: '--enable-source-maps'
oneMacTableName: ${self:custom.oneMacTableName}

layers:
- ${cf:aws-sdk-v2-layer-${self:custom.stage}.AwsSdkV2LambdaLayerQualifiedArn}
- ${cf:aws-sdk-v2-layer-${self:custom.stage}.AwsSdkV2LambdaLayerQualifiedArn}

functions:
addPropertyToJWT:
Expand Down Expand Up @@ -89,5 +91,4 @@ functions:

insertNotification:
handler: ./handlers/insertNotification.main
timeout: 180

timeout: 180
2 changes: 1 addition & 1 deletion services/app-api/getDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getDetails = async (event) => {
if (!userRoleObj.isCMSUser && result.Item.reviewTeam)
delete result.Item.reviewTeam;

result.Item.actions = getActionsForPackage(
result.Item.actions = await getActionsForPackage(
result.Item.componentType,
originalStatus,
!!result.Item.latestRaiResponseTimestamp,
Expand Down
182 changes: 89 additions & 93 deletions services/app-api/getMyPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,106 +19,102 @@ export const getMyPackages = async (email, group) => {
if (!email) return RESPONSE_CODE.USER_NOT_FOUND;
if (!group) return RESPONSE_CODE.DATA_MISSING;

return getUser(email)
.then((user) => {
if (!user) throw RESPONSE_CODE.USER_NOT_AUTHORIZED;
try {
const user = await getUser(email);
if (!user) throw RESPONSE_CODE.USER_NOT_AUTHORIZED;

const userRoleObj = getUserRoleObj(user.roleList);
const territoryList = getActiveTerritories(user.roleList);
const statusMap = userRoleObj.isCMSUser
? cmsStatusUIMap
: stateStatusUIMap;
const userRoleObj = getUserRoleObj(user.roleList);
const territoryList = getActiveTerritories(user.roleList);
const statusMap = userRoleObj.isCMSUser ? cmsStatusUIMap : stateStatusUIMap;

if (
!userRoleObj.canAccessDashboard ||
(Array.isArray(territoryList) && territoryList.length === 0)
) {
throw RESPONSE_CODE.USER_NOT_AUTHORIZED;
}
if (
!userRoleObj.canAccessDashboard ||
(Array.isArray(territoryList) && territoryList.length === 0)
) {
throw RESPONSE_CODE.USER_NOT_AUTHORIZED;
}

const baseParams = {
TableName: process.env.oneMacTableName,
IndexName: "GSI1",
ExclusiveStartKey: null,
ScanIndexForward: false,
ProjectionExpression:
"componentId,componentType,currentStatus,submissionTimestamp,latestRaiResponseTimestamp,lastActivityTimestamp,submitterName,submitterEmail,waiverAuthority, cpocName, reviewTeam, subStatus, finalDispositionDate",
};
const grouppk = "OneMAC#" + group;
let paramList = [];
if (territoryList[0] !== "N/A") {
paramList = territoryList.map((territory) => {
return {
...baseParams,
KeyConditionExpression: "GSI1pk = :pk AND begins_with(GSI1sk,:t1)",
ExpressionAttributeValues: {
":pk": grouppk,
":t1": territory,
},
};
});
} else {
paramList = [
{
...baseParams,
KeyConditionExpression: "GSI1pk = :pk",
ExpressionAttributeValues: {
":pk": grouppk,
},
const baseParams = {
TableName: process.env.oneMacTableName,
IndexName: "GSI1",
ExclusiveStartKey: null,
ScanIndexForward: false,
ProjectionExpression:
"componentId,componentType,currentStatus,submissionTimestamp,latestRaiResponseTimestamp,lastActivityTimestamp,submitterName,submitterEmail,waiverAuthority, cpocName, reviewTeam, subStatus, finalDispositionDate",
};
const grouppk = "OneMAC#" + group;
let paramList = [];
if (territoryList[0] !== "N/A") {
paramList = territoryList.map((territory) => {
return {
...baseParams,
KeyConditionExpression: "GSI1pk = :pk AND begins_with(GSI1sk,:t1)",
ExpressionAttributeValues: {
":pk": grouppk,
":t1": territory,
},
];
}
};
});
} else {
paramList = [
{
...baseParams,
KeyConditionExpression: "GSI1pk = :pk",
ExpressionAttributeValues: {
":pk": grouppk,
},
},
];
}

return Promise.all(
paramList.map(async (params) => {
const promiseItems = [];
do {
const results = await dynamoDb.query(params);
results.Items.map((oneItem) => {
oneItem.actions = getActionsForPackage(
oneItem.componentType,
oneItem.currentStatus,
!!oneItem.latestRaiResponseTimestamp,
oneItem.subStatus,
userRoleObj,
"package"
);
if (oneItem.waiverAuthority)
oneItem.temporaryExtensionType = oneItem.waiverAuthority.slice(
0,
7
);
// Using a for...of loop to ensure async operations are awaited correctly
const allItems = [];
for (const params of paramList) {
const promiseItems = [];
do {
const results = await dynamoDb.query(params);
for (const oneItem of results.Items) {
oneItem.actions = await getActionsForPackage(
oneItem.componentType,
oneItem.currentStatus,
!!oneItem.latestRaiResponseTimestamp,
oneItem.subStatus,
userRoleObj,
"package"
);
if (oneItem.waiverAuthority)
oneItem.temporaryExtensionType = oneItem.waiverAuthority.slice(
0,
7
);

if (statusMap[oneItem.subStatus]) {
oneItem.subStatus = statusMap[oneItem.subStatus];
}
if (statusMap[oneItem.subStatus]) {
oneItem.subStatus = statusMap[oneItem.subStatus];
}

if (!statusMap[oneItem.currentStatus])
console.log(
"%s status of %s not mapped!",
oneItem.pk,
oneItem.currentStatus
);
else {
oneItem.currentStatus = statusMap[oneItem.currentStatus];
if (
oneItem.currentStatus !== Workflow.ONEMAC_STATUS.INACTIVATED
)
promiseItems.push(oneItem);
}
});
params.ExclusiveStartKey = results.LastEvaluatedKey;
} while (params.ExclusiveStartKey);
return promiseItems;
})
).then((values) => {
return values.flat();
});
})
.catch((error) => {
console.log("error is: ", error);
return error;
});
if (!statusMap[oneItem.currentStatus])
console.log(
"%s status of %s not mapped!",
oneItem.pk,
oneItem.currentStatus
);
else {
oneItem.currentStatus = statusMap[oneItem.currentStatus];
if (oneItem.currentStatus !== Workflow.ONEMAC_STATUS.INACTIVATED)
promiseItems.push(oneItem);
}
}
params.ExclusiveStartKey = results.LastEvaluatedKey;
} while (params.ExclusiveStartKey);

allItems.push(...promiseItems);
}

return allItems; // Flattened list of all items
} catch (error) {
console.log("error is: ", error);
return error;
}
};

// get the approver list for a rols and possibly a territory
Expand Down
Loading

0 comments on commit 802168e

Please sign in to comment.