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

Commit c09aefd

Browse files
committed
enable list problem api for web arena super role
1 parent 7b6c86e commit c09aefd

File tree

6 files changed

+158
-8
lines changed

6 files changed

+158
-8
lines changed

actions/srmProblems.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
* - listRoundProblems will include round id
1212
* - listRoundProblemComponents will include round id
1313
*
14-
* @version 1.1
14+
* Changes in 1.2 (TC API - List SRM Problems API Update)
15+
* - Update listSRMProblems api to allow web arena super user access it.
16+
* @version 1.2
1517
* @author TCSASSEMBLER
1618
*/
1719
/*jslint node: true, nomen: true, plusplus: true */
@@ -21,6 +23,7 @@ var _ = require('underscore');
2123
var moment = require('moment');
2224
var IllegalArgumentError = require('../errors/IllegalArgumentError');
2325
var NotFoundError = require('../errors/NotFoundError');
26+
var UnauthorizedError = require('../errors/UnauthorizedError');
2427
var ForbiddenError = require('../errors/ForbiddenError');
2528

2629
/**
@@ -206,6 +209,12 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
206209
});
207210
};
208211

212+
/**
213+
* The filter for list SRM problem api when caller is the web arena super user.
214+
* @type {string}
215+
*/
216+
var SRM_PROBLEM_WEB_ARENA_SUPER_FILTER = " AND p.status_id = 90";
217+
209218
/**
210219
* Get SRM problems.
211220
*
@@ -216,14 +225,36 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
216225
*/
217226
var listSRMProblems = function (api, connection, dbConnectionMap, next) {
218227
var helper = api.helper,
228+
caller = connection.caller,
219229
result = [],
220230
sqlParams = {};
221231

222232
async.waterfall([
223233
function (cb) {
224-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
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.'));
225244
}, function (cb) {
226-
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
245+
if (caller.isWebArenaSuper) {
246+
async.waterfall([
247+
function (cbx) {
248+
helper.readQuery("get_srm_problems", cbx);
249+
},
250+
function (sql, cbx) {
251+
sql = helper.editSql(sql, SRM_PROBLEM_WEB_ARENA_SUPER_FILTER, null);
252+
api.dataAccess.executeSqlQuery(sql, sqlParams, "informixoltp", dbConnectionMap, cbx);
253+
}
254+
], cb);
255+
} else {
256+
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
257+
}
227258
}, function (results, cb) {
228259
_.each(results, function (item) {
229260
result.push(parseProblem(item));

queries/get_srm_problems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ t.problem_type_desc AS problem_type_desc
99
FROM problem p
1010
LEFT OUTER JOIN problem_status_lu s ON p.status_id = s.problem_status_id
1111
LEFT OUTER JOIN problem_type_lu t ON p.problem_type_id = t.problem_type_id
12+
WHERE 1=1
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
DELETE FROM round_component WHERE round_id = 13672 and division_id = 1;
1+
DELETE FROM round_component WHERE round_id = 13672 and division_id = 1;
2+
DELETE FROM problem WHERE problem_id = 2001;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

2-
INSERT INTO 'informix'.round_component(round_id, component_id, submit_order, division_id, difficulty_id, points, open_order) VALUES(13672, 2020, 0, 1, 1, 500, 0);
2+
INSERT INTO 'informix'.round_component(round_id, component_id, submit_order, division_id, difficulty_id, points, open_order) VALUES(13672, 2020, 0, 1, 1, 500, 0);
3+
INSERT INTO 'informix'.problem(problem_id, name, status_id, proposed_division_id, problem_type_id) VALUES(2001, "Used Problem", 90, 1, 1);

test/test.srmProblems.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ 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",
34+
twight : "ad|124766"
3335
};
3436

3537

@@ -146,14 +148,22 @@ describe('SRM Round Problem APIs', function () {
146148
});
147149

148150
it("Admin access only.", function (done) {
149-
assertError("/v2/data/srm/problems", 'user', 403, "Admin access only.", done);
151+
assertError("/v2/data/srm/problems", 'user', 403, "Admin or web Arena super user only.", done);
152+
});
153+
154+
it("Admin or web arena only.", function (done) {
155+
assertError("/v2/data/srm/problems", 'twight', 403, "Admin or web Arena super user only.", done);
150156
});
151157

152158
it("Valid request.", function (done) {
153159
validateResult("/v2/data/srm/problems", 'heffan',
154160
"./test_files/srm_problems/list_srm_problems.json", done);
155161
});
156162

163+
it("Valid request with web arena super user.", function (done) {
164+
validateResult("/v2/data/srm/problems", "ksmith", "./test_files/srm_problems/list_used_srm_problems.json", done);
165+
});
166+
157167
});
158168

159169
describe('List SRM Round Problems API', function () {
@@ -278,4 +288,4 @@ describe('SRM Round Problem APIs', function () {
278288
"./test_files/srm_problems/list_round_problem_components_global.json", done);
279289
});
280290
});
281-
});
291+
});

