Skip to content

issue 55 fix #67

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 1 commit into from
Apr 17, 2020
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
22 changes: 22 additions & 0 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ async function ensureAccessibleByGroupsAccess (currentUser, challenge) {
}
}

/**
* Ensure the user can access the groups being updated to
* @param {Object} currentUser the user who perform operation
* @param {Object} data the challenge data to be updated
* @param {String} challenge the original challenge data
*/

async function ensureAcessibilityToModifiedGroups (currentUser, data, challenge) {
const userGroups = await helper.getUserGroups(currentUser.userId)
const userGroupsNames = _.map(userGroups, group => group.name)
const updatedGroups = _.difference(_.union(challenge.groups, data.groups), _.intersection(challenge.groups, data.groups))
const filtered = updatedGroups.filter(g => !userGroupsNames.includes(g))
if (filtered.length > 0) {
throw new errors.ForbiddenError(`You don't have access to this group!`)
}
}

/**
* Search challenges
* @param {Object} currentUser the user who perform operation
Expand Down Expand Up @@ -668,6 +685,11 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
await ensureAccessibleByGroupsAccess(currentUser, challenge)
console.log('After checking group access')

// check groups access to be updated group values
if (data.groups) {
await ensureAcessibilityToModifiedGroups(currentUser, data, challenge)
}

console.log('before fetching attachments')
let newAttachments
if (isFull || !_.isUndefined(data.attachmentIds)) {
Expand Down