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

Commit a81d5d7

Browse files
authored
Challenge eligibility updates for v3 groups (#505)
* Improve challenge visibility control (#501) * IMPROVE CHALLENGE VISIBILITY CONTROL (https://www.topcoder.com/challenge-details/30057891/?type=develop) Verification guide: docs/Verification_Guide-Improve Challenge Visibility Control.doc * Restoring an accidentially modified file * Fixed the case with a challenge that doesn't have eligibility * 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. * improve the query * update query for groups (#502) * Update queries (#503) improve logging for v3 api call * should use externalToken field name
1 parent d667715 commit a81d5d7

23 files changed

+1046
-65
lines changed

actions/challengeRegistration.js

+27-12
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* The APIs to register a challenge (studio category or software category) for the current logged-in user.
55
*
6-
* @version 1.7
7-
* @author ecnu_haozi, xjtufreeman, bugbuka, flytoj2ee, muzehyun
6+
* @version 1.8
7+
* @author ecnu_haozi, xjtufreeman, bugbuka, flytoj2ee, muzehyun, GFalcon
88
*
99
* changes in 1.1:
1010
* Combine Challenge Registration API(BUGR-11058)
@@ -27,6 +27,9 @@
2727
*
2828
* changes in 1.7:
2929
* Avoid reliability info set if there is none for new user.
30+
*
31+
* changes in 1.8:
32+
* Added the verification of the challenge's eligibility
3033
*/
3134
"use strict";
3235

@@ -880,19 +883,31 @@ exports.registerChallenge = {
880883
} else {
881884
api.helper.checkUserActivated(connection.caller.handle, api, connection.dbConnectionMap, function (err, inactive) {
882885
var fail = err || inactive;
883-
if (fail) cb(fail);
884-
else api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
886+
if (fail) {
887+
cb(fail);
888+
} else {
889+
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
890+
}
885891
}, "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.");
886892
}
887-
}, function (result, cb) {
888-
if (result.length > 0) {
889-
if (result[0].is_studio) {
890-
registerStudioChallengeAction(api, connection, next);
891-
} else {
892-
registerSoftwareChallengeAction(api, connection, next);
893-
}
894-
} else {
893+
}, function(result, cb) {
894+
// If the challenge is not found in the tcs_catalog:project table,
895+
if (result.length === 0) {
896+
// Do nothing, do not register
895897
cb();
898+
return;
899+
}
900+
var isStudio = result[0].isStudio !== 0;
901+
api.challengeHelper.checkUserChallengeEligibility(connection, challengeId, function (err) {
902+
cb(err, isStudio);
903+
});
904+
}, function (isStudio, cb) {
905+
if (_.isUndefined(isStudio)) {
906+
cb();
907+
} else if (isStudio) {
908+
registerStudioChallengeAction(api, connection, next);
909+
} else {
910+
registerSoftwareChallengeAction(api, connection, next);
896911
}
897912
}
898913
], function (err) {

actions/challenges.js

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
22
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.31
4+
* @version 1.32
55
* @author Sky_, mekanizumu, TCSASSEMBLER, freegod, Ghost_141, kurtrips, xjtufreeman, ecnu_haozi, hesibo, LazyChild,
6-
* @author isv, muzehyun, bugbuka
6+
* @author isv, muzehyun, bugbuka, GFalcon
77
* @changes from 1.0
88
* merged with Member Registration API
99
* changes in 1.1:
@@ -79,9 +79,12 @@
7979
* - Update challenge type filter.
8080
* Changes in 1.31:
8181
* - Remove screeningScorecardId and reviewScorecardId from search challenges api.
82+
* Changes in 1.32:
83+
* - validateChallenge function now checks if an user belongs to a group via
84+
* user_group_xref for old challenges and by calling V3 API for new ones.
8285
*/
8386
"use strict";
84-
/*jslint stupid: true, unparam: true, continue: true */
87+
/*jslint stupid: true, unparam: true, continue: true, nomen: true */
8588

8689
require('datejs');
8790
var fs = require('fs');
@@ -851,7 +854,7 @@ var addFilter = function (sql, filter, isMyChallenges, helper, caller) {
851854
* @since 1.10
852855
*/
853856
function validateChallenge(api, connection, dbConnectionMap, challengeId, isStudio, callback) {
854-
var error, sqlParams, helper = api.helper;
857+
var error, sqlParams, helper = api.helper, userId = (connection.caller.userId || 0);
855858
async.waterfall([
856859
function (cb) {
857860
error = helper.checkPositiveInteger(challengeId, 'challengeId') ||
@@ -862,31 +865,18 @@ function validateChallenge(api, connection, dbConnectionMap, challengeId, isStud
862865
}
863866
sqlParams = {
864867
challengeId: challengeId,
865-
user_id: connection.caller.userId || 0
868+
user_id: userId
866869
};
867-
async.parallel({
868-
accessibility: function (cbx) {
869-
api.dataAccess.executeQuery('check_user_challenge_accessibility', sqlParams, dbConnectionMap, cbx);
870-
},
871-
exists: function (cbx) {
872-
api.dataAccess.executeQuery('check_challenge_exists', sqlParams, dbConnectionMap, cbx);
873-
}
874-
}, cb);
870+
api.dataAccess.executeQuery('check_challenge_exists', sqlParams, dbConnectionMap, cb);
875871
}, function (res, cb) {
876-
if (res.exists.length === 0 || Boolean(res.exists[0].is_studio) !== isStudio) {
872+
// If the record with this callengeId doesn't exist in 'project' table
873+
// or there's a studio/software mismatch
874+
if (res.length === 0 || Boolean(res[0].is_studio) !== isStudio) {
877875
cb(new NotFoundError("Challenge not found."));
878876
return;
879877
}
880-
var access = res.accessibility[0];
881-
if (access.is_private && !access.has_access && connection.caller.accessLevel !== "admin") {
882-
if (connection.caller.accessLevel === "anon") {
883-
cb(new UnauthorizedError());
884-
} else {
885-
cb(new ForbiddenError());
886-
}
887-
return;
888-
}
889-
cb();
878+
// Check the eligibility
879+
api.challengeHelper.checkUserChallengeEligibility(connection, challengeId, cb);
890880
}
891881
], callback);
892882
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DATABASE common_oltp;
2+
3+
DELETE FROM user_group_xref WHERE group_id > 3330000 AND group_id < 3330100;
4+
DELETE FROM security_groups WHERE group_id > 3330000 AND group_id < 3330100;
5+
DELETE FROM group_contest_eligibility WHERE contest_eligibility_id > 1110000 AND contest_eligibility_id < 1110100;
6+
DELETE FROM contest_eligibility WHERE contest_eligibility_id > 1110000 AND contest_eligibility_id < 1110100;
7+
8+
DATABASE informixoltp;
9+
10+
-- UPDATE coder SET comp_country_code = NULL WHERE user_id = 132458;
11+
12+
DATABASE tcs_catalog;
13+
14+
DELETE FROM notification WHERE project_id > 1110000 AND project_id < 1110100;
15+
DELETE FROM project_result WHERE project_id > 1110000 AND project_id < 1110100;
16+
DELETE FROM project_user_audit WHERE project_id > 1110000 AND project_id < 1110100;
17+
DELETE FROM component_inquiry WHERE project_id > 1110000 AND project_id < 1110100;
18+
DELETE FROM resource_info WHERE resource_id IN (SELECT resource_id FROM resource WHERE project_id > 1110000 AND project_id < 1110100);
19+
DELETE FROM resource WHERE project_id > 1110000 AND project_id < 1110100;
20+
21+
DELETE FROM project_info WHERE project_id > 1110000 AND project_id < 1110100;
22+
DELETE FROM comp_versions WHERE component_id = 3330333;
23+
DELETE FROM comp_catalog WHERE component_id = 3330333;
24+
DELETE FROM project_phase WHERE project_id > 1110000 AND project_id < 1110100;
25+
DELETE FROM project WHERE project_id > 1110000 AND project_id < 1110100;
26+
27+
DELETE FROM review_item_comment WHERE review_item_comment_id > 7770000 AND review_item_id < 7770100;
28+
DELETE FROM review_item WHERE review_item_id > 5550000 AND review_item_id < 5550100;
29+
DELETE FROM review WHERE review_id > 4440000 AND review_id < 4440100;
30+
DELETE FROM scorecard_question WHERE scorecard_question_id = 3330333;
31+
DELETE FROM scorecard_section WHERE scorecard_section_id = 3330333;
32+
DELETE FROM scorecard_group WHERE scorecard_group_id = 3330333;
33+
DELETE FROM scorecard WHERE scorecard_id = 3330333;
34+
DELETE FROM submission WHERE submission_id > 2220000 AND submission_id < 2220100;
35+
DELETE FROM prize WHERE project_id > 2220000 AND project_id < 2220100;
36+
DELETE FROM upload WHERE project_id > 2220000 AND project_id < 2220100;
37+
DELETE FROM resource WHERE project_id > 2220000 AND project_id < 2220100;
38+
DELETE FROM project_phase WHERE project_id > 2220000 AND project_id < 2220100;
39+
DELETE FROM project WHERE project_id > 2220000 AND project_id < 2220100;

0 commit comments

Comments
 (0)