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

Commit 3292e7c

Browse files
author
fireice.topcoder
committed
restrict registration for copilot posting contest
1 parent eb174ae commit 3292e7c

7 files changed

+155
-74
lines changed

actions/challengeRegistration.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ var persistResource = function (api, resourceId, userId, challengeId, dbConnecti
120120
api.dataAccess.executeQuery("insert_resource", {
121121
resourceId: resourceId,
122122
projectId: challengeId,
123+
userId: userId,
123124
createUser: '"' + userId + '"',
124125
modifyUser: '"' + userId + '"'
125126
},
@@ -566,9 +567,29 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
566567
api.log("Execute registerSoftwareChallengeAction#run", 'debug');
567568

568569
var challengeId = Number(connection.params.challengeId);
570+
var sqlParams = {
571+
challengeId: challengeId,
572+
user_id: connection.caller.userId
573+
};
574+
var execQuery = function (name) {
575+
return function (cbx) {
576+
api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx);
577+
};
578+
};
569579
async.waterfall([
570-
571-
function (cb) {
580+
function(cb) {
581+
async.parallel({
582+
isCopilotPosting: execQuery('check_challenge_is_copilot_posting'),
583+
isCopilot: execQuery('check_is_copilot')
584+
}, cb);
585+
}, function(res, cb) {
586+
if (res.isCopilotPosting.length > 0 && res.isCopilotPosting[0].challenge_is_copilot) {
587+
if (res.isCopilot.length === 0 || !res.isCopilot[0].user_is_copilot) {
588+
cb(new ForbiddenError('You should be a copilot before register a copilot posting.'));
589+
}
590+
}
591+
cb(null);
592+
}, function (cb) {
572593
api.challengeHelper.getChallengeTerms(
573594
connection,
574595
challengeId,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT
2+
(project_id IS NOT NULL) as challenge_is_copilot
3+
FROM project p
4+
WHERE p.project_id = @challengeId@
5+
AND p.project_category_id = 29
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name" : "check_challenge_is_copilot_posting",
3+
"db" : "tcs_catalog",
4+
"sqlfile" : "check_challenge_is_copilot_posting"
5+
}

queries/insert_resource

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
INSERT INTO resource
2-
( resource_id,
3-
resource_role_id,
4-
project_id,
5-
create_user,
6-
create_date,
7-
modify_user,
8-
modify_date)
9-
VALUES
10-
( @resourceId@,
11-
1,
12-
@projectId@,
13-
@createUser@,
14-
CURRENT,
15-
@modifyUser@,
16-
CURRENT
1+
INSERT INTO resource
2+
( resource_id,
3+
resource_role_id,
4+
project_id,
5+
user_id,
6+
create_user,
7+
create_date,
8+
modify_user,
9+
modify_date)
10+
VALUES
11+
( @resourceId@,
12+
1,
13+
@projectId@,
14+
@userId@,
15+
@createUser@,
16+
CURRENT,
17+
@modifyUser@,
18+
CURRENT
1719
)
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
delete from resource_info;
2-
delete from notification;
3-
delete from resource where project_id > 40000000 and project_id < 40000020;
4-
delete from project_result where project_id > 40000000 and project_id < 40000020;
5-
delete from project_user_audit where project_id > 40000000 and project_id < 40000020;
6-
delete from component_inquiry where project_id > 40000000 and project_id < 40000020;
7-
8-
delete from project_info where project_id > 40000000 and project_id < 40000020;
9-
delete from project_phase where project_id > 40000000 and project_id < 40000020;
10-
delete from component_inquiry where project_id > 40000000 and project_id < 40000020;
11-
delete from project where project_id > 40000000 and project_id < 40000020;
12-
delete from comp_version_dates_history where comp_vers_id = 40000001;
13-
delete from comp_versions where component_id > 40000000 and component_id < 40000020;
14-
delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020;
15-
delete from comp_catalog where component_id > 40000000 and component_id < 40000020;
16-
delete from user_rating where user_id = 400011;
17-
delete from user_reliability where user_id = 400011;
18-
delete from project_studio_specification where project_studio_spec_id = 1;
1+
delete from resource_info;
2+
delete from notification;
3+
delete from resource where project_id > 40000000 and project_id < 40000020;
4+
delete from project_result where project_id > 40000000 and project_id < 40000020;
5+
delete from project_user_audit where project_id > 40000000 and project_id < 40000020;
6+
delete from component_inquiry where project_id > 40000000 and project_id < 40000020;
7+
8+
delete from project_info where project_id > 40000000 and project_id < 40000020;
9+
delete from project_phase where project_id > 40000000 and project_id < 40000020;
10+
delete from component_inquiry where project_id > 40000000 and project_id < 40000020;
11+
delete from project where project_id > 40000000 and project_id < 40000020;
12+
delete from comp_version_dates_history where comp_vers_id > 40000000 and comp_vers_id < 40000020;
13+
delete from comp_versions where component_id > 40000000 and component_id < 40000020;
14+
delete from comp_versions where comp_vers_id > 40000000 and comp_vers_id < 40000020;
15+
delete from comp_catalog where component_id > 40000000 and component_id < 40000020;
16+
delete from user_rating where user_id = 400011;
17+
delete from user_reliability where user_id = 400011;
18+
delete from project_studio_specification where project_studio_spec_id = 1;
19+
20+
delete from copilot_profile where copilot_profile_id = 400011;
Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
1-
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null);
2-
3-
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT);
4-
5-
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT);
6-
7-
INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0');
8-
9-
INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0');
10-
11-
INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT);
12-
13-
14-
INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT);
15-
16-
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT);
17-
18-
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1);
19-
20-
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT);
21-
22-
23-
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT);
24-
25-
INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0');
26-
27-
INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0');
28-
29-
30-
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT);
31-
32-
INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null);
33-
34-
INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113);
35-
36-
INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003);
37-
38-
INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131);
1+
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000001, 1, 2, 132456, CURRENT, 132456, CURRENT, 40000011, null);
2+
3+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT);
4+
5+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000001, 2, '40000001', 132456, CURRENT, 132456, CURRENT);
6+
7+
INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000001', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0');
8+
9+
INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000001', '40000001', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0');
10+
11+
INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000001, 40000001, 113, CURRENT);
12+
13+
14+
INSERT INTO project_studio_specification(project_studio_spec_id,contest_description,create_user,create_date,modify_user,modify_date) VALUES (1,'Description of Studio Contest 40000002.','132456',CURRENT,'132456',CURRENT);
15+
16+
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000001, 40000001, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT);
17+
18+
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000002, 1, 20, 132456, CURRENT, 132456, CURRENT, 40000012, 1);
19+
20+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 6, 'Hestia Business Information', 132456, CURRENT, 132456, CURRENT);
21+
22+
23+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000002, 2, '40000002', 132456, CURRENT, 132456, CURRENT);
24+
25+
INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000002', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0');
26+
27+
INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000002', '40000002', '1', '1.0', CURRENT, '131', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0');
28+
29+
30+
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000002, 40000002, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT);
31+
32+
INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 0, 113, null);
33+
34+
INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, null, 113);
35+
36+
INSERT INTO user_rating (user_id, rating, phase_id, last_rated_project_id) values (400011, 3000, 131, 40000003);
37+
38+
INSERT INTO user_reliability (user_id, rating, phase_id) values (400011, 1.00, 131);
39+
40+
INSERT INTO project (project_id, project_status_id, project_category_id, create_user, create_date, modify_user, modify_date, tc_direct_project_id, project_studio_spec_id) VALUES (40000003, 1, 29, 132456, CURRENT, 132456, CURRENT, 40000011, null);
41+
42+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 6, 'Java Throttle 1.0', 132456, CURRENT, 132456, CURRENT);
43+
44+
INSERT INTO project_info (project_id, project_info_type_id, value, create_user, create_date, modify_user, modify_date) VALUES (40000003, 2, '40000003', 132456, CURRENT, 132456, CURRENT);
45+
46+
INSERT INTO comp_catalog (component_id, current_version, short_desc, component_name, description, function_desc, create_time, status_id, root_category_id, modify_date, public_ind) VALUES ('40000003', '1', 'Coolest component ever', 'Component 4', 'Coolest component ever', 'Component', CURRENT, '1', '5801776', CURRENT, '0');
47+
48+
INSERT INTO comp_versions (comp_vers_id, component_id, version, version_text, create_time, phase_id, phase_time, price, comments, modify_date, suspended_ind) VALUES ('40000003', '40000003', '1', '1.0', CURRENT, '113', '1976-05-04 00:00:00.0', '1000.00', 'Cool', CURRENT, '0');
49+
50+
INSERT INTO comp_version_dates_history (comp_version_dates_history_id, comp_vers_id, phase_id , initial_submission_date) VALUES (40000003, 40000003, 113, CURRENT);
51+
52+
INSERT INTO project_phase (project_phase_id, project_id, phase_type_id, phase_status_id, fixed_start_time, scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, duration, create_user, create_date, modify_user, modify_date) VALUES (40000003, 40000003, 1, 2, null, CURRENT + -44640 UNITS MINUTE, CURRENT + -36000 UNITS MINUTE, CURRENT + -44640 UNITS MINUTE, null, 518400000, 132456, CURRENT, 132456, CURRENT);
53+
54+
INSERT INTO copilot_profile(copilot_profile_id, user_id, copilot_profile_status_id, suspension_count, reliability, create_user, create_date, update_user, update_date)
55+
VALUES(400011, 400011, 1, 1, 50, 132456, CURRENT, 132456, CURRENT);

test/test.challengeRegistration.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,33 @@ describe('Challenge Registration API', function () {
297297
.expect(403, done);
298298
});
299299

300+
301+
// Only copilot can register copilot posting.
302+
it('User is not copilot', function (done) {
303+
supertest(API_ENDPOINT)
304+
.post("/v2/challenges/40000003/register")
305+
.set('Accept', 'application/json')
306+
.set('Authorization', getAuthHeader(user12))
307+
.expect('Content-Type', /json/)
308+
.expect(403, done);
309+
});
310+
311+
// Check if the data are in expected structure and data
312+
// It's a copilot posting challenge.
313+
it('User register a copilot posting challenge', function (done) {
314+
supertest(API_ENDPOINT)
315+
.post("/v2/challenges/40000003/register")
316+
.set('Accept', 'application/json')
317+
.set('Authorization', getAuthHeader(user11))
318+
.expect('Content-Type', /json/)
319+
.expect(200)
320+
.end(function (err, result) {
321+
if (err) {
322+
done(err);
323+
return;
324+
}
325+
console.log('Registration completed. Now verify the database is the same as predicted data');
326+
validateDatabaseForDevelop(done);
327+
});
328+
});
300329
});

0 commit comments

Comments
 (0)