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

Commit c05286a

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

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

actions/srmRoundQuestions.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ 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

@@ -277,6 +279,28 @@ var setRoundSurvey = function (api, connection, dbConnectionMap, next) {
277279
});
278280
};
279281

282+
/**
283+
* Check if user authorized and is admin or web Arena super user
284+
*
285+
* @param api the api instance.
286+
* @param the connection instance
287+
* @param callback the callback method
288+
*/
289+
function checkAuthorization(api, connection, callback) {
290+
var helper = api.helper,
291+
caller = connection.caller;
292+
293+
if (!helper.isAdmin(caller) && !caller.isWebArenaSuper) {
294+
if (!helper.isMember(caller)) {
295+
callback(new UnauthorizedError("Authorized information needed."));
296+
} else {
297+
callback(new ForbiddenError("Admin or web Arena super user only."));
298+
}
299+
} else {
300+
callback();
301+
}
302+
}
303+
280304
/**
281305
* Check question id.
282306
*
@@ -515,7 +539,7 @@ var addRoundQuestion = function (api, connection, dbConnectionMap, next) {
515539

516540
async.waterfall([
517541
function (cb) {
518-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
542+
checkAuthorization(api, connection, cb);
519543
}, function (cb) {
520544
checkRoundId(api, dbConnectionMap, roundId, cb);
521545
}, function (error, cb) {

test/test.srmRoundQuestions.js

Lines changed: 7 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

@@ -454,12 +455,14 @@ describe('SRM Round Questions APIs', function () {
454455
assertPostError("/v2/data/srm/rounds/13673/questions", null, validRequest, 401, "Authorized information needed.", done);
455456
});
456457

457-
it("Admin access only.", function (done) {
458-
assertPostError("/v2/data/srm/rounds/13673/questions", 'user', validRequest, 403, "Admin access only.", done);
458+
it("Admin or web Arena super user only.", function (done) {
459+
assertPostError("/v2/data/srm/rounds/13673/questions", 'user', validRequest, 403, "Admin or web Arena super user only.", done);
459460
});
460461

462+
// Only admin or web arena super user can get into this step
461463
it("roundId should be number.", function (done) {
462464
assertPostError("/v2/data/srm/rounds/aaa/questions", 'heffan', validRequest, 400, "roundId should be number.", done);
465+
assertPostError("/v2/data/srm/rounds/aaa/questions", 'ksmith', validRequest, 400, "roundId should be number.", done);
463466
});
464467

465468
it("roundId should be Integer.", function (done) {
@@ -935,4 +938,4 @@ describe('SRM Round Questions APIs', function () {
935938
], done);
936939
});
937940
});
938-
});
941+
});

0 commit comments

Comments
 (0)