Skip to content

Commit d4f9cf4

Browse files
authored
Revert "Revert "feat(top-262): make billing account optional for specific timeline templates""
1 parent ab2c489 commit d4f9cf4

File tree

6 files changed

+1253
-272
lines changed

6 files changed

+1253
-272
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ workflows:
8686
branches:
8787
only:
8888
- dev
89+
- feature/top-262-projectid-non-mandatory
8990

9091
- "build-qa":
9192
context: org-global

config/default.js

+2
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,6 @@ module.exports = {
130130
GRPC_CHALLENGE_SERVER_PORT: process.env.GRPC_DOMAIN_CHALLENGE_SERVER_PORT || 8888,
131131
GRPC_ACL_SERVER_HOST: process.env.GRPC_ACL_SERVER_HOST || "localhost",
132132
GRPC_ACL_SERVER_PORT: process.env.GRPC_ACL_SERVER_PORT || 8889,
133+
134+
SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID: process.env.SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID || '517e76b0-8824-4e72-9b48-a1ebde1793a8'
133135
};

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"dev": "nodemon app.js",
99
"lint": "prettier src/**/*.js",
1010
"lint:fix": "prettier --write src/**/*.js",
11+
"standard-lint": "standard",
12+
"standard-lint:fix": "standard --fix",
1113
"init-es": "node src/init-es.js",
1214
"init-db": "node src/init-db.js",
1315
"sync-es": "node src/scripts/sync-es.js",
@@ -37,13 +39,14 @@
3739
"mocha-prepare": "^0.1.0",
3840
"nodemon": "^2.0.20",
3941
"nyc": "^14.0.0",
40-
"prettier": "^2.8.1"
42+
"prettier": "^2.8.1",
43+
"standard": "^17.1.0"
4144
},
4245
"dependencies": {
4346
"@grpc/grpc-js": "^1.8.12",
4447
"@opensearch-project/opensearch": "^2.2.0",
45-
"@topcoder-framework/domain-challenge": "^0.24.1",
4648
"@topcoder-framework/domain-acl": "^0.24.0",
49+
"@topcoder-framework/domain-challenge": "^0.24.1",
4750
"@topcoder-framework/lib-common": "^0.24.1",
4851
"aws-sdk": "^2.1145.0",
4952
"axios": "^0.19.0",

src/common/challenge-helper.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ class ChallengeHelper {
169169

170170
async validateCreateChallengeRequest(currentUser, challenge) {
171171
// projectId is required for non self-service challenges
172-
if (challenge.legacy.selfService == null && challenge.projectId == null) {
172+
if (
173+
challenge.legacy.selfService == null &&
174+
challenge.projectId == null &&
175+
this.isProjectIdRequired(challenge.timelineTemplateId)
176+
) {
173177
throw new errors.BadRequestError("projectId is required for non self-service challenges.");
174178
}
175179

@@ -524,6 +528,12 @@ class ChallengeHelper {
524528
delete overview.totalPrizesInCents;
525529
}
526530
}
531+
532+
isProjectIdRequired(timelineTemplateId) {
533+
const template = _.get(config, "SKIP_PROJECT_ID_BY_TIMLINE_TEMPLATE_ID", '517e76b0-8824-4e72-9b48-a1ebde1793a8');
534+
535+
return template !== timelineTemplateId;
536+
}
527537
}
528538

529539
module.exports = new ChallengeHelper();

src/services/ChallengeService.js

+35-22
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ async function createChallenge(currentUser, challenge, userToken) {
941941
console.log("TYPE", prizeTypeTmp);
942942
if (challenge.legacy.selfService) {
943943
// if self-service, create a new project (what about if projectId is provided in the payload? confirm with business!)
944-
if (!challenge.projectId) {
944+
if (!challenge.projectId && challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
945945
const selfServiceProjectName = `Self service - ${currentUser.handle} - ${challenge.name}`;
946946
challenge.projectId = await helper.createSelfServiceProject(
947947
selfServiceProjectName,
@@ -963,14 +963,18 @@ async function createChallenge(currentUser, challenge, userToken) {
963963
}
964964

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

968-
const { directProjectId } = await projectHelper.getProject(projectId, currentUser);
969-
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId);
969+
const { directProjectId } = await projectHelper.getProject(projectId, currentUser);
970+
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(
971+
projectId
972+
);
970973

971-
_.set(challenge, "legacy.directProjectId", directProjectId);
972-
_.set(challenge, "billing.billingAccountId", billingAccountId);
973-
_.set(challenge, "billing.markup", markup || 0);
974+
_.set(challenge, "legacy.directProjectId", directProjectId);
975+
_.set(challenge, "billing.billingAccountId", billingAccountId);
976+
_.set(challenge, "billing.markup", markup || 0);
977+
}
974978

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

1519-
const projectId = _.get(challenge, "projectId");
1523+
let projectId, billingAccountId, markup;
1524+
if (challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)) {
1525+
projectId = _.get(challenge, "projectId");
15201526

1521-
const { billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId);
1527+
({ billingAccountId, markup } = await projectHelper.getProjectBillingInformation(projectId));
15221528

1523-
if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
1524-
_.set(data, "billing.billingAccountId", billingAccountId);
1525-
_.set(data, "billing.markup", markup || 0);
1526-
}
1529+
if (billingAccountId && _.isUndefined(_.get(challenge, "billing.billingAccountId"))) {
1530+
_.set(data, "billing.billingAccountId", billingAccountId);
1531+
_.set(data, "billing.markup", markup || 0);
1532+
}
15271533

1528-
// Make sure the user cannot change the direct project ID
1529-
if (data.legacy) {
1530-
data.legacy = _.assign({}, challenge.legacy, data.legacy);
1531-
_.set(data, "legacy.directProjectId", challenge.legacy.directProjectId);
1534+
// Make sure the user cannot change the direct project ID
1535+
if (data.legacy) {
1536+
data.legacy = _.assign({}, challenge.legacy, data.legacy);
1537+
_.set(data, "legacy.directProjectId", challenge.legacy.directProjectId);
1538+
}
15321539
}
15331540

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

1610-
if (data.status === constants.challengeStatuses.Draft) {
1618+
if (
1619+
data.status === constants.challengeStatuses.Draft &&
1620+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
1621+
) {
16111622
try {
16121623
await helper.updateSelfServiceProjectInfo(
16131624
projectId,
@@ -1620,8 +1631,9 @@ async function updateChallenge(currentUser, challengeId, data) {
16201631
}
16211632

16221633
if (
1623-
data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
1624-
data.status === constants.challengeStatuses.CancelledPaymentFailed
1634+
(data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
1635+
data.status === constants.challengeStatuses.CancelledPaymentFailed) &&
1636+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
16251637
) {
16261638
try {
16271639
await helper.cancelProject(challenge.projectId, data.cancelReason, currentUser);
@@ -1641,7 +1653,8 @@ async function updateChallenge(currentUser, challengeId, data) {
16411653
// if activating a challenge, the challenge must have a billing account id
16421654
if (
16431655
(!billingAccountId || billingAccountId === null) &&
1644-
challenge.status === constants.challengeStatuses.Draft
1656+
challenge.status === constants.challengeStatuses.Draft &&
1657+
challengeHelper.isProjectIdRequired(challenge.timelineTemplateId)
16451658
) {
16461659
throw new errors.BadRequestError(
16471660
"Cannot Activate this project, it has no active billing account."

0 commit comments

Comments
 (0)