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');
2123var moment = require ( 'moment' ) ;
2224var IllegalArgumentError = require ( '../errors/IllegalArgumentError' ) ;
2325var NotFoundError = require ( '../errors/NotFoundError' ) ;
26+ var UnauthorizedError = require ( '../errors/UnauthorizedError' ) ;
2427var 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 */
217226var 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 ) ) ;
0 commit comments