Skip to content

Dev - sync with master #719

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

Merged
merged 8 commits into from
Apr 10, 2024
Merged
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
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ workflows:
branches:
only:
- dev
- feature/top-262-projectid-non-mandatory

- "build-qa":
context: org-global
2 changes: 0 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -130,6 +130,4 @@ module.exports = {
GRPC_CHALLENGE_SERVER_PORT: process.env.GRPC_DOMAIN_CHALLENGE_SERVER_PORT || 8888,
GRPC_ACL_SERVER_HOST: process.env.GRPC_ACL_SERVER_HOST || "localhost",
GRPC_ACL_SERVER_PORT: process.env.GRPC_ACL_SERVER_PORT || 8889,

SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID: process.env.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID || '517e76b0-8824-4e72-9b48-a1ebde1793a8'
};
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
"dev": "nodemon app.js",
"lint": "prettier src/**/*.js",
"lint:fix": "prettier --write src/**/*.js",
"standard-lint": "standard",
"standard-lint:fix": "standard --fix",
"init-es": "node src/init-es.js",
"init-db": "node src/init-db.js",
"sync-es": "node src/scripts/sync-es.js",
@@ -39,14 +37,13 @@
"mocha-prepare": "^0.1.0",
"nodemon": "^2.0.20",
"nyc": "^14.0.0",
"prettier": "^2.8.1",
"standard": "^17.1.0"
"prettier": "^2.8.1"
},
"dependencies": {
"@grpc/grpc-js": "^1.8.12",
"@opensearch-project/opensearch": "^2.2.0",
"@topcoder-framework/domain-acl": "^0.24.0",
"@topcoder-framework/domain-challenge": "^0.24.1",
"@topcoder-framework/domain-acl": "^0.24.0",
"@topcoder-framework/lib-common": "^0.24.1",
"aws-sdk": "^2.1145.0",
"axios": "^0.19.0",
12 changes: 1 addition & 11 deletions src/common/challenge-helper.js
Original file line number Diff line number Diff line change
@@ -169,11 +169,7 @@ class ChallengeHelper {

async validateCreateChallengeRequest(currentUser, challenge) {
// projectId is required for non self-service challenges
if (
challenge.legacy.selfService == null &&
challenge.projectId == null &&
this.isProjectIdRequired(challenge.timelineTemplateId)
) {
if (challenge.legacy.selfService == null && challenge.projectId == null) {
throw new errors.BadRequestError("projectId is required for non self-service challenges.");
}

@@ -528,12 +524,6 @@ class ChallengeHelper {
delete overview.totalPrizesInCents;
}
}

isProjectIdRequired(timelineTemplateId) {
const template = _.get(config, "SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID", '517e76b0-8824-4e72-9b48-a1ebde1793a8');

return template !== timelineTemplateId;
}
}

module.exports = new ChallengeHelper();
57 changes: 22 additions & 35 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
@@ -941,7 +941,7 @@ async function createChallenge(currentUser, challenge, userToken) {
console.log("TYPE", prizeTypeTmp);
if (challenge.legacy.selfService) {
// if self-service, create a new project (what about if projectId is provided in the payload? confirm with business!)
if (!challenge.projectId && challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
if (!challenge.projectId) {
const selfServiceProjectName = `Self service - ${currentUser.handle} - ${challenge.name}`;
challenge.projectId = await helper.createSelfServiceProject(
selfServiceProjectName,
@@ -963,18 +963,14 @@ async function createChallenge(currentUser, challenge, userToken) {
}

/** Ensure project exists, and set direct project id, billing account id & markup */
if (challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
const { projectId } = challenge;
const { projectId } = challenge;

const { directProjectId } = await projectHelper.getProject(projectId, currentUser);
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(
projectId
);
const { directProjectId } = await projectHelper.getProject(projectId, currentUser);
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId);

_.set(challenge, "legacy.directProjectId", directProjectId);
_.set(challenge, "billing.billingAccountId", billingAccountId);
_.set(challenge, "billing.markup", markup || 0);
}
_.set(challenge, "legacy.directProjectId", directProjectId);
_.set(challenge, "billing.billingAccountId", billingAccountId);
_.set(challenge, "billing.markup", markup || 0);

if (!_.isUndefined(_.get(challenge, "legacy.reviewType"))) {
_.set(challenge, "legacy.reviewType", _.toUpper(_.get(challenge, "legacy.reviewType")));
@@ -1520,22 +1516,19 @@ async function updateChallenge(currentUser, challengeId, data) {
convertPrizeSetValuesToDollars(challenge.prizeSets, challenge.overview);
}

let projectId, billingAccountId, markup;
if (challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
projectId = _.get(challenge, "projectId");
const projectId = _.get(challenge, "projectId");

({ billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId));
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId);

if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
_.set(data, "billing.billingAccountId", billingAccountId);
_.set(data, "billing.markup", markup || 0);
}
if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
_.set(data, "billing.billingAccountId", billingAccountId);
_.set(data, "billing.markup", markup || 0);
}

// Make sure the user cannot change the direct project ID
if (data.legacy) {
data.legacy = _.assign({}, challenge.legacy, data.legacy);
_.set(data, "legacy.directProjectId", challenge.legacy.directProjectId);
}
// Make sure the user cannot change the direct project ID
if (data.legacy) {
data.legacy = _.assign({}, challenge.legacy, data.legacy);
_.set(data, "legacy.directProjectId", challenge.legacy.directProjectId);
}

// Remove fields from data that are not allowed to be updated and that match the existing challenge
@@ -1578,8 +1571,7 @@ async function updateChallenge(currentUser, challengeId, data) {
if (
(data.status === constants.challengeStatuses.Approved ||
data.status === constants.challengeStatuses.Active) &&
challenge.status !== constants.challengeStatuses.Active &&
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
challenge.status !== constants.challengeStatuses.Active
) {
try {
const selfServiceProjectName = `Self service - ${challenge.createdBy} - ${challenge.name}`;
@@ -1615,10 +1607,7 @@ async function updateChallenge(currentUser, challengeId, data) {
}
}

if (
data.status === constants.challengeStatuses.Draft &&
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
) {
if (data.status === constants.challengeStatuses.Draft) {
try {
await helper.updateSelfServiceProjectInfo(
projectId,
@@ -1631,9 +1620,8 @@ async function updateChallenge(currentUser, challengeId, data) {
}

if (
(data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
data.status === constants.challengeStatuses.CancelledPaymentFailed) &&
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
data.status === constants.challengeStatuses.CancelledPaymentFailed
) {
try {
await helper.cancelProject(challenge.projectId, data.cancelReason, currentUser);
@@ -1653,8 +1641,7 @@ async function updateChallenge(currentUser, challengeId, data) {
// if activating a challenge, the challenge must have a billing account id
if (
(!billingAccountId || billingAccountId === null) &&
challenge.status === constants.challengeStatuses.Draft &&
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
challenge.status === constants.challengeStatuses.Draft
) {
throw new errors.BadRequestError(
"Cannot Activate this project, it has no active billing account."
1,446 changes: 247 additions & 1,199 deletions yarn.lock

Large diffs are not rendered by default.