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

Commit f9a1daa

Browse files
committed
Merge branch 'dev' of github.com:cloudspokes/tc-api into dev
2 parents 70212a6 + 547460e commit f9a1daa

16 files changed

+351
-34
lines changed

actions/srmProblems.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
* - listRoundProblems will include round id
1212
* - listRoundProblemComponents will include round id
1313
*
14-
* @version 1.1
14+
* Changes in 1.2 (TC API - List SRM Problems API Update)
15+
* - Update listSRMProblems api to allow web arena super user access it.
16+
* @version 1.2
1517
* @author TCSASSEMBLER
1618
*/
1719
/*jslint node: true, nomen: true, plusplus: true */
@@ -21,6 +23,7 @@ var _ = require('underscore');
2123
var moment = require('moment');
2224
var IllegalArgumentError = require('../errors/IllegalArgumentError');
2325
var NotFoundError = require('../errors/NotFoundError');
26+
var UnauthorizedError = require('../errors/UnauthorizedError');
2427
var ForbiddenError = require('../errors/ForbiddenError');
2528

2629
/**
@@ -206,6 +209,12 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
206209
});
207210
};
208211

212+
/**
213+
* The filter for list SRM problem api when caller is the web arena super user.
214+
* @type {string}
215+
*/
216+
var SRM_PROBLEM_WEB_ARENA_SUPER_FILTER = " AND p.status_id = 90";
217+
209218
/**
210219
* Get SRM problems.
211220
*
@@ -216,14 +225,36 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
216225
*/
217226
var listSRMProblems = function (api, connection, dbConnectionMap, next) {
218227
var helper = api.helper,
228+
caller = connection.caller,
219229
result = [],
220230
sqlParams = {};
221231

222232
async.waterfall([
223233
function (cb) {
224-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
234+
if (!helper.isAdmin(caller) && !caller.isWebArenaSuper) {
235+
if (!helper.isMember(caller)) {
236+
cb(new UnauthorizedError("Authorized information needed."));
237+
} else {
238+
cb(new ForbiddenError("Admin or web Arena super user only."));
239+
}
240+
} else {
241+
cb();
242+
}
243+
//cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
225244
}, function (cb) {
226-
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
245+
if (caller.isWebArenaSuper) {
246+
async.waterfall([
247+
function (cbx) {
248+
helper.readQuery("get_srm_problems", cbx);
249+
},
250+
function (sql, cbx) {
251+
sql = helper.editSql(sql, SRM_PROBLEM_WEB_ARENA_SUPER_FILTER, null);
252+
api.dataAccess.executeSqlQuery(sql, sqlParams, "informixoltp", dbConnectionMap, cbx);
253+
}
254+
], cb);
255+
} else {
256+
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
257+
}
227258
}, function (results, cb) {
228259
_.each(results, function (item) {
229260
result.push(parseProblem(item));

actions/srmRoundManagement.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66
*
77
* Changes in version 1.1 (Module Assembly - Web Arena - Match Configurations):
88
* - Updated ListSRMContestRounds to send UTC time in milliseconds for registration and coding start time
9+
* Changes in version 1.2 (First2Finish - TC API - Modify SRM Round API Update):
10+
* - updated modifySRMContestRound to support web arena super role
911
*
10-
* @version 1.1
12+
* @version 1.2
1113
* @author TCSASSEMBLER
1214
*/
1315
/*jslint node: true, nomen: true */
1416
"use strict";
1517
var async = require('async');
1618
var _ = require('underscore');
1719
var NotFoundError = require('../errors/NotFoundError');
20+
var ForbiddenError = require('../errors/ForbiddenError');
1821

1922
/**
2023
* Max value for integer
@@ -430,7 +433,7 @@ exports.createSRMContestRound = {
430433
params.id = MAX_INT;
431434
var error =
432435
checkContestRound(helper, params) ||
433-
helper.checkAdmin(connection, "You need to be authorized first.", "You are forbidden for this API.");
436+
helper.checkAdminOrWebArenaSuper(connection, "You need to be authorized first.", "You are forbidden for this API.");
434437
cb(error);
435438
},
436439
function (cb) {
@@ -440,6 +443,9 @@ exports.createSRMContestRound = {
440443
},
441444
function (roundId, cbx) {
442445
params.id = roundId;
446+
if (connection.caller.isWebArenaSuper) {
447+
params.type.id = 24;
448+
}
443449
api.dataAccess.executeQuery('insert_srm_contest_round',
444450
{
445451
contest_id: params.contest_id,
@@ -451,7 +457,8 @@ exports.createSRMContestRound = {
451457
name: params.name,
452458
status: params.status,
453459
short_name: params.short_name,
454-
auto_end: params.auto_end
460+
auto_end: params.auto_end,
461+
creator_id: connection.caller.userId
455462
},
456463
dbConnectionMap, cbx);
457464
}
@@ -613,13 +620,20 @@ exports.modifySRMContestRound = {
613620
helper.handleNoConnection(api, connection, next);
614621
return;
615622
}
623+
if (_.isUndefined(params.auto_end)) {
624+
params.auto_end = false;
625+
}
616626
async.series([
617627
function (cb) {
618628
console.log("oldRoundId = " + oldRoundId);
619629
var error =
620-
helper.checkIdParameter(oldRoundId, 'oldRoundId') ||
621-
checkContestRound(helper, params) ||
622-
helper.checkAdmin(connection, "You need to be authorized first.", "You are forbidden for this API.");
630+
helper.checkIdParameter(oldRoundId, 'oldRoundId') ||
631+
checkContestRound(helper, params) ||
632+
helper.checkAdminOrWebArenaSuper(
633+
connection,
634+
"You need to be authorized first.",
635+
"You are forbidden for this API."
636+
);
623637
cb(error);
624638
},
625639
// check if modifying round existed.
@@ -630,10 +644,12 @@ exports.modifySRMContestRound = {
630644
}, dbConnectionMap),
631645
function (result, cbx) {
632646
if (result.length === 0) {
633-
cbx(new NotFoundError('modifying round is not existed.'));
634-
} else {
635-
cbx(null);
647+
return cbx(new NotFoundError('modifying round is not existed.'));
648+
}
649+
if (connection.caller.isWebArenaSuper && result[0].creator_id !== connection.caller.userId) {
650+
return cbx(new ForbiddenError('Round was not created by you.'));
636651
}
652+
return cbx();
637653
}], cb);
638654
},
639655
function (cb) {

apiary.apib

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8513,6 +8513,16 @@ Request
85138513
"description":"The request is understood, but it has been refused or access is not allowed."
85148514
}
85158515

8516+
+ Response 403 (application/json)
8517+
8518+
{
8519+
"name":"Forbidden",
8520+
"value":"403",
8521+
"description": "The request is understood, but it has been refused or access is not allowed."
8522+
"details": "Round was not created by you."
8523+
}
8524+
8525+
85168526
+ Response 404 (application/json)
85178527

85188528
{

queries/get_round_onlyid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
select round_id from round where round_id=@round_id@;
1+
select round_id, creator_id from round where round_id=@round_id@;

queries/get_srm_problems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ t.problem_type_desc AS problem_type_desc
99
FROM problem p
1010
LEFT OUTER JOIN problem_status_lu s ON p.status_id = s.problem_status_id
1111
LEFT OUTER JOIN problem_type_lu t ON p.problem_type_id = t.problem_type_id
12+
WHERE 1=1

queries/insert_srm_contest_round

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name, auto_end)
2-
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@', @auto_end@)
1+
INSERT INTO round (round_id, contest_id, round_type_id, registration_limit, invitational, region_id, name, status, short_name, auto_end, creator_id)
2+
VALUES (@round_id@, @contest_id@, @round_type_id@, @registration_limit@, @invitational@, @region_id@, '@name@', '@status@', '@short_name@', @auto_end@, @creator_id@)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
DELETE FROM round_component WHERE round_id = 13672 and division_id = 1;
1+
DELETE FROM round_component WHERE round_id = 13672 and division_id = 1;
2+
DELETE FROM problem WHERE problem_id = 2001;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

2-
INSERT INTO 'informix'.round_component(round_id, component_id, submit_order, division_id, difficulty_id, points, open_order) VALUES(13672, 2020, 0, 1, 1, 500, 0);
2+
INSERT INTO 'informix'.round_component(round_id, component_id, submit_order, division_id, difficulty_id, points, open_order) VALUES(13672, 2020, 0, 1, 1, 500, 0);
3+
INSERT INTO 'informix'.problem(problem_id, name, status_id, proposed_division_id, problem_type_id) VALUES(2001, "Used Problem", 90, 1, 1);

test/sqls/srmRoundManagement/informixoltp__insert_rounds

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ INSERT INTO contest (contest_id, name, status, group_id) VALUES (30007, "Contest
5555
INSERT INTO contest (contest_id, name, status, group_id) VALUES (30008, "Contest 8", "A", -1);
5656
INSERT INTO contest (contest_id, name, status, group_id) VALUES (30009, "Contest 9", "A", -1);
5757

58-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational)
59-
VALUES (40055, 30006, "Round 7", "A", 11, 'short name 7', 1, 0, 5);
58+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational, creator_id)
59+
VALUES (40055, 30006, "Round 7", "A", 11, 'short name 7', 1, 0, 5, 124861);
6060
INSERT INTO SURVEY(survey_id, name, start_date, end_date, status_id, text)
6161
VALUES (40055, 'survey2', '2013-10-09 01:50:00', '2013-10-09 02:50:00', 1, 'text 2');
6262
INSERT INTO round_room_assignment (round_id, coders_per_room, algorithm, by_division, final, by_region, p)
@@ -82,8 +82,8 @@ INSERT INTO round_segment (round_id, segment_id, start_time, end_time, status)
8282
INSERT INTO room (room_id, round_id, name, division_id, room_type_id) VALUES (499154, 40055, "Admin Room", -1, 1);
8383

8484

85-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational)
86-
VALUES (40060, 30009, "Round 8", "A", 11, 'short name 8', 1, 0, 5);
85+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational, creator_id)
86+
VALUES (40060, 30009, "Round 8", "A", 11, 'short name 8', 1, 0, 5, 132456);
8787
INSERT INTO SURVEY(survey_id, name, start_date, end_date, status_id, text)
8888
VALUES (40060, 'survey3', '2013-10-09 01:50:00', '2013-10-09 02:50:00', 1, 'text 3');
8989
INSERT INTO round_room_assignment (round_id, coders_per_room, algorithm, by_division, final, by_region, p)
@@ -128,8 +128,8 @@ INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name
128128
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational)
129129
VALUES (41005, 30010, "Round 5", "A", 10, 'short name 5', 1, 512, 4);
130130

131-
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational)
132-
VALUES (41006, 30011, "Round 6", "A", 11, 'short name 6', 1, 0, 5);
131+
INSERT INTO round (round_id, contest_id, name, status, round_type_id, short_name, region_id, registration_limit, invitational, creator_id)
132+
VALUES (41006, 30011, "Round 6", "A", 11, 'short name 6', 1, 0, 5, 124861);
133133
INSERT INTO SURVEY(survey_id, name, start_date, end_date, status_id, text)
134134
VALUES (41006, 'survey1', '2013-10-09 01:50:00', '2013-10-09 02:50:00', 1, 'text 1');
135135
INSERT INTO round_room_assignment (round_id, coders_per_room, algorithm, by_division, final, by_region, p)

test/test.srmProblems.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ var API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:8080',
2929
USER = {
3030
heffan : "ad|132456",
3131
"super" : "ad|132457",
32-
user : "ad|132458"
32+
user : "ad|132458",
33+
ksmith : "ad|124861",
34+
twight : "ad|124766"
3335
};
3436

3537

@@ -146,14 +148,22 @@ describe('SRM Round Problem APIs', function () {
146148
});
147149

148150
it("Admin access only.", function (done) {
149-
assertError("/v2/data/srm/problems", 'user', 403, "Admin access only.", done);
151+
assertError("/v2/data/srm/problems", 'user', 403, "Admin or web Arena super user only.", done);
152+
});
153+
154+
it("Admin or web arena only.", function (done) {
155+
assertError("/v2/data/srm/problems", 'twight', 403, "Admin or web Arena super user only.", done);
150156
});
151157

152158
it("Valid request.", function (done) {
153159
validateResult("/v2/data/srm/problems", 'heffan',
154160
"./test_files/srm_problems/list_srm_problems.json", done);
155161
});
156162

163+
it("Valid request with web arena super user.", function (done) {
164+
validateResult("/v2/data/srm/problems", "ksmith", "./test_files/srm_problems/list_used_srm_problems.json", done);
165+
});
166+
157167
});
158168

159169
describe('List SRM Round Problems API', function () {
@@ -278,4 +288,4 @@ describe('SRM Round Problem APIs', function () {
278288
"./test_files/srm_problems/list_round_problem_components_global.json", done);
279289
});
280290
});
281-
});
291+
});

0 commit comments

Comments
 (0)