test/test_files/srm_problems/list_srm_problems.json

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"id": 10194,
55
"name": "BlackAndWhiteGame",
6+
"proposedDivisionId": -1,
67
"type": {
78
"id": 3,
89
"description": "Long"
@@ -15,6 +16,7 @@
1516
{
1617
"id": 10195,
1718
"name": "TestProblem",
19+
"proposedDivisionId": 1,
1820
"type": {
1921
"id": 1,
2022
"description": "Single"
@@ -23,6 +25,110 @@
2325
"id": 75,
2426
"description": "Final Testing"
2527
}
28+
},
29+
{
30+
"id": 10205,
31+
"name": "SnowCleaning",
32+
"proposedDivisionId": -1,
33+
"type": {
34+
"id": 3,
35+
"description": "Long"
36+
},
37+
"status": {
38+
"id": 75,
39+
"description": "Final Testing"
40+
}
41+
},
42+
{
43+
"id": 10207,
44+
"name": "ColorfulBuilding",
45+
"proposedDivisionId": 1,
46+
"type": {
47+
"id": 1,
48+
"description": "Single"
49+
},
50+
"status": {
51+
"id": 75,
52+
"description": "Final Testing"
53+
}
54+
},
55+
{
56+
"id": 10208,
57+
"name": "RandomPaintingOnABoard",
58+
"proposedDivisionId": 1,
59+
"type": {
60+
"id": 1,
61+
"description": "Single"
62+
},
63+
"status": {
64+
"id": 75,
65+
"description": "Final Testing"
66+
}
67+
},
68+
{
69+
"id": 10209,
70+
"name": "GooseInZooDivOne",
71+
"proposedDivisionId": 1,
72+
"type": {
73+
"id": 1,
74+
"description": "Single"
75+
},
76+
"status": {
77+
"id": 75,
78+
"description": "Final Testing"
79+
}
80+
},
81+
{
82+
"id": 10211,
83+
"name": "SemiPerfectPower",
84+
"proposedDivisionId": 1,
85+
"type": {
86+
"id": 1,
87+
"description": "Single"
88+
},
89+
"status": {
90+
"id": 75,
91+
"description": "Final Testing"
92+
}
93+
},
94+
{
95+
"id": 10212,
96+
"name": "ShoutterDiv1",
97+
"proposedDivisionId": 1,
98+
"type": {
99+
"id": 1,
100+
"description": "Single"
101+
},
102+
"status": {
103+
"id": 75,
104+
"description": "Final Testing"
105+
}
106+
},
107+
{
108+
"id": 10213,
109+
"name": "UndoHistory",
110+
"proposedDivisionId": 1,
111+
"type": {
112+
"id": 1,
113+
"description": "Single"
114+
},
115+
"status": {
116+
"id": 75,
117+
"description": "Final Testing"
118+
}
119+
},
120+
{
121+
"id": 2001,
122+
"name": "Used Problem",
123+
"proposedDivisionId": 1,
124+
"type": {
125+
"id": 1,
126+
"description": "Single"
127+
},
128+
"status": {
129+
"id": 90,
130+
"description": "Used"
131+
}
26132
}
27133
]
28134
}

0 commit comments

Comments
 (0)