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

Commit 915d0e2

Browse files
committed
enable modify srm contest and add srm contest api for web arena super role
1 parent f9a1daa commit 915d0e2

File tree

2 files changed

+98
-73
lines changed

2 files changed

+98
-73
lines changed

actions/srmChallenges.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.10
5-
* @author Sky_, freegod, panoptimum, Ghost_141, onsky
4+
* @version 1.11
5+
* @author Sky_, freegod, panoptimum, Ghost_141, onsky, TCSFIRST2FINISHER
66
* changes in 1.1:
77
* - implement srm API
88
* changes in 1.2:
@@ -30,6 +30,8 @@
3030
* - Implement Rounds For Problem API
3131
* Changes in 1.10:
3232
* - Update the get srm schedule API.
33+
* Changes in 1.11 (TC API - Create SRM Contest API and Modify SRM Contest API Update):
34+
* - Enable web arena super role access for createSRMContest, updateSRMContest
3335
*/
3436
/*jslint node: true, nomen: true */
3537
"use strict";
@@ -229,6 +231,7 @@ var LEADER_COUNT = 5;
229231
* Forbidden error message for non-admin users
230232
*/
231233
var NON_ADMIN_MESSAGE = "Admin access only.",
234+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or Web Arena Super access only.",
232235
UNAUTHORIZED_MESSAGE = "Authorized access only.";
233236
/**
234237
* The API for searching SRM challenges
@@ -264,7 +267,7 @@ exports.searchSRMChallenges = {
264267
pageIndex = Number(params.pageIndex || 1);
265268
pageSize = Number(params.pageSize || DEFAULT_PAGE_SIZE);
266269
listType = (params.listType || 'ACTIVE').toUpperCase();
267-
challengeName = '%' + params.challengeName.toLowerCase() + '%' || '%';
270+
challengeName = _.has(params, 'challengeName') ? '%' + params.challengeName.toLowerCase() + '%' : '%';
268271

269272
if (!_.isDefined(params.sortOrder) && sortColumn === "roundid") {
270273
sortOrder = "desc";
@@ -1434,7 +1437,11 @@ exports.createSRMContest = {
14341437
async.auto(
14351438
{
14361439
admin: function (cb) {
1437-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1440+
cb(helper.checkAdminOrWebArenaSuper(
1441+
connection,
1442+
UNAUTHORIZED_MESSAGE,
1443+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE
1444+
));
14381445
},
14391446
common: [ // do common validations
14401447
'admin',
@@ -1536,7 +1543,11 @@ exports.updateSRMContest = {
15361543
async.auto(
15371544
{
15381545
admin: function (cb) {
1539-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1546+
cb(helper.checkAdminOrWebArenaSuper(
1547+
connection,
1548+
UNAUTHORIZED_MESSAGE,
1549+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE
1550+
));
15401551
},
15411552
validate: [
15421553
'admin',

test/test.SRMContestManagement.js

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/*
22
* Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.0
5-
* @author panoptimum
4+
* @version 1.1
5+
* @author panoptimum, TCSFIRST2FINISHER
6+
*
7+
* Changes in 1.1:
8+
* - Remove checks for contestId, for its no longer an argument to the create api.
9+
* - Add tests for create, modify of web arena super role.
610
*/
711
/*global describe, it, before, beforeEach, after, afterEach*/
812
/*jslint node: true, nomen: true*/
@@ -35,7 +39,8 @@ var API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:8080',
3539
USER = {
3640
heffan : "ad|132456",
3741
"super" : "ad|132457",
38-
user : "ad|132458"
42+
user : "ad|132458",
43+
ksmith : "ad|124861"
3944
};
4045

