Skip to content

Commit c5084dd

Browse files
committed
fix: user with topcoder user role should not be allowed to create challenges
1 parent 143a789 commit c5084dd

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ typings/
6363
.next
6464
ecr-login.sh
6565
.npmrc
66+
test.js

src/routes.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module.exports = {
3030
constants.UserRoles.SelfServiceCustomer,
3131
constants.UserRoles.Copilot,
3232
constants.UserRoles.Manager,
33-
constants.UserRoles.User,
3433
],
3534
scopes: [CREATE, ALL],
3635
},
@@ -53,6 +52,7 @@ module.exports = {
5352
method: "getChallenge",
5453
scopes: [READ, ALL],
5554
},
55+
// @deprecated
5656
put: {
5757
controller: "ChallengeController",
5858
method: "updateChallenge",
@@ -62,7 +62,6 @@ module.exports = {
6262
constants.UserRoles.SelfServiceCustomer,
6363
constants.UserRoles.Copilot,
6464
constants.UserRoles.Manager,
65-
constants.UserRoles.User,
6665
],
6766
scopes: [UPDATE, ALL],
6867
},
@@ -75,7 +74,6 @@ module.exports = {
7574
constants.UserRoles.SelfServiceCustomer,
7675
constants.UserRoles.Copilot,
7776
constants.UserRoles.Manager,
78-
constants.UserRoles.User,
7977
],
8078
scopes: [UPDATE, ALL],
8179
},
@@ -88,7 +86,6 @@ module.exports = {
8886
constants.UserRoles.Copilot,
8987
constants.UserRoles.SelfServiceCustomer,
9088
constants.UserRoles.Manager,
91-
constants.UserRoles.User,
9289
],
9390
scopes: [DELETE, ALL],
9491
},

src/services/ChallengeService.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,12 @@ createChallenge.schema = {
11821182
projectId: Joi.number().integer().positive(),
11831183
legacyId: Joi.number().integer().positive(),
11841184
startDate: Joi.date().iso(),
1185-
status: Joi.string().valid([constants.challengeStatuses.Active, constants.challengeStatuses.New, constants.challengeStatuses.Draft, constants.challengeStatuses.Approved]),
1185+
status: Joi.string().valid([
1186+
constants.challengeStatuses.Active,
1187+
constants.challengeStatuses.New,
1188+
constants.challengeStatuses.Draft,
1189+
constants.challengeStatuses.Approved,
1190+
]),
11861191
groups: Joi.array().items(Joi.optionalId()).unique(),
11871192
// gitRepoURLs: Joi.array().items(Joi.string().uri()),
11881193
terms: Joi.array().items(
@@ -1428,7 +1433,7 @@ async function updateChallenge(currentUser, challengeId, data) {
14281433
data = sanitizeData(sanitizeChallenge(data), challenge);
14291434
console.debug("Sanitized Data:", data);
14301435

1431-
validateChallengeUpdateRequest(currentUser, challenge, data);
1436+
await validateChallengeUpdateRequest(currentUser, challenge, data);
14321437

14331438
let sendActivationEmail = false;
14341439
let sendSubmittedEmail = false;
@@ -1615,7 +1620,12 @@ async function updateChallenge(currentUser, challengeId, data) {
16151620
const finalStatus = data.status || challenge.status;
16161621
const finalTimelineTemplateId = data.timelineTemplateId || challenge.timelineTemplateId;
16171622
let timelineTemplateChanged = false;
1618-
if (!currentUser.isMachine && !hasAdminRole(currentUser) && !_.get(data, "legacy.pureV5") && !_.get(challenge, "legacy.pureV5")) {
1623+
if (
1624+
!currentUser.isMachine &&
1625+
!hasAdminRole(currentUser) &&
1626+
!_.get(data, "legacy.pureV5") &&
1627+
!_.get(challenge, "legacy.pureV5")
1628+
) {
16191629
if (
16201630
finalStatus !== constants.challengeStatuses.New &&
16211631
finalTimelineTemplateId !== challenge.timelineTemplateId
@@ -1748,7 +1758,9 @@ async function updateChallenge(currentUser, challengeId, data) {
17481758
const { track, type } = await challengeHelper.validateAndGetChallengeTypeAndTrack({
17491759
typeId: challenge.typeId,
17501760
trackId: challenge.trackId,
1751-
timelineTemplateId: timelineTemplateChanged ? finalTimelineTemplateId : challenge.timelineTemplateId,
1761+
timelineTemplateId: timelineTemplateChanged
1762+
? finalTimelineTemplateId
1763+
: challenge.timelineTemplateId,
17521764
});
17531765

17541766
if (_.get(type, "isTask")) {

0 commit comments

Comments
 (0)