Skip to content

Fix issue in _ensureAccessibleForTaskChallenge #376

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 2 commits into from
Jan 28, 2021
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
10 changes: 4 additions & 6 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,18 +857,16 @@ async function ensureAccessibleByGroupsAccess (currentUser, challenge) {
* @param {Object} challenge the challenge to check
*/
async function _ensureAccessibleForTaskChallenge (currentUser, challenge) {
let memberChallengeIds
// Remove privateDescription for unregistered users
let challengeResourceIds
if (currentUser) {
if (!currentUser.isMachine) {
memberChallengeIds = await listChallengesByMember(currentUser.userId)
if (!_.includes(memberChallengeIds, challenge.id)) {
}
const challengeResources = await getChallengeResources(challenge.id)
challengeResourceIds = _.map(challengeResources, r => _.toString(r.memberId))
}
}
// Check if challenge is task and apply security rules
if (_.get(challenge, 'task.isTask', false) && _.get(challenge, 'task.isAssigned', false)) {
const canAccesChallenge = _.isUndefined(currentUser) ? false : _.includes((memberChallengeIds || []), challenge.id) || currentUser.isMachine || hasAdminRole(currentUser)
const canAccesChallenge = _.isUndefined(currentUser) ? false : currentUser.isMachine || hasAdminRole(currentUser) || _.includes((challengeResourceIds || []), _.toString(currentUser.userId))
if (!canAccesChallenge) {
throw new errors.ForbiddenError(`You don't have access to view this challenge`)
}
Expand Down