4146
/* This function returns a function that takes a callback and runs a sql file
@@ -83,7 +88,8 @@ function createGetRequest(data) {
8388
function createPutRequest(data) {
8489
var result = request(API_ENDPOINT)
8590
.put(data.route)
86-
.set('Accept', 'application/json');
91+
.set('Accept', 'application/json')
92+
.send(data.request);
8793
if (data.handle) {
8894
result.set('Authorization', generateAuthHeader(data.handle));
8995
}
@@ -289,24 +295,26 @@ function create(request, response, status, handle) {
289295
});
290296
} else {
291297
result = function (done) {
292-
async.series(
298+
async.waterfall(
293299
[
294-
assertResponse("post", {
295-
handle: handle,
296-
request: request,
297-
response: response,
298-
status: status,
299-
route: ROUTE
300-
}),
301-
async.apply(getContest, request.contestId)
302-
],
303-
function (error, results) {
304-
if (error) {
305-
done(error);
306-
} else {
307-
assert.deepEqual(results[1], request, "Contest was correctly created.");
308-
done();
300+
_.bind(
301+
testHelper.runSqlSelectQuery,
302+
testHelper,
303+
'SEQUENCE_CONTEST_SEQ.NEXTVAL as next_id from table(set{1})',
304+
'informixoltp'
305+
),
306+
function (result, cb) {
307+
assertResponse("post", {
308+
handle: handle,
309+
request: request,
310+
response: {contestId: result[0].next_id + 1},
311+
status: status,
312+
route: ROUTE
313+
})(cb);
309314
}
315+
],
316+
function (error) {
317+
return done(error);
310318
}
311319
);
312320
};
@@ -341,7 +349,7 @@ function modify(request, response, status, handle, id) {
341349
{}
342350
);
343351
if (status !== 200) {
344-
result = assertResponse("post", {
352+
result = assertResponse("put", {
345353
handle: handle,
346354
request: request,
347355
response: response,
@@ -352,7 +360,7 @@ function modify(request, response, status, handle, id) {
352360
result = function (done) {
353361
async.series(
354362
[
355-
assertResponse("post", {
363+
assertResponse("put", {
356364
handle: handle,
357365
request: request,
358366
response: response,
@@ -394,7 +402,7 @@ function modify(request, response, status, handle, id) {
394402
async.series(
395403
[
396404
async.apply(getRound, id),
397-
assertResponse("post", {
405+
assertResponse("put", {
398406
handle: handle,
399407
request: request,
400408
response: response,
@@ -495,55 +503,13 @@ describe('SRM Contest Management APIs', function () {
495503
"name": "Forbidden",
496504
"value": 403,
497505
"description": "The request is understood, but it has been refused or access is not allowed.",
498-
"details": "Admin access only."
506+
"details": "Admin or Web Arena Super access only."
499507
}},
500508
403,
501509
"user"
502510
)
503511
);
504512

505-
506-
it(
507-
"Invalid contestId.",
508-
create(
509-
{
510-
name: "name",
511-
contestId: "foobar"
512-
},
513-
{
514-
"error": {
515-
"name": "Bad Request",
516-
"value": 400,
517-
"description": "The request was invalid. An accompanying message will explain why.",
518-
"details": "contestId should be number."
519-
}
520-
},
521-
400,
522-
"heffan"
523-
)
524-
);
525-
526-
527-
it(
528-
"Invalid contestId - already exists.",
529-
create(
530-
{
531-
name: "name",
532-
contestId: 1001
533-
},
534-
{
535-
"error": {
536-
"name": "Bad Request",
537-
"value": 400,
538-
"description": "The request was invalid. An accompanying message will explain why.",
539-
"details": "contestId is already in use."
540-
}
541-
},
542-
400,
543-
"heffan"
544-
)
545-
);
546-
547513
it(
548514
"Invalid name - no string",
549515
create(
@@ -1143,7 +1109,7 @@ describe('SRM Contest Management APIs', function () {
11431109
"name": "Forbidden",
11441110
"value": 403,
11451111
"description": "The request is understood, but it has been refused or access is not allowed.",
1146-
"details": "Admin access only."
1112+
"details": "Admin or Web Arena Super access only."
11471113
}},
11481114
403,
11491115
"user",
@@ -1857,7 +1823,6 @@ describe('SRM Contest Management APIs', function () {
18571823
"Create a new Contest.",
18581824
create(
18591825
{
1860-
"contestId": 1010,
18611826
"name": "Name 10",
18621827
"startDate": "2014-06-11 09:00",
18631828
"endDate": "2014-06-21 09:00",
@@ -1876,6 +1841,30 @@ describe('SRM Contest Management APIs', function () {
18761841
"heffan"
18771842
)
18781843
);
1844+
1845+
it(
1846+
"Create a new Contest with web arena super role.",
1847+
create(
1848+
{
1849+
"name": "Name 10",
1850+
"startDate": "2014-06-11 09:00",
1851+
"endDate": "2014-06-21 09:00",
1852+
"status": "A",
1853+
"groupId": -1,
1854+
"adText": "Ad Text 10",
1855+
"adStart": "2014-06-12 09:00",
1856+
"adEnd": "2014-06-17 09:00",
1857+
"adTask": "Ad Task 10",
1858+
"adCommand": "Ad Command 10",
1859+
"activateMenu": null,
1860+
"seasonId": 2
1861+
},
1862+
{"success": true},
1863+
200,
1864+
"ksmith"
1865+
)
1866+
);
1867+
18791868
});
18801869

18811870
describe('Modify SRM Contest API', function () {
@@ -1916,6 +1905,31 @@ describe('SRM Contest Management APIs', function () {
19161905
)
19171906
);
19181907

1908+
it(
1909+
"Modify contest - id === contestId && web arena super role",
1910+
modify(
1911+
{
1912+
"contestId": 1010,
1913+
"name": "New Name",
1914+
"startDate": "2014-06-11 10:00",
1915+
"endDate": "2014-06-21 10:00",
1916+
"status": "F",
1917+
"groupId": null,
1918+
"adText": "Ad New Text",
1919+
"adStart": "2014-06-12 10:00",
1920+
"adEnd": "2014-06-17 10:00",
1921+
"adTask": "Ad New Task",
1922+
"adCommand": "Ad New Command",
1923+
"activateMenu": 0,
1924+
"seasonId": 1
1925+
},
1926+
{"success": true},
1927+
200,
1928+
"ksmith",
1929+
1010
1930+
)
1931+
);
1932+
19191933
it(
19201934
"Modify contest - id !== contestId",
19211935
modify(

0 commit comments

Comments
 (0)