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

Commit 24b9eec

Browse files
committed
enable web arena role to create round api
1 parent 0959cb7 commit 24b9eec

File tree

7 files changed

+88
-12
lines changed

7 files changed

+88
-12
lines changed

actions/srmRoundManagement.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ exports.createSRMContestRound = {
430430
params.id = MAX_INT;
431431
var error =
432432
checkContestRound(helper, params) ||
433-
helper.checkAdmin(connection, "You need to be authorized first.", "You are forbidden for this API.");
433+
helper.checkAdminOrWebArenaSuper(connection, "You need to be authorized first.", "You are forbidden for this API.");
434434
cb(error);
435435
},
436436
function (cb) {
@@ -440,6 +440,9 @@ exports.createSRMContestRound = {
440440
},
441441
function (roundId, cbx) {
442442
params.id = roundId;
443+
if (connection.caller.isWebArenaSuper) {
444+
params.type.id = 24;
445+
}
443446
api.dataAccess.executeQuery('insert_srm_contest_round',
444447
{
445448
contest_id: params.contest_id,
@@ -451,7 +454,8 @@ exports.createSRMContestRound = {
451454
name: params.name,
452455
status: params.status,
453456
short_name: params.short_name,
454-
auto_end: params.auto_end
457+
auto_end: params.auto_end,
458+
creator_id: connection.caller.userId
455459
},
456460
dbConnectionMap, cbx);
457461
}
@@ -613,6 +617,9 @@ exports.modifySRMContestRound = {
613617
helper.handleNoConnection(api, connection, next);
614618
return;
615619
}
620+
if (_.isUndefined(params.auto_end)) {
621+
params.auto_end = false;
622+
}
616623
async.series([
617624
function (cb) {
618625
console.log("oldRoundId = " + oldRoundId);

initializers/helper.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* This module contains helper functions.
88
* @author Sky_, Ghost_141, muzehyun, kurtrips, isv, LazyChild, hesibo, panoptimum, flytoj2ee, TCSASSEMBLER
9-
* @version 1.41
9+
* @version 1.42
1010
* changes in 1.1:
1111
* - add mapProperties
1212
* changes in 1.2:
@@ -110,6 +110,8 @@
110110
* - Update getLowerCaseList method to use map method.
111111
* Changes in 1.41:
112112
* - Update apiName2dbNameMap to add entries for srm schedule API.
113+
* Changes in 1.42:
114+
* - Add checkAdminOrWebArenaSuper to check if user has web arena super role.
113115
*/
114116
"use strict";
115117

@@ -1412,6 +1414,20 @@ helper.checkAdmin = function (connection, unauthorizedErrMsg, forbiddenErrMsg) {
14121414
return new ForbiddenError();
14131415
};
14141416

1417+
/**
1418+
* Check whether given user has web arena super role or not
1419+
* @param connection - the api connection object
1420+
* @param {String} unauthorizedErrMsg - the error message for unauthorized error.
1421+
* @param {String} forbiddenErrMsg - the error message for forbidden error.
1422+
* @return {Error} if user is not admin or does not have web arena super role.
1423+
*/
1424+
helper.checkAdminOrWebArenaSuper = function (connection, unauthorizedErrMsg, forbiddenErrMsg) {
1425+
if (connection.caller.isWebArenaSuper) {
1426+
return null;
1427+
}
1428+
return helper.checkAdmin(connection, unauthorizedErrMsg, forbiddenErrMsg);
1429+
};
1430+
14151431
/**
14161432
* Check if the caller has at least member access level.
14171433
* @param {Object} connection - the connection object.

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@)

test/test.srmRoundManagement.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/*
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.0
5-
* @author TCASSEMBLER
4+
* @version 1.1
5+
* @author TCASSEMBLER, TCSFINALFIXER
6+
*
7+
* Changes in 1.1:
8+
* - Add test 'should create new round for web arena super role'
69
*/
710
"use strict";
811
/*global describe, it, before, beforeEach, after, afterEach */
@@ -1328,9 +1331,53 @@ describe('SRM Round Management APIs', function () {
13281331
}
13291332
], done);
13301333
});
1331-
});
1332-
13331334

1335+
it('should create new round for web arena super role', function (done) {
1336+
async.waterfall([
1337+
_.bind(testHelper.runSqlSelectQuery, testHelper, GET_ROUND_SEQ_SQL, "informixoltp"),
1338+
function (results, cb) {
1339+
var roundId = results[0].next_id + 1,
1340+
req = _.clone(goodRequest),
1341+
jwt = testHelper.generateAuthHeader({sub: 'ad|124861'});
1342+
request(API_ENDPOINT)
1343+
.post('/v2/data/srm/rounds')
1344+
.set('Accept', 'application/json')
1345+
.set('Content-Type', 'application/json')
1346+
.set('Authorization', jwt)
1347+
.expect('Content-Type', /json/)
1348+
.expect(200)
1349+
.send(req)
1350+
.end(function (err, res) {
1351+
if (err) {
1352+
return cb(err);
1353+
}
1354+
assert.equal(res.body.roundId, roundId);
1355+
testHelper.runSqlSelectQuery(
1356+
"creator_id, round_type_id from round where round_id = " + roundId,
1357+
"informixoltp",
1358+
function (error, results) {
1359+
if (error) {
1360+
return cb(error);
1361+
}
1362+
assert.ok(results && results.length === 1, "query should have succeeded.");
1363+
assert.equal(
1364+
results[0].creator_id,
1365+
124861,
1366+
"creator should be ksmith"
1367+
);
1368+
assert.equal(
1369+
results[0].round_type_id,
1370+
24,
1371+
"round type should be 'Instant Match'"
1372+
);
1373+
return cb();
1374+
}
1375+
);
1376+
});
1377+
}
1378+
], done);
1379+
});
1380+
});
13341381
});
13351382

13361383
describe("Modify SRM Contest Round", function () {

test/test_files/srmRoundManagement/contest30002.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"id": 11,
1616
"desc": "Weakest Link Round"
1717
},
18-
"segments": {
18+
"segments": {
19+
"codingStartTime": 1383958200000,
20+
"registrationStartTime": 1381276200000,
1921
"registrationStart": "Oct 08, 2013 21:50 EDT",
2022
"registrationLength": 60,
2123
"registrationStatus": "A",
@@ -78,4 +80,4 @@
7880
}
7981
}
8082
]
81-
}
83+
}

test/test_files/srmRoundManagement/contest30007.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
"challengeStatus": "A",
5050
"codingLength": 60,
5151
"codingStart": "Nov 08, 2013 20:50 EST",
52+
"codingStartTime": 1383958200000,
53+
"registrationStartTime": 1381276200000,
5254
"codingStatus": "A",
5355
"intermissionLength": 60,
5456
"intermissionStatus": "A",

test/test_files/srmRoundManagement/contest30011.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"challengeStatus": "A",
5151
"codingLength": 60,
5252
"codingStart": "Nov 08, 2013 20:50 EST",
53+
"codingStartTime": 1383958200000,
54+
"registrationStartTime":1381276200000,
5355
"codingStatus": "A",
5456
"intermissionLength": 60,
5557
"intermissionStatus": "A",
@@ -79,4 +81,4 @@
7981
}
8082

8183
]
82-
}
84+
}

0 commit comments

Comments
 (0)