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

Commit 70212a6

Browse files
committed
enable web arena super role for get rounds api
1 parent 0959cb7 commit 70212a6

15 files changed

+936
-1062
lines changed

actions/rounds.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
/**
55
* Implement the get rounds api.
66
*
7-
* @version 1.0
8-
* @author TCASSEMBLER
7+
* @version 1.1
8+
* @author TCASSEMBLER, TCSFINALFIXER
9+
*
10+
* Changes in 1.1:
11+
* - Add support for web arena super role.
12+
* - Add creatorId field to output.
913
*/
1014
/*jslint node: true, nomen: true, plusplus: true, stupid: true, unparam: true */
1115
"use strict";
@@ -206,7 +210,8 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
206210
var helper = api.helper, sqlParams,
207211
result = {}, params = connection.params, pageIndex, pageSize, sortColumn,
208212
sortOrder, error, filterCondition, statusCondition = '', allowedSort,
209-
data = [], statuses, allowedStatus, tmp, i, tmpTypeId;
213+
data = [], statuses, allowedStatus, tmp, i, tmpTypeId,
214+
isWebArenaSuper = connection.caller.isWebArenaSuper;
210215

211216
sortOrder = (params.sortOrder || "asc").toLowerCase();
212217
sortColumn = (params.sortColumn || "registrationPhaseStartTime").toLowerCase();
@@ -215,7 +220,18 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
215220

