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

Commit e489e3a

Browse files
committed
enable add round question answer api for web arena super role
1 parent 915d0e2 commit e489e3a

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
*
@@ -362,6 +363,7 @@ function checkAnswerValues(api, text, sortOrder, correct, callback) {
362363
*/
363364
var addRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
364365
var helper = api.helper,
366+
caller = connection.caller,
365367
sqlParams = {},
366368
questionId = Number(connection.params.questionId),
367369
text = connection.params.text,
@@ -370,7 +372,15 @@ var addRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
370372

371373
async.waterfall([
372374
function (cb) {
373-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
375+
if (!helper.isAdmin(caller) && !caller.isWebArenaSuper) {
376+
if (!helper.isMember(caller)) {
377+
cb(new UnauthorizedError("Authorized information needed."));
378+
} else {
379+
cb(new ForbiddenError("Admin or web Arena super user only."));
380+
}
381+
} else {
382+
cb();
383+
}
374384
}, function (cb) {
375385
checkQuestionId(api, dbConnectionMap, questionId, cb);
376386
}, function (error, 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

@@ -389,14 +390,19 @@ describe('SRM Round Questions APIs', function () {
389390
assertPostError("/v2/data/srm/questions/306/answers", null, validRequest, 401, "Authorized information needed.", done);
390391
});
391392

392-
it("Admin access only.", function (done) {
393-
assertPostError("/v2/data/srm/questions/306/answers", 'user', validRequest, 403, "Admin access only.", done);
393+
it("Admin or web Arena super user only.", function (done) {
394+
assertPostError("/v2/data/srm/questions/306/answers", 'user', validRequest, 403, "Admin or web Arena super user only.", done);
394395
});
395396

397+
// Only admin or web arena super user can get into this step
396398
it("questionId should be number.", function (done) {
397399
assertPostError("/v2/data/srm/questions/aaa/answers", 'heffan', validRequest, 400, "questionId should be number.", done);
398400
});
399401

402+
it("questionId should be number.", function (done) {
403+
assertPostError("/v2/data/srm/questions/aaa/answers", 'ksmith', validRequest, 400, "questionId should be number.", done);
404+
});
405+
400406
it("questionId should be Integer.", function (done) {
401407
assertPostError("/v2/data/srm/questions/30.6/answers", 'heffan', validRequest, 400, "questionId should be Integer.", done);
402408
});
@@ -935,4 +941,4 @@ describe('SRM Round Questions APIs', function () {
935941
], done);
936942
});
937943
});
938-
});
944+
});

0 commit comments

Comments
 (0)