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

Commit 69c29f2

Browse files
committed
enable list round problems and components apis for web arena super role
1 parent 79aec49 commit 69c29f2

9 files changed

+67
-31
lines changed

actions/srmProblems.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ var async = require('async');
2222
var _ = require('underscore');
2323
var moment = require('moment');
2424
var IllegalArgumentError = require('../errors/IllegalArgumentError');
25-
var NotFoundError = require('../errors/NotFoundError');
26-
var UnauthorizedError = require('../errors/UnauthorizedError');
27-
var ForbiddenError = require('../errors/ForbiddenError');
25+
26+
/**
27+
* Error messages
28+
*/
29+
var NON_ADMIN_MESSAGE = "Admin access only.",
30+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or web Arena super user only.",
31+
UNAUTHORIZED_MESSAGE = "Authorized information needed.";
2832

2933
/**
3034
* Parsed the problem from database query result.
@@ -54,15 +58,15 @@ var listRoundProblems = function (api, connection, dbConnectionMap, next) {
5458

5559
async.waterfall([
5660
function (cb) {
57-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
61+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
5862
}, function (cb) {
5963
cb(helper.checkIdParameter(roundId, "roundId"));
6064
}, function (cb) {
6165
sqlParams.roundId = roundId;
6266
api.dataAccess.executeQuery("get_srm_assigned_problems", sqlParams, dbConnectionMap, cb);
6367
}, function (results, cb) {
6468
if (results.length === 0) {
65-
cb(new NotFoundError("Cannot find records by given roundId."));
69+
cb();
6670
return;
6771
}
6872
_.each(results, function (item) {
@@ -105,7 +109,7 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
105109

106110
async.waterfall([
107111
function (cb) {
108-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
112+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
109113
}, function (cb) {
110114
// check parameters
111115
var error = helper.checkIdParameter(roundId, "roundId");
@@ -135,7 +139,7 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
135139
}
136140
}, function (results, cb) {
137141
if (results.length === 0) {
138-
cb(new NotFoundError("Cannot find records by given roundId."));
142+
cb();
139143
return;
140144
}
141145
_.each(results, function (item) {
@@ -231,16 +235,7 @@ var listSRMProblems = function (api, connection, dbConnectionMap, next) {
231235

232236
async.waterfall([
233237
function (cb) {
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.'));
238+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
244239
}, function (cb) {
245240
if (caller.isWebArenaSuper) {
246241
async.waterfall([

test/test.srmProblems.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,18 @@ describe('SRM Round Problem APIs', function () {
172172
assertError("/v2/data/srm/rounds/13672/problems", null, 401, "Authorized information needed.", done);
173173
});
174174

175-
it("Admin access only.", function (done) {
176-
assertError("/v2/data/srm/rounds/13672/problems", 'user', 403, "Admin access only.", done);
175+
it("Admin or web Arena super user only.", function (done) {
176+
assertError("/v2/data/srm/rounds/13672/problems", 'user', 403, "Admin or web Arena super user only.", done);
177177
});
178178

179179
it("roundId should be number.", function (done) {
180180
assertError("/v2/data/srm/rounds/aaa/problems", 'heffan', 400, "roundId should be number.", done);
181181
});
182182

183+
it("roundId should be number (with web Arena super user).", function (done) {
184+
assertError("/v2/data/srm/rounds/aaa/problems", 'ksmith', 400, "roundId should be number.", done);
185+
});
186+
183187
it("roundId should be Integer.", function (done) {
184188
assertError("/v2/data/srm/rounds/1.01/problems", 'heffan', 400, "roundId should be Integer.", done);
185189
});
@@ -193,8 +197,9 @@ describe('SRM Round Problem APIs', function () {
193197
'heffan', 400, "roundId should be less or equal to 2147483647.", done);
194198
});
195199

196-
it("Cannot find records by given roundId.", function (done) {
197-
assertError("/v2/data/srm/rounds/100/problems", 'heffan', 404, "Cannot find records by given roundId.", done);
200+
it("Valid empty SRM round problems.", function (done) {
201+
validateResult("/v2/data/srm/rounds/100/problems", 'heffan',
202+
"./test_files/srm_problems/list_round_problems_empty.json", done);
198203
});
199204

200205
it("Valid request.", function (done) {
@@ -210,14 +215,18 @@ describe('SRM Round Problem APIs', function () {
210215
assertError("/v2/data/srm/rounds/13672/components", null, 401, "Authorized information needed.", done);
211216
});
212217

213-
it("Admin access only.", function (done) {
214-
assertError("/v2/data/srm/rounds/13672/components", 'user', 403, "Admin access only.", done);
218+
it("Admin or web Arena super user only.", function (done) {
219+
assertError("/v2/data/srm/rounds/13672/components", 'user', 403, "Admin or web Arena super user only.", done);
215220
});
216221

217222
it("roundId should be number.", function (done) {
218223
assertError("/v2/data/srm/rounds/aaa/components", 'heffan', 400, "roundId should be number.", done);
219224
});
220225

226+
it("roundId should be number (with web Arena super user).", function (done) {
227+
assertError("/v2/data/srm/rounds/aaa/components", 'ksmith', 400, "roundId should be number.", done);
228+
});
229+
221230
it("roundId should be Integer.", function (done) {
222231
assertError("/v2/data/srm/rounds/1.01/components", 'heffan', 400, "roundId should be Integer.", done);
223232
});
@@ -287,5 +296,11 @@ describe('SRM Round Problem APIs', function () {
287296
validateResult("/v2/data/srm/rounds/13672/components", 'heffan',
288297
"./test_files/srm_problems/list_round_problem_components_global.json", done);
289298
});
299+
300+
it("Valid empty SRM round components.", function (done) {
301+
validateResult("/v2/data/srm/rounds/1000000/components", 'heffan',
302+
"./test_files/srm_problems/list_round_problem_components_empty.json", done);
303+
});
304+
290305
});
291306
});

test/test_files/srm_problems/list_round_problem_components.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"openOrder": 0,
1313
"pointValue": 250,
14+
"roundId": 13672,
1415
"componentData": {
1516
"id": 2021,
1617
"problemId": 10195,
@@ -29,4 +30,4 @@
2930
"submitOrder": 0
3031
}
3132
]
32-
}
33+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"components": []
3+
}

test/test_files/srm_problems/list_round_problem_components_global.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"openOrder": 0,
1313
"pointValue": 500,
14+
"roundId": 13672,
1415
"componentData": {
1516
"id": 2020,
1617
"problemId": 10194,
@@ -38,6 +39,7 @@
3839
},
3940
"openOrder": 0,
4041
"pointValue": 250,
42+
"roundId": 13672,
4143
"componentData": {
4244
"id": 2021,
4345
"problemId": 10195,
@@ -56,4 +58,4 @@
5658
"submitOrder": 0
5759
}
5860
]
59-
}
61+
}

test/test_files/srm_problems/list_round_problems.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
"problemData": {
99
"id": 10194,
1010
"name": "BlackAndWhiteGame",
11+
"proposedDivisionId": 1,
12+
"roundId": 13672,
1113
"type": {
1214
"id": 3,
1315
"description": "Long"
1416
},
1517
"status": {
16-
"id": 75,
17-
"description": "Final Testing"
18+
"id": 90,
19+
"description": "Used"
1820
}
1921
}
2022
},
@@ -26,6 +28,8 @@
2628
"problemData": {
2729
"id": 10195,
2830
"name": "TestProblem",
31+
"proposedDivisionId": 2,
32+
"roundId": 13672,
2933
"type": {
3034
"id": 1,
3135
"description": "Single"
@@ -37,4 +41,4 @@
3741
}
3842
}
3943
]
40-
}
44+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"assignedProblems": []
3+
}

test/test_files/srm_problems/list_srm_problems.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"description": "Long"
1010
},
1111
"status": {
12-
"id": 75,
13-
"description": "Final Testing"
12+
"id": 90,
13+
"description": "Used"
1414
}
1515
},
1616
{
@@ -131,4 +131,4 @@
131131
}
132132
}
133133
]
134-
}
134+
}

test/test_files/srm_problems/list_used_srm_problems.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
{
22
"problems": [
3+
{
4+
"id": 10194,
5+
"name": "BlackAndWhiteGame",
6+
"proposedDivisionId": -1,
7+
"type": {
8+
"id": 3,
9+
"description": "Long"
10+
},
11+
"status": {
12+
"id": 90,
13+
"description": "Used"
14+
}
15+
},
316
{
417
"id": 2001,
518
"name": "Used Problem",

0 commit comments

Comments
 (0)