216221
async.waterfall([
217222
function (cb) {
218-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
223+
error = helper.checkAdminOrWebArenaSuper(
224+
connection,
225+
'Authorized information needed.',
226+
'Admin or Web Arena Super access only.'
227+
);
228+
if (error) {
229+
return cb(error);
230+
}
231+
if (isWebArenaSuper) {
232+
params.type = 'Instant%20Match';
233+
}
234+
return cb();
219235
}, function (cb) {
220236
allowedSort = helper.getLowerCaseList(Object.keys(SORT_COLUMNS));
221237
if (_.isDefined(params.pageIndex) && pageIndex !== -1) {
@@ -273,6 +289,9 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
273289
}
274290

275291
filterCondition = ' r.round_id > 0 ';
292+
if (isWebArenaSuper) {
293+
filterCondition = filterCondition + ' AND r.creator_id = ' + connection.caller.userId + ' ';
294+
}
276295
if (_.isDefined(params.name)) {
277296
// set name filter
278297
filterCondition = filterCondition + ' AND LOWER(r.name) LIKE LOWER("%' + decodeURIComponent(params.name) + '%")';
@@ -309,16 +328,20 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
309328
// query database to get result
310329
async.parallel({
311330
count: function (cbx) {
312-
api.dataAccess.executeQuery("get_rounds_count",
331+
return api.dataAccess.executeQuery(
332+
"get_rounds_count",
313333
sqlParams,
314334
dbConnectionMap,
315-
cbx);
335+
cbx
336+
);
316337
},
317338
rounds: function (cbx) {
318-
api.dataAccess.executeQuery("get_rounds",
339+
return api.dataAccess.executeQuery(
340+
"get_rounds",
319341
sqlParams,
320342
dbConnectionMap,
321-
cbx);
343+
cbx
344+
);
322345
}
323346
}, cb);
324347
}, function (results, cb) {
@@ -338,6 +361,7 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
338361

339362
record = {
340363
"id": rounds[i].id,
364+
"creatorId": rounds[i].creator_id,
341365
"name": rounds[i].name,
342366
"shortName": rounds[i].short_name,
343367
"type": rounds[i].round_type_desc,
@@ -361,7 +385,7 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
361385
if (!_.isUndefined(rounds[i]["start_time_" + j])
362386
&& !_.isUndefined(rounds[i]["end_time_" + j])
363387
&& !_.isUndefined(rounds[i]["status_" + j])) {
364-
record["roundSchedule"].push({
388+
record.roundSchedule.push({
365389
"phaseName": rounds[i]["name_" + j],
366390
"startTime": rounds[i]["start_time_" + j] ? moment(rounds[i]["start_time_" + j]).format(OUTPUT_DATE_FORMAT) : undefined,
367391
"endTime": rounds[i]["end_time_" + j] ? moment(rounds[i]["end_time_" + j]).format(OUTPUT_DATE_FORMAT) : undefined,
@@ -397,8 +421,8 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
397421
for (i = 0; i < results.terms.length; i++) {
398422
for (j = 0; j < data.length; j++) {
399423
// only return the first term
400-
if (results.terms[i].round_id === data[j].id && !data[j]["roundTerms"]) {
401-
data[j]["roundTerms"] = results.terms[i].terms_content;
424+
if (results.terms[i].round_id === data[j].id && !data[j].roundTerms) {
425+
data[j].roundTerms = results.terms[i].terms_content;
402426
break;
403427
}
404428
}
@@ -407,7 +431,7 @@ var getRounds = function (api, connection, dbConnectionMap, next) {
407431
for (i = 0; i < results.languages.length; i++) {
408432
for (j = 0; j < data.length; j++) {
409433
if (results.languages[i].round_id === data[j].id) {
410-
data[j]["languages"].push({"id": results.languages[i].language_id, "description": results.languages[i].language_name});
434+
data[j].languages.push({"id": results.languages[i].language_id, "description": results.languages[i].language_name});
411435
}
412436
}
413437
}

apiary.apib

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15829,83 +15829,86 @@ Source Code Image Generation APIs
1582915829
+ Response 200 (application/json)
1583015830

1583115831
{
15832-
"total": 1,
15833-
"pageIndex": 1,
15834-
"pageSize": 2,
15835-
"data": [
15836-
{
15837-
"ID": 12001,
15838-
"Name": "test round 12001",
15839-
"Short Name": "short name 12001",
15840-
"Type": "Single Round Match",
15841-
"Status": "Active",
15842-
"Registration Limit": 1000,
15843-
"Invitational Type": "Not",
15844-
"Region": "Alpha",
15845-
"contestId": 12917,
15846-
"contestName": "Test SRM",
15847-
"contestStatus": "A",
15848-
"hasProblems": true,
15849-
"hasTerms": true,
15850-
"hasSchedule": true,
15851-
"hasQuestions": false,
15852-
"Round Schedule": [
15853-
{
15854-
"Phase Name": "Registration Phase",
15855-
"Start Time": "2013-11-02T05:50:51.000+05:00",
15856-
"End Time": "2013-12-02T05:50:51.000+05:00",
15857-
"Status": "Past"
15858-
},
15859-
{
15860-
"Phase Name": "Coding Phase",
15861-
"Start Time": "2013-12-02T05:50:52.000+05:00",
15862-
"End Time": "2013-12-05T05:50:51.000+05:00",
15863-
"Status": "Past"
15864-
},
15865-
{
15866-
"Phase Name": "Intermission Phase",
15867-
"Start Time": "2013-12-06T05:50:51.000+05:00",
15868-
"End Time": "2013-12-07T05:50:51.000+05:00",
15869-
"Status": "Past"
15870-
},
15871-
{
15872-
"Phase Name": "Challenge Phase",
15873-
"Start Time": "2013-12-08T05:50:51.000+05:00",
15874-
"End Time": "2013-12-09T05:50:51.000+05:00",
15875-
"Status": "Past"
15876-
},
15877-
{
15878-
"Phase Name": "System Test Phase",
15879-
"Start Time": "2013-12-10T05:50:51.000+05:00",
15880-
"End Time": "2013-12-11T05:50:51.000+05:00",
15881-
"Status": "Active"
15882-
},
15883-
{
15884-
"Phase Name": "Moderated Chat Phase",
15885-
"Start Time": "2013-12-12T05:50:51.000+05:00",
15886-
"End Time": "2013-12-13T05:50:51.000+05:00",
15887-
"Status": "Draft"
15888-
},
15889-
{
15890-
"Phase Name": "Room Assignment Phase",
15891-
"Start Time": "2013-12-14T05:50:51.000+05:00",
15892-
"End Time": "2013-12-15T05:50:51.000+05:00",
15893-
"Status": "Draft"
15894-
}
15895-
],
15896-
"languages": [
15897-
{
15898-
"id": 1,
15899-
"description": "Java"
15900-
},
15901-
{
15902-
"id": 2,
15903-
"description": "XML"
15904-
}
15905-
]
15906-
}
15907-
]
15908-
}
15832+
"data": [
15833+
{
15834+
"autoEnd": 0,
15835+
"contestId": 12001, "creatorId": 132456,
15836+
"contestName": "test contest 12001",
15837+
"contestStatus": "I",
15838+
"hasProblems": false,
15839+
"hasQuestions": false,
15840+
"hasSchedule": true,
15841+
"hasTerms": true,
15842+
"id": 12001,
15843+
"invitationalType": "Not",
15844+
"languages": [
15845+
{
15846+
"description": "Java",
15847+
"id": 1
15848+
},
15849+
{
15850+
"description": "XML",
15851+
"id": 2
15852+
}
15853+
],
15854+
"name": "test round 12001",
15855+
"region": "Alpha",
15856+
"registrationLimit": 1000,
15857+
"roundSchedule": [
15858+
{
15859+
"endTime": "2013-12-02T00:50:51+00:00",
15860+
"phaseName": "Registration Phase",
15861+
"startTime": "2013-11-02T00:50:51+00:00",
15862+
"status": "Past"
15863+
},
15864+
{
15865+
"endTime": "2013-12-05T00:50:51+00:00",
15866+
"phaseName": "Coding Phase",
15867+
"startTime": "2013-12-02T00:50:52+00:00",
15868+
"status": "Past"
15869+
},
15870+
{
15871+
"endTime": "2013-12-07T00:50:51+00:00",
15872+
"phaseName": "Intermission Phase",
15873+
"startTime": "2013-12-06T00:50:51+00:00",
15874+
"status": "Past"
15875+
},
15876+
{
15877+
"endTime": "2013-12-09T00:50:51+00:00",
15878+
"phaseName": "Challenge Phase",
15879+
"startTime": "2013-12-08T00:50:51+00:00",
15880+
"status": "Past"
15881+
},
15882+
{
15883+
"endTime": "2013-12-11T00:50:51+00:00",
15884+
"phaseName": "System Test Phase",
15885+
"startTime": "2013-12-10T00:50:51+00:00",
15886+
"status": "Active"
15887+
},
15888+
{
15889+
"endTime": "2013-12-13T00:50:51+00:00",
15890+
"phaseName": "Moderated Chat Phase",
15891+
"startTime": "2013-12-12T00:50:51+00:00",
15892+
"status": "Draft"
15893+
},
15894+
{
15895+
"endTime": "2013-12-15T00:50:51+00:00",
15896+
"phaseName": "Room Assignment Phase",
15897+
"startTime": "2013-12-14T00:50:51+00:00",
15898+
"status": "Draft"
15899+
}
15900+
],
15901+
"roundTerms": "term1",
15902+
"shortName": "short name 12001",
15903+
"status": "Active",
15904+
"type": "Single Round Match"
15905+
}
15906+
],
15907+
"pageIndex": 1,
15908+
"pageSize": 2,
15909+
"total": 1
15910+
}
15911+
1590915912

1591015913
+ Response 400 (application/json)
1591115914

@@ -16135,7 +16138,7 @@ Source Code Image Generation APIs
1613516138
{
1613616139
"name":"Forbidden",
1613716140
"value":"403",
16138-
"description":"Admin access only."
16141+
"description":"Admin or Web Arena Super access only."
1613916142
}
1614016143

1614116144
+ Response 500 (application/json)

initializers/helper.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* This module contains helper functions.
88
* @author Sky_, Ghost_141, muzehyun, kurtrips, isv, LazyChild, hesibo, panoptimum, flytoj2ee, TCSASSEMBLER
9-
* @version 1.41
9+
* @version 1.42
1010
* changes in 1.1:
1111
* - add mapProperties
1212
* changes in 1.2:
@@ -110,6 +110,8 @@
110110
* - Update getLowerCaseList method to use map method.
111111
* Changes in 1.41:
112112
* - Update apiName2dbNameMap to add entries for srm schedule API.
113+
* Changes in 1.42:
114+
* - Add checkAdminOrWebArenaSuper to check if user has web arena super role.
113115
*/
114116
"use strict";
115117

@@ -1412,6 +1414,20 @@ helper.checkAdmin = function (connection, unauthorizedErrMsg, forbiddenErrMsg) {
14121414
return new ForbiddenError();
14131415
};
14141416

1417+
/**
1418+
* Check whether given user has web arena super role or not
1419+
* @param connection - the api connection object
1420+
* @param {String} unauthorizedErrMsg - the error message for unauthorized error.
1421+
* @param {String} forbiddenErrMsg - the error message for forbidden error.
1422+
* @return {Error} if user is not admin or does not have web arena super role.
1423+
*/
1424+
helper.checkAdminOrWebArenaSuper = function (connection, unauthorizedErrMsg, forbiddenErrMsg) {
1425+
if (connection.caller.isWebArenaSuper) {
1426+
return null;
1427+
}
1428+
return helper.checkAdmin(connection, unauthorizedErrMsg, forbiddenErrMsg);
1429+
};
1430+
14151431
/**
14161432
* Check if the caller has at least member access level.
14171433
* @param {Object} connection - the connection object.

queries/get_rounds

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ SELECT
22
SKIP @firstRowIndex@
33
FIRST @pageSize@
44
r.round_id as id,
5+
r.creator_id as creator_id,
56
r.name as name,
67
r.short_name as short_name,
78
r.auto_end as auto_end,
8-
rt.round_type_desc,
9+
rt.round_type_desc,
910
c.contest_id as contest_id,
1011
c.name as contest_name,
1112
c.status as contest_status,
@@ -17,7 +18,7 @@ SELECT
1718
'Draft'
1819
ELSE NULL
1920
END AS round_status,
20-
r.registration_limit,
21+
r.registration_limit,
2122
CASE WHEN (r.invitational = 0) THEN
2223
'Not'
2324
WHEN (r.invitational = 1) THEN
@@ -120,7 +121,7 @@ SELECT
120121
'true'
121122
ELSE 'false'
122123
END AS has_questions
123-
124+
124125
FROM (round r
125126
LEFT OUTER JOIN round_type_lu rt
126127
ON r.round_type_id=rt.round_type_id

test/sqls/rounds/informixoltp__insert_test_data

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VA
5555
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12005, 7, '2011-12-14 01:50:51', '2011-12-15 01:50:51', 'F');
5656

5757

58-
INSERT INTO round(round_id, contest_id, name, status, registration_limit, invitational, round_type_id, short_name, region_id) VALUES(12006, 12001, 'test round 12006', 'A', 1000, 0, 19, 'short name 12006', 1);
58+
INSERT INTO round(round_id, contest_id, name, status, registration_limit, invitational, round_type_id, short_name, region_id) VALUES(12006, 12001, 'test round 12006', 'A', 1000, 0, 24, 'short name 12006', 1);
5959

6060
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 1, '2015-11-02 01:50:51', '2015-12-02 01:50:51', 'P');
6161
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 2, '2015-12-02 01:50:52', '2015-12-05 01:50:51', 'P');
6262
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 3, '2015-12-06 01:50:51', '2015-12-07 01:50:51', 'P');
6363
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 4, '2015-12-08 01:50:51', '2015-12-09 01:50:51', 'P');
6464
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 5, '2015-12-10 01:50:51', '2015-12-11 01:50:51', 'A');
65-
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 7, '2015-12-14 01:50:51', '2015-12-15 01:50:51', 'F');
65+
INSERT INTO round_segment(round_id, segment_id, start_time, end_time, status) VALUES(12006, 7, '2015-12-14 01:50:51', '2015-12-15 01:50:51', 'F');
66+
67+
update round set creator_id = 132456 where round_id >= 12001 and round_id < 13000;
68+
update round set creator_id = 124861 where round_id = 12006;

0 commit comments

Comments
 (0)