Skip to content

Merging Dev to Master #674

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 14 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 32 additions & 3 deletions src/common/challenge-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ class ChallengeHelper {
}
}

/**
* Validate Challenge groups.
* @param {Object} groups the group of a challenge
*/
async validateGroups(groups) {
const promises = [];
_.each(groups, (g) => {
promises.push(
(async () => {
const group = await helper.getGroupById(g);
if (!group || group.status !== "active") {
throw new errors.BadRequestError("The groups provided are invalid " + g);
}
})()
);
});
await Promise.all(promises);
}

async validateCreateChallengeRequest(currentUser, challenge) {
// projectId is required for non self-service challenges
if (challenge.legacy.selfService == null && challenge.projectId == null) {
Expand All @@ -98,7 +117,13 @@ class ChallengeHelper {
// helper.ensureNoDuplicateOrNullElements(challenge.events, 'events')

// check groups authorization
await helper.ensureAccessibleByGroupsAccess(currentUser, challenge);
if (challenge.groups && challenge.groups.length > 0) {
if (currentUser.isMachine || hasAdminRole(currentUser)) {
await this.validateGroups(challenge.groups);
} else {
await helper.ensureAccessibleByGroupsAccess(currentUser, challenge);
}
}

if (challenge.constraints) {
await ChallengeHelper.validateChallengeConstraints(challenge.constraints);
Expand All @@ -118,8 +143,12 @@ class ChallengeHelper {
}

// check groups access to be updated group values
if (data.groups) {
await ensureAcessibilityToModifiedGroups(currentUser, data, challenge);
if (data.groups && data.groups.length > 0) {
if (currentUser.isMachine || hasAdminRole(currentUser)) {
await this.validateGroups(data.groups);
} else {
await ensureAcessibilityToModifiedGroups(currentUser, data, challenge);
}
}

// Ensure descriptionFormat is either 'markdown' or 'html'
Expand Down
3 changes: 1 addition & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const { ChallengeDomain } = require("@topcoder-framework/domain-challenge");

const { hasAdminRole } = require("../common/role-helper");
const {
validateChallengeUpdateRequest,
enrichChallengeForResponse,
sanitizeRepeatedFieldsInUpdateRequest,
convertPrizeSetValuesToCents,
Expand Down Expand Up @@ -1491,7 +1490,7 @@ async function updateChallenge(currentUser, challengeId, data) {

const challengeResources = await helper.getChallengeResources(challengeId);

await validateChallengeUpdateRequest(currentUser, challenge, data, challengeResources);
await challengeHelper.validateChallengeUpdateRequest(currentUser, challenge, data, challengeResources);
validateTask(currentUser, challenge, data, challengeResources);

let sendActivationEmail = false;
Expand Down