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

Commit ad0256d

Browse files
committed
enable get round question answers api for web arena super role
1 parent 915d0e2 commit ad0256d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

actions/srmRoundQuestions.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ var _ = require('underscore');
1919
var moment = require('moment');
2020
var IllegalArgumentError = require('../errors/IllegalArgumentError');
2121
var NotFoundError = require('../errors/NotFoundError');
22+
var UnauthorizedError = require('../errors/UnauthorizedError');
23+
var ForbiddenError = require('../errors/ForbiddenError');
2224

2325
var DATE_FORMAT = "YYYY-MM-DD HH:mm";
2426

25-
2627
/**
2728
* Get Round Question Answers.
2829
*
@@ -33,12 +34,21 @@ var DATE_FORMAT = "YYYY-MM-DD HH:mm";
3334
*/
3435
var getRoundQuestionAnswers = function (api, connection, dbConnectionMap, next) {
3536
var helper = api.helper,
37+
caller = connection.caller,
3638
result = [],
3739
questionId = Number(connection.params.questionId);
3840

3941
async.waterfall([
4042
function (cb) {
41-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
43+
if (!helper.isAdmin(caller) && !caller.isWebArenaSuper) {
44+
if (!helper.isMember(caller)) {
45+
cb(new UnauthorizedError("Authorized information needed."));
46+
} else {
47+
cb(new ForbiddenError("Admin or web Arena super user only."));
48+
}
49+
} else {
50+
cb();
51+
}
4252
}, function (cb) {
4353
cb(helper.checkIdParameter(questionId, "questionId"));
4454
}, function (cb) {

test/test.srmRoundQuestions.js

Lines changed: 10 additions & 4 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

@@ -250,14 +251,19 @@ describe('SRM Round Questions APIs', function () {
250251
assertError("/v2/data/srm/rounds/1000000/answers", null, 401, "Authorized information needed.", done);
251252
});
252253

253-
it("Admin access only.", function (done) {
254-
assertError("/v2/data/srm/rounds/1000000/answers", 'user', 403, "Admin access only.", done);
254+
it("Admin or web arena only.", function (done) {
255+
assertError("/v2/data/srm/rounds/1000000/answers", 'user', 403, "Admin or web Arena super user only.", done);
255256
});
256257

258+
// Only admin or web arena super user can get into this step
257259
it("questionId should be number.", function (done) {
258260
assertError("/v2/data/srm/rounds/aaa/answers", 'heffan', 400, "questionId should be number.", done);
259261
});
260262

263+
it("questionId should be number.", function (done) {
264+
assertError("/v2/data/srm/rounds/aaa/answers", 'ksmith', 400, "questionId should be number.", done);
265+
});
266+
261267
it("questionId should be Integer.", function (done) {
262268
assertError("/v2/data/srm/rounds/100000.01/answers", 'heffan', 400, "questionId should be Integer.", done);
263269
});
@@ -935,4 +941,4 @@ describe('SRM Round Questions APIs', function () {
935941
], done);
936942
});
937943
});
938-
});
944+
});

0 commit comments

Comments
 (0)