Skip to content

Commit e29a714

Browse files
Merge pull request #67 from rashmi73/issue_55
issue 55 fix
2 parents 4e911f9 + 3942366 commit e29a714

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/services/ChallengeService.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ async function ensureAccessibleByGroupsAccess (currentUser, challenge) {
6060
}
6161
}
6262

63+
/**
64+
* Ensure the user can access the groups being updated to
65+
* @param {Object} currentUser the user who perform operation
66+
* @param {Object} data the challenge data to be updated
67+
* @param {String} challenge the original challenge data
68+
*/
69+
70+
async function ensureAcessibilityToModifiedGroups (currentUser, data, challenge) {
71+
const userGroups = await helper.getUserGroups(currentUser.userId)
72+
const userGroupsNames = _.map(userGroups, group => group.name)
73+
const updatedGroups = _.difference(_.union(challenge.groups, data.groups), _.intersection(challenge.groups, data.groups))
74+
const filtered = updatedGroups.filter(g => !userGroupsNames.includes(g))
75+
if (filtered.length > 0) {
76+
throw new errors.ForbiddenError(`You don't have access to this group!`)
77+
}
78+
}
79+
6380
/**
6481
* Search challenges
6582
* @param {Object} currentUser the user who perform operation
@@ -668,6 +685,11 @@ async function update (currentUser, challengeId, data, userToken, isFull) {
668685
await ensureAccessibleByGroupsAccess(currentUser, challenge)
669686
console.log('After checking group access')
670687

688+
// check groups access to be updated group values
689+
if (data.groups) {
690+
await ensureAcessibilityToModifiedGroups(currentUser, data, challenge)
691+
}
692+
671693
console.log('before fetching attachments')
672694
let newAttachments
673695
if (isFull || !_.isUndefined(data.attachmentIds)) {

0 commit comments

Comments
 (0)