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

Commit 03b0100

Browse files
committed
enable set round language, segments, components and terms apis for web arena super role
1 parent 69c29f2 commit 03b0100

File tree

5 files changed

+61
-32
lines changed

5 files changed

+61
-32
lines changed

actions/srmChallenges.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ exports.setRoundLanguages = {
18861886
async.auto(
18871887
{
18881888
admin: function (cb) {
1889-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1889+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
18901890
},
18911891
roundId: [
18921892
'admin',

actions/srmRoundComponentsAndTerms.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ var _ = require('underscore');
1414
var moment = require('moment');
1515
var IllegalArgumentError = require('../errors/IllegalArgumentError');
1616

17+
/**
18+
* Error messages
19+
*/
20+
var NON_ADMIN_MESSAGE = "Admin access only.",
21+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or web Arena super user only.",
22+
UNAUTHORIZED_MESSAGE = "Authorized information needed.";
23+
1724
/**
1825
* Check whether the given value is defined and id parameter.
1926
* @param value - the given value.
@@ -206,7 +213,7 @@ var setRoundComponents = function (api, connection, dbConnectionMap, next) {
206213

207214
async.waterfall([
208215
function (cb) {
209-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
216+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
210217
}, function (cb) {
211218
checkRoundId(api, dbConnectionMap, roundId, cb);
212219
}, function (error, cb) {
@@ -278,7 +285,7 @@ var setRoundTerms = function (api, connection, dbConnectionMap, next) {
278285

279286
async.waterfall([
280287
function (cb) {
281-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
288+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
282289
}, function (cb) {
283290
checkRoundId(api, dbConnectionMap, roundId, cb);
284291
}, function (error, cb) {

actions/srmRoundSegments.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ var IllegalArgumentError = require('../errors/IllegalArgumentError');
2020

2121
var DATE_FORMAT = "YYYY-MM-DD HH:mm:ssZZ";
2222
var DB_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss";
23+
24+
/**
25+
* Error messages
26+
*/
27+
var NON_ADMIN_MESSAGE = "Admin access only.",
28+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or web Arena super user only.",
29+
UNAUTHORIZED_MESSAGE = "Authorized information needed.";
30+
2331
/**
2432
* Check round id.
2533
*
@@ -155,7 +163,7 @@ var setRoundSegments = function (api, connection, dbConnectionMap, next) {
155163

156164
async.waterfall([
157165
function (cb) {
158-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
166+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
159167
}, function (cb) {
160168
checkRoundId(api, dbConnectionMap, roundId, cb);
161169
}, function (error, cb) {

test/test.srmRoundComponentsAndTerms.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ var API_ENDPOINT = process.env.API_ENDPOINT || 'http://localhost:8080',
2828
USER = {
2929
heffan : "ad|132456",
3030
"super" : "ad|132457",
31-
user : "ad|132458"
31+
user : "ad|132458",
32+
ksmith : "ad|124861" // web arena super user
3233
};
3334

3435

@@ -168,14 +169,18 @@ describe('SRM Round Components And Terms APIs', function () {
168169
assertPostError("/v2/data/srm/rounds/13673/components", null, validRequest, 401, "Authorized information needed.", done);
169170
});
170171

171-
it("Admin access only.", function (done) {
172-
assertPostError("/v2/data/srm/rounds/13673/components", 'user', validRequest, 403, "Admin access only.", done);
172+
it("Admin or web Arena super user only.", function (done) {
173+
assertPostError("/v2/data/srm/rounds/13673/components", 'user', validRequest, 403, "Admin or web Arena super user only.", done);
173174
});
174175

175176
it("roundId should be number.", function (done) {
176177
assertPostError("/v2/data/srm/rounds/13673a/components", 'heffan', validRequest, 400, "roundId should be number.", done);
177178
});
178179

180+
it("roundId should be number (with web Arena super user).", function (done) {
181+
assertPostError("/v2/data/srm/rounds/13673a/components", 'ksmith', validRequest, 400, "roundId should be number.", done);
182+
});
183+
179184
it("roundId should be Integer.", function (done) {
180185
assertPostError("/v2/data/srm/rounds/13673.01/components", 'heffan', validRequest, 400, "roundId should be Integer.", done);
181186
});
@@ -195,46 +200,46 @@ describe('SRM Round Components And Terms APIs', function () {
195200
"components should be Array.", done);
196201
});
197202

198-
it("componentId should not be null or undefined", function (done) {
203+
it("componentId should be provided", function (done) {
199204
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
200205
{"points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1}]};
201206
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
202-
"componentId should not be null or undefined", done);
207+
"componentId should be provided", done);
203208
});
204209

205-
it("points should not be null or undefined", function (done) {
210+
it("points should be provided", function (done) {
206211
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
207212
{"componentId": 2021, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1}]};
208213
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
209-
"points should not be null or undefined", done);
214+
"points should be provided", done);
210215
});
211216

212-
it("divisionId should not be null or undefined", function (done) {
217+
it("divisionId should be provided", function (done) {
213218
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
214219
{"componentId": 2021, "points": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1}]};
215220
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
216-
"divisionId should not be null or undefined", done);
221+
"divisionId should be provided", done);
217222
});
218223

219-
it("difficultyId should not be null or undefined", function (done) {
224+
it("difficultyId should be provided", function (done) {
220225
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
221226
{"componentId": 2021, "points": 1, "divisionId": 1, "openOrder": 1, "submitOrder": 1}]};
222227
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
223-
"difficultyId should not be null or undefined", done);
228+
"difficultyId should be provided", done);
224229
});
225230

226-
it("openOrder should not be null or undefined", function (done) {
231+
it("openOrder should be provided", function (done) {
227232
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
228233
{"componentId": 2021, "points": 1, "divisionId": 1, "difficultyId": 1, "submitOrder": 1}]};
229234
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
230-
"openOrder should not be null or undefined", done);
235+
"openOrder should be provided", done);
231236
});
232237

233-
it("submitOrder should not be null or undefined", function (done) {
238+
it("submitOrder should be provided", function (done) {
234239
validRequest = {"components": [{"componentId": 2020, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1, "submitOrder": 1},
235240
{"componentId": 2021, "points": 1, "divisionId": 1, "difficultyId": 1, "openOrder": 1}]};
236241
assertPostError("/v2/data/srm/rounds/13673/components", 'heffan', validRequest, 400,
237-
"submitOrder should not be null or undefined", done);
242+
"submitOrder should be provided", done);
238243
});
239244

240245
it("componentId should be positive.", function (done) {
@@ -315,14 +320,18 @@ describe('SRM Round Components And Terms APIs', function () {
315320
assertPostError("/v2/data/srm/rounds/13673/terms", null, validRequest, 401, "Authorized information needed.", done);
316321
});
317322

318-
it("Admin access only.", function (done) {
319-
assertPostError("/v2/data/srm/rounds/13673/terms", 'user', validRequest, 403, "Admin access only.", done);
323+
it("Admin or web Arena super user only.", function (done) {
324+
assertPostError("/v2/data/srm/rounds/13673/terms", 'user', validRequest, 403, "Admin or web Arena super user only.", done);
320325
});
321326

322327
it("roundId should be number.", function (done) {
323328
assertPostError("/v2/data/srm/rounds/13673a/terms", 'heffan', validRequest, 400, "roundId should be number.", done);
324329
});
325330

331+
it("roundId should be number (with web Arena super user).", function (done) {
332+
assertPostError("/v2/data/srm/rounds/13673a/terms", 'ksmith', validRequest, 400, "roundId should be number.", done);
333+
});
334+
326335
it("roundId should be Integer.", function (done) {
327336
assertPostError("/v2/data/srm/rounds/13673.01/terms", 'heffan', validRequest, 400, "roundId should be Integer.", done);
328337
});
@@ -476,4 +485,4 @@ describe('SRM Round Components And Terms APIs', function () {
476485
});
477486
});
478487
});
479-
});
488+
});

test/test.srmRoundSegments.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ 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"
3334
};
3435

3536

@@ -117,22 +118,26 @@ describe('SRM Round Questions APIs', function () {
117118
clearDb(done);
118119
});
119120
describe('Set Round Segments API invalid test', function () {
120-
var validRequest = {"registrationStart": "2014-09-07 19:44:44", "registrationLength" : 20,
121-
"codingStart": "2014-09-07 20:14:44", "codingLength": 100, "intermissionLength": 10,
121+
var validRequest = {"registrationStart": "2014-09-07 19:44:44Z", "registrationLength" : 20,
122+
"codingStart": "2014-09-07 20:14:44Z", "codingLength": 100, "intermissionLength": 10,
122123
"challengeLength": 15, "registrationStatus": "F", "codingStatus": "F",
123124
"intermissionStatus": "F", "challengeStatus": "F", "systemTestStatus": "F"};
124125
it("No anonymous access.", function (done) {
125126
assertPostError("/v2/data/srm/rounds/13673/segments", null, validRequest, 401, "Authorized information needed.", done);
126127
});
127128

128-
it("Admin access only.", function (done) {
129-
assertPostError("/v2/data/srm/rounds/13673/segments", 'user', validRequest, 403, "Admin access only.", done);
129+
it("Admin or web Arena super user only.", function (done) {
130+
assertPostError("/v2/data/srm/rounds/13673/segments", 'user', validRequest, 403, "Admin or web Arena super user only.", done);
130131
});
131132

132133
it("roundId should be number.", function (done) {
133134
assertPostError("/v2/data/srm/rounds/aaa/segments", 'heffan', validRequest, 400, "roundId should be number.", done);
134135
});
135136

137+
it("roundId should be number (with web Arena super user).", function (done) {
138+
assertPostError("/v2/data/srm/rounds/aaa/segments", 'ksmith', validRequest, 400, "roundId should be number.", done);
139+
});
140+
136141
it("roundId should be Integer.", function (done) {
137142
assertPostError("/v2/data/srm/rounds/1367.3/segments", 'heffan', validRequest, 400, "roundId should be Integer.", done);
138143
});
@@ -152,7 +157,7 @@ describe('SRM Round Questions APIs', function () {
152157
});
153158

154159
it("registrationLength should be number.", function (done) {
155-
validRequest.registrationStart = "2014-09-07 19:44:44"
160+
validRequest.registrationStart = "2014-09-07 19:44:44Z"
156161
validRequest.registrationLength = "oo";
157162
assertPostError("/v2/data/srm/rounds/13673/segments", 'heffan', validRequest, 400, "registrationLength should be number.", done);
158163
});
@@ -174,7 +179,7 @@ describe('SRM Round Questions APIs', function () {
174179
});
175180

176181
it("codingLength should be number.", function (done) {
177-
validRequest.codingStart = "2014-09-07 20:14:44";
182+
validRequest.codingStart = "2014-09-07 20:14:44Z";
178183
validRequest.codingLength = "oo";
179184
assertPostError("/v2/data/srm/rounds/13673/segments", 'heffan', validRequest, 400, "codingLength should be number.", done);
180185
});
@@ -251,8 +256,8 @@ describe('SRM Round Questions APIs', function () {
251256
describe('Valid test', function () {
252257

253258
it("Valid set segments.", function (done) {
254-
var validRequest = {"registrationStart": "2014-09-07 19:44:44", "registrationLength" : 20,
255-
"codingStart": "2014-09-07 20:14:44", "codingLength": 100, "intermissionLength": 10,
259+
var validRequest = {"registrationStart": "2014-09-07 19:44:44+0800", "registrationLength" : 20,
260+
"codingStart": "2014-09-07 20:14:44+0800", "codingLength": 100, "intermissionLength": 10,
256261
"challengeLength": 15, "registrationStatus": "F", "codingStatus": "F",
257262
"intermissionStatus": "F", "challengeStatus": "F", "systemTestStatus": "F"};
258263
async.waterfall([
@@ -320,4 +325,4 @@ describe('SRM Round Questions APIs', function () {
320325
],done);
321326
});
322327
});
323-
});
328+
});

0 commit comments

Comments
 (0)