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

Commit 899023c

Browse files
committed
Merge branch 'dev' of github.com:cloudspokes/tc-api into dev
2 parents c05286a + f9da51c commit 899023c

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

actions/srmRoundQuestions.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var ForbiddenError = require('../errors/ForbiddenError');
2424

2525
var DATE_FORMAT = "YYYY-MM-DD HH:mm";
2626

27-
2827
/**
2928
* Get Round Question Answers.
3029
*
@@ -35,12 +34,21 @@ var DATE_FORMAT = "YYYY-MM-DD HH:mm";
3534
*/
3635
var getRoundQuestionAnswers = function (api, connection, dbConnectionMap, next) {
3736
var helper = api.helper,
37+
caller = connection.caller,
3838
result = [],
3939
questionId = Number(connection.params.questionId);
4040

4141
async.waterfall([
4242
function (cb) {
43-
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+
}
4452
}, function (cb) {
4553
cb(helper.checkIdParameter(questionId, "questionId"));
4654
}, function (cb) {
@@ -386,6 +394,7 @@ function checkAnswerValues(api, text, sortOrder, correct, callback) {
386394
*/
387395
var addRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
388396
var helper = api.helper,
397+
caller = connection.caller,
389398
sqlParams = {},
390399
questionId = Number(connection.params.questionId),
391400
text = connection.params.text,
@@ -394,7 +403,15 @@ var addRoundQuestionAnswer = function (api, connection, dbConnectionMap, next) {
394403

395404
async.waterfall([
396405
function (cb) {
397-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
406+
if (!helper.isAdmin(caller) && !caller.isWebArenaSuper) {
407+
if (!helper.isMember(caller)) {
408+
cb(new UnauthorizedError("Authorized information needed."));
409+
} else {
410+
cb(new ForbiddenError("Admin or web Arena super user only."));
411+
}
412+
} else {
413+
cb();
414+
}
398415
}, function (cb) {
399416
checkQuestionId(api, dbConnectionMap, questionId, cb);
400417
}, function (error, cb) {

test/test.srmRoundQuestions.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,19 @@ describe('SRM Round Questions APIs', function () {
251251
assertError("/v2/data/srm/rounds/1000000/answers", null, 401, "Authorized information needed.", done);
252252
});
253253

254-
it("Admin access only.", function (done) {
255-
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);
256256
});
257257

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

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+
262267
it("questionId should be Integer.", function (done) {
263268
assertError("/v2/data/srm/rounds/100000.01/answers", 'heffan', 400, "questionId should be Integer.", done);
264269
});
@@ -390,14 +395,19 @@ describe('SRM Round Questions APIs', function () {
390395
assertPostError("/v2/data/srm/questions/306/answers", null, validRequest, 401, "Authorized information needed.", done);
391396
});
392397

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

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

407+
it("questionId should be number.", function (done) {
408+
assertPostError("/v2/data/srm/questions/aaa/answers", 'ksmith', validRequest, 400, "questionId should be number.", done);
409+
});
410+
401411
it("questionId should be Integer.", function (done) {
402412
assertPostError("/v2/data/srm/questions/30.6/answers", 'heffan', validRequest, 400, "questionId should be Integer.", done);
403413
});

0 commit comments

Comments
 (0)