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

Commit 7b6c86e

Browse files
committed
merge changes
2 parents 8a39be1 + 24b9eec commit 7b6c86e

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

actions/srmRoundManagement.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ exports.createSRMContestRound = {
433433
params.id = MAX_INT;
434434
var error =
435435
checkContestRound(helper, params) ||
436-
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.");
437437
cb(error);
438438
},
439439
function (cb) {
@@ -443,6 +443,9 @@ exports.createSRMContestRound = {
443443
},
444444
function (roundId, cbx) {
445445
params.id = roundId;
446+
if (connection.caller.isWebArenaSuper) {
447+
params.type.id = 24;
448+
}
446449
api.dataAccess.executeQuery('insert_srm_contest_round',
447450
{
448451
contest_id: params.contest_id,
@@ -454,7 +457,8 @@ exports.createSRMContestRound = {
454457
name: params.name,
455458
status: params.status,
456459
short_name: params.short_name,
457-
auto_end: params.auto_end
460+
auto_end: params.auto_end,
461+
creator_id: connection.caller.userId
458462
},
459463
dbConnectionMap, cbx);
460464
}

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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Changes in 1.1:
88
* - Add tests 'should 403 if web arena super modifies round not his own',
99
* 'should modify own round for web arena super role'
10+
* - Add test 'should create new round for web arena super role'
1011
*/
1112
"use strict";
1213
/*global describe, it, before, beforeEach, after, afterEach */
@@ -1332,6 +1333,52 @@ describe('SRM Round Management APIs', function () {
13321333
}
13331334
], done);
13341335
});
1336+
1337+
it('should create new round for web arena super role', function (done) {
1338+
async.waterfall([
1339+
_.bind(testHelper.runSqlSelectQuery, testHelper, GET_ROUND_SEQ_SQL, "informixoltp"),
1340+
function (results, cb) {
1341+
var roundId = results[0].next_id + 1,
1342+
req = _.clone(goodRequest),
1343+
jwt = testHelper.generateAuthHeader({sub: 'ad|124861'});
1344+
request(API_ENDPOINT)
1345+
.post('/v2/data/srm/rounds')
1346+
.set('Accept', 'application/json')
1347+
.set('Content-Type', 'application/json')
1348+
.set('Authorization', jwt)
1349+
.expect('Content-Type', /json/)
1350+
.expect(200)
1351+
.send(req)
1352+
.end(function (err, res) {
1353+
if (err) {
1354+
return cb(err);
1355+
}
1356+
assert.equal(res.body.roundId, roundId);
1357+
testHelper.runSqlSelectQuery(
1358+
"creator_id, round_type_id from round where round_id = " + roundId,
1359+
"informixoltp",
1360+
function (error, results) {
1361+
if (error) {
1362+
return cb(error);
1363+
}
1364+
assert.ok(results && results.length === 1, "query should have succeeded.");
1365+
assert.equal(
1366+
results[0].creator_id,
1367+
124861,
1368+
"creator should be ksmith"
1369+
);
1370+
assert.equal(
1371+
results[0].round_type_id,
1372+
24,
1373+
"round type should be 'Instant Match'"
1374+
);
1375+
return cb();
1376+
}
1377+
);
1378+
});
1379+
}
1380+
], done);
1381+
});
13351382
});
13361383
});
13371384

0 commit comments

Comments
 (0)