Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Improve challenge visibility control #501

Merged
merged 4 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixed the case with a challenge that doesn't have eligibility
  • Loading branch information
TheOsch committed Jun 16, 2017
commit 445be50b7aac2abe76aba1d404e09914299e9bb7
20 changes: 15 additions & 5 deletions actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,22 +867,32 @@ function validateChallenge(api, connection, dbConnectionMap, challengeId, isStud
challengeId: challengeId,
user_id: userId
};
api.dataAccess.executeQuery('get_challenge_accessibility_and_groups', sqlParams, dbConnectionMap, cb);
async.parallel({
accessibility: function (cbx) {
api.dataAccess.executeQuery('get_challenge_accessibility_and_groups', sqlParams, dbConnectionMap, cbx);
},
exists: function (cbx) {
api.dataAccess.executeQuery('check_challenge_exists', sqlParams, dbConnectionMap, cbx);
}
}, cb);
}, function (res, cb) {
// If the record with this callengeId doesn't exist in contest_eligibility table
// If the record with this callengeId doesn't exist in 'project' table
// or there's a studio/software mismatch
if (res.length === 0 || Boolean(res[0].is_studio) !== isStudio) {
if (res.exists.length === 0 || Boolean(res.exists[0].is_studio) !== isStudio) {
cb(new NotFoundError("Challenge not found."));
return;
}
// If there's no corresponding record in group_contest_eligibility
// or the user is an admin
if (_.isNull(res[0].challenge_group_ind) || _.isUndefined(res[0].challenge_group_ind) || connection.caller.accessLevel === 'admin') {
if (res.accessibility.length === 0
|| _.isNull(res.accessibility[0].challenge_group_ind)
|| _.isUndefined(res.accessibility[0].challenge_group_ind)
|| connection.caller.accessLevel === 'admin') {
cb();
return;
}
error = false;
async.some(res, function (record, cbx) {
async.some(res.accessibility, function (record, cbx) {
if (record.challenge_group_ind === 0) {
cbx(!(_.isNull(record.user_group_xref_found) || _.isUndefined(record.user_group_xref_found)));
} else {
Expand Down
1 change: 0 additions & 1 deletion db_scripts/test_eligibility.insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ INSERT INTO review_item_comment (review_item_comment_id, resource_id, review_ite

DATABASE common_oltp;

INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110001, 2220001, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110002, 2220002, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110003, 2220003, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110004, 2220004, 0);
Expand Down