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
Shared the eligibility verification with challengeRegistration.
The eligibility check routine is now in challengeHelper and can be added anywhere by a couple of simple lines of code.
  • Loading branch information
TheOsch committed Jun 18, 2017
commit 16be372f51e13af663a17b69d12ac2c39cfb7ae0
39 changes: 27 additions & 12 deletions actions/challengeRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* The APIs to register a challenge (studio category or software category) for the current logged-in user.
*
* @version 1.7
* @author ecnu_haozi, xjtufreeman, bugbuka, flytoj2ee, muzehyun
* @version 1.8
* @author ecnu_haozi, xjtufreeman, bugbuka, flytoj2ee, muzehyun, GFalcon
*
* changes in 1.1:
* Combine Challenge Registration API(BUGR-11058)
Expand All @@ -27,6 +27,9 @@
*
* changes in 1.7:
* Avoid reliability info set if there is none for new user.
*
* changes in 1.8:
* Added the verification of the challenge's eligibility
*/
"use strict";

Expand Down Expand Up @@ -880,19 +883,31 @@ exports.registerChallenge = {
} else {
api.helper.checkUserActivated(connection.caller.handle, api, connection.dbConnectionMap, function (err, inactive) {
var fail = err || inactive;
if (fail) cb(fail);
else api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
if (fail) {
cb(fail);
} else {
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
}
}, "You must activate your account in order to participate. Please check your e-mail in order to complete the activation process, or contact [email protected] if you did not receive an e-mail.");
}
}, function (result, cb) {
if (result.length > 0) {
if (result[0].is_studio) {
registerStudioChallengeAction(api, connection, next);
} else {
registerSoftwareChallengeAction(api, connection, next);
}
} else {
}, function(result, cb) {
// If the challenge is not found in the tcs_catalog:project table,
if (result.length === 0) {
// Do nothing, do not register
cb();
return;
}
var isStudio = result[0].isStudio !== 0;
api.challengeHelper.checkUserChallengeEligibility(connection, challengeId, function (err) {
cb(err, isStudio);
});
}, function (isStudio, cb) {
if (_.isUndefined(isStudio)) {
cb();
} else if (isStudio) {
registerStudioChallengeAction(api, connection, next);
} else {
registerSoftwareChallengeAction(api, connection, next);
}
}
], function (err) {
Expand Down
47 changes: 4 additions & 43 deletions actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,55 +867,16 @@ function validateChallenge(api, connection, dbConnectionMap, challengeId, isStud
challengeId: challengeId,
user_id: userId
};
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);
api.dataAccess.executeQuery('check_challenge_exists', sqlParams, dbConnectionMap, cb);
}, function (res, cb) {
// If the record with this callengeId doesn't exist in 'project' table
// or there's a studio/software mismatch
if (res.exists.length === 0 || Boolean(res.exists[0].is_studio) !== isStudio) {
if (res.length === 0 || Boolean(res[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 (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.accessibility, function (record, cbx) {
if (record.challenge_group_ind === 0) {
cbx(!(_.isNull(record.user_group_xref_found) || _.isUndefined(record.user_group_xref_found)));
} else {
api.v3client.isUserInGroup(connection, userId, record.group_id, function (err, result) {
if (err) {
error = err;
cbx(true);
} else {
cbx(result);
}
});
}
}, function (eligible) {
if (error) {
cb(error);
} else if (eligible) {
cb();
} else if (connection.caller.accessLevel === "anon") {
cb(new UnauthorizedError());
} else {
cb(new ForbiddenError());
}
});
// Check the eligibility
api.challengeHelper.checkUserChallengeEligibility(connection, challengeId, cb);
}
], callback);
}
Expand Down
17 changes: 17 additions & 0 deletions db_scripts/test_eligibility.delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ DELETE FROM security_groups WHERE group_id > 3330000 AND group_id < 3330100;
DELETE FROM group_contest_eligibility WHERE contest_eligibility_id > 1110000 AND contest_eligibility_id < 1110100;
DELETE FROM contest_eligibility WHERE contest_eligibility_id > 1110000 AND contest_eligibility_id < 1110100;

DATABASE informixoltp;

-- UPDATE coder SET comp_country_code = NULL WHERE user_id = 132458;

DATABASE tcs_catalog;

DELETE FROM notification WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM project_result WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM project_user_audit WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM component_inquiry WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM resource_info WHERE resource_id IN (SELECT resource_id FROM resource WHERE project_id > 1110000 AND project_id < 1110100);
DELETE FROM resource WHERE project_id > 1110000 AND project_id < 1110100;

DELETE FROM project_info WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM comp_versions WHERE component_id = 3330333;
DELETE FROM comp_catalog WHERE component_id = 3330333;
DELETE FROM project_phase WHERE project_id > 1110000 AND project_id < 1110100;
DELETE FROM project WHERE project_id > 1110000 AND project_id < 1110100;

DELETE FROM review_item_comment WHERE review_item_comment_id > 7770000 AND review_item_id < 7770100;
DELETE FROM review_item WHERE review_item_id > 5550000 AND review_item_id < 5550100;
DELETE FROM review WHERE review_id > 4440000 AND review_id < 4440100;
Expand Down
89 changes: 88 additions & 1 deletion db_scripts/test_eligibility.insert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ INSERT INTO review_item (review_item_id, review_id, scorecard_question_id, uploa
VALUES (5550004, 4440004, 3330333, 9990004, "---", 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO review_item (review_item_id, review_id, scorecard_question_id, upload_id, answer, sort, create_user, create_date, modify_user, modify_date)
VALUES (5550005, 4440005, 3330333, 9990005, "---", 1, "132456", CURRENT, "132456", CURRENT);


INSERT INTO review_item_comment (review_item_comment_id, resource_id, review_item_id, comment_type_id, content, sort, create_user, create_date, modify_user, modify_date)
VALUES (7770001, 8880001, 5550001, 1, "The current user has the right to view this challenge", 1, "132456", CURRENT, "132456", CURRENT);
Expand All @@ -111,6 +110,84 @@ INSERT INTO review_item_comment (review_item_comment_id, resource_id, review_ite
VALUES (7770004, 8880004, 5550004, 1, "The current user has the right to view this challenge", 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO review_item_comment (review_item_comment_id, resource_id, review_item_id, comment_type_id, content, sort, create_user, create_date, modify_user, modify_date)
VALUES (7770005, 8880005, 5550005, 1, "The current user has the right to view this challenge", 1, "132456", CURRENT, "132456", CURRENT);

INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
VALUES (1110001, 1, 14, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
VALUES (1110002, 1, 14, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
VALUES (1110003, 1, 14, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
VALUES (1110004, 1, 14, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date)
VALUES (1110005, 1, 14, "132456", CURRENT, "132456", CURRENT);

INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (2220001, 1110001, 1, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (2220002, 1110002, 1, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (2220003, 1110003, 1, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (2220004, 1110004, 1, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (2220005, 1110005, 1, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);

INSERT INTO comp_catalog (component_id, current_version, component_name, status_id, modify_date, public_ind)
VALUES (3330333, 1, "---", 1, CURRENT, 0);

INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, phase_id, phase_time, price, modify_date)
VALUES (4440444, 3330333, 1, "1", 113, CURRENT, 1000, CURRENT);

INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110001, 2, "3330333", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110002, 2, "3330333", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110003, 2, "3330333", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110004, 2, "3330333", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110005, 2, "3330333", "132456", CURRENT, "132456", CURRENT);

INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110001, 6, 3330333, "Not private", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110002, 6, 3330333, "Old logic - access allowed", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110003, 6, 3330333, "Old logic - access denied", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110004, 6, 3330333, "New logic - access allowed", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110005, 6, 3330333, "New logic - access denied", CURRENT, "132456", CURRENT);

INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110001, 79, "---", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110002, 79, "---", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110003, 79, "---", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110004, 79, "---", "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date)
VALUES (1110005, 79, "---", "132456", CURRENT, "132456", CURRENT);

INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (3330001, 1110001, 2, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (3330002, 1110002, 2, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (3330003, 1110003, 2, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (3330004, 1110004, 2, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, scheduled_start_time, scheduled_end_time, duration, create_user, create_date, modify_user, modify_date)
VALUES (3330005, 1110005, 2, 2, CURRENT, CURRENT, 1, "132456", CURRENT, "132456", CURRENT);

DATABASE informixoltp;

UPDATE coder SET comp_country_code = (
SELECT MIN(country_code) FROM country WHERE country_name = "United States"
) WHERE coder_id = 132458;

DATABASE common_oltp;

Expand All @@ -130,3 +207,13 @@ INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110003, 3330002);
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110004, 3330003);
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110005, 3330004);

INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110012, 1110002, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110013, 1110003, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110014, 1110004, 0);
INSERT INTO contest_eligibility (contest_eligibility_id, contest_id, is_studio) VALUES (1110015, 1110005, 0);

INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110012, 3330001);
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110013, 3330002);
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110014, 3330003);
INSERT INTO group_contest_eligibility (contest_eligibility_id, group_id) VALUES (1110015, 3330004);
Binary file not shown.
Loading