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

Commit 7cc3607

Browse files
author
ykohata
committed
Merge branch 'technology-2015-01-29'
2 parents bab8807 + f5b5628 commit 7cc3607

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1641
-1245
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
}

actions/srmChallenges.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* Copyright (C) 2013-2014 TopCoder Inc., All Rights Reserved.
33
*
4-
* @version 1.10
5-
* @author Sky_, freegod, panoptimum, Ghost_141, onsky
4+
* @version 1.11
5+
* @author Sky_, freegod, panoptimum, Ghost_141, onsky, TCSFIRST2FINISHER
66
* changes in 1.1:
77
* - implement srm API
88
* changes in 1.2:
@@ -30,6 +30,8 @@
3030
* - Implement Rounds For Problem API
3131
* Changes in 1.10:
3232
* - Update the get srm schedule API.
33+
* Changes in 1.11 (TC API - Create SRM Contest API and Modify SRM Contest API Update):
34+
* - Enable web arena super role access for createSRMContest, updateSRMContest
3335
*/
3436
/*jslint node: true, nomen: true */
3537
"use strict";
@@ -229,6 +231,7 @@ var LEADER_COUNT = 5;
229231
* Forbidden error message for non-admin users
230232
*/
231233
var NON_ADMIN_MESSAGE = "Admin access only.",
234+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or Web Arena Super access only.",
232235
UNAUTHORIZED_MESSAGE = "Authorized access only.";
233236
/**
234237
* The API for searching SRM challenges
@@ -264,7 +267,7 @@ exports.searchSRMChallenges = {
264267
pageIndex = Number(params.pageIndex || 1);
265268
pageSize = Number(params.pageSize || DEFAULT_PAGE_SIZE);
266269
listType = (params.listType || 'ACTIVE').toUpperCase();
267-
challengeName = '%' + params.challengeName.toLowerCase() + '%' || '%';
270+
challengeName = _.has(params, 'challengeName') ? '%' + params.challengeName.toLowerCase() + '%' : '%';
268271

269272
if (!_.isDefined(params.sortOrder) && sortColumn === "roundid") {
270273
sortOrder = "desc";
@@ -1434,7 +1437,11 @@ exports.createSRMContest = {
14341437
async.auto(
14351438
{
14361439
admin: function (cb) {
1437-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1440+
cb(helper.checkAdminOrWebArenaSuper(
1441+
connection,
1442+
UNAUTHORIZED_MESSAGE,
1443+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE
1444+
));
14381445
},
14391446
common: [ // do common validations
14401447
'admin',
@@ -1536,7 +1543,11 @@ exports.updateSRMContest = {
15361543
async.auto(
15371544
{
15381545
admin: function (cb) {
1539-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1546+
cb(helper.checkAdminOrWebArenaSuper(
1547+
connection,
1548+
UNAUTHORIZED_MESSAGE,
1549+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE
1550+
));
15401551
},
15411552
validate: [
15421553
'admin',
@@ -1875,7 +1886,7 @@ exports.setRoundLanguages = {
18751886
async.auto(
18761887
{
18771888
admin: function (cb) {
1878-
cb(helper.checkAdmin(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_MESSAGE));
1889+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
18791890
},
18801891
roundId: [
18811892
'admin',

actions/srmProblems.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
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 */
@@ -20,8 +22,13 @@ var async = require('async');
2022
var _ = require('underscore');
2123
var moment = require('moment');
2224
var IllegalArgumentError = require('../errors/IllegalArgumentError');
23-
var NotFoundError = require('../errors/NotFoundError');
24-
var ForbiddenError = require('../errors/ForbiddenError');
25+
26+
/**
27+
* Error messages
28+
*/
29+
var NON_ADMIN_MESSAGE = "Admin access only.",
30+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or web Arena super user only.",
31+
UNAUTHORIZED_MESSAGE = "Authorized information needed.";
2532

2633
/**
2734
* Parsed the problem from database query result.
@@ -51,15 +58,15 @@ var listRoundProblems = function (api, connection, dbConnectionMap, next) {
5158

5259
async.waterfall([
5360
function (cb) {
54-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
61+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
5562
}, function (cb) {
5663
cb(helper.checkIdParameter(roundId, "roundId"));
5764
}, function (cb) {
5865
sqlParams.roundId = roundId;
5966
api.dataAccess.executeQuery("get_srm_assigned_problems", sqlParams, dbConnectionMap, cb);
6067
}, function (results, cb) {
6168
if (results.length === 0) {
62-
cb(new NotFoundError("Cannot find records by given roundId."));
69+
cb();
6370
return;
6471
}
6572
_.each(results, function (item) {
@@ -102,7 +109,7 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
102109

103110
async.waterfall([
104111
function (cb) {
105-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
112+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
106113
}, function (cb) {
107114
// check parameters
108115
var error = helper.checkIdParameter(roundId, "roundId");
@@ -132,7 +139,7 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
132139
}
133140
}, function (results, cb) {
134141
if (results.length === 0) {
135-
cb(new NotFoundError("Cannot find records by given roundId."));
142+
cb();
136143
return;
137144
}
138145
_.each(results, function (item) {
@@ -206,6 +213,12 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
206213
});
207214
};
208215

216+
/**
217+
* The filter for list SRM problem api when caller is the web arena super user.
218+
* @type {string}
219+
*/
220+
var SRM_PROBLEM_WEB_ARENA_SUPER_FILTER = " AND p.status_id = 90";
221+
209222
/**
210223
* Get SRM problems.
211224
*
@@ -216,14 +229,27 @@ var listRoundProblemComponents = function (api, connection, dbConnectionMap, nex
216229
*/
217230
var listSRMProblems = function (api, connection, dbConnectionMap, next) {
218231
var helper = api.helper,
232+
caller = connection.caller,
219233
result = [],
220234
sqlParams = {};
221235

222236
async.waterfall([
223237
function (cb) {
224-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
238+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
225239
}, function (cb) {
226-
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
240+
if (caller.isWebArenaSuper) {
241+
async.waterfall([
242+
function (cbx) {
243+
helper.readQuery("get_srm_problems", cbx);
244+
},
245+
function (sql, cbx) {
246+
sql = helper.editSql(sql, SRM_PROBLEM_WEB_ARENA_SUPER_FILTER, null);
247+
api.dataAccess.executeSqlQuery(sql, sqlParams, "informixoltp", dbConnectionMap, cbx);
248+
}
249+
], cb);
250+
} else {
251+
api.dataAccess.executeQuery("get_srm_problems", sqlParams, dbConnectionMap, cb);
252+
}
227253
}, function (results, cb) {
228254
_.each(results, function (item) {
229255
result.push(parseProblem(item));

actions/srmRoundComponentsAndTerms.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ var _ = require('underscore');
1414
var moment = require('moment');
1515
var IllegalArgumentError = require('../errors/IllegalArgumentError');
1616

17+
/**
18+
* Error messages
19+
*/
20+
var NON_ADMIN_MESSAGE = "Admin access only.",
21+
NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE = "Admin or web Arena super user only.",
22+
UNAUTHORIZED_MESSAGE = "Authorized information needed.";
23+
1724
/**
1825
* Check whether the given value is defined and id parameter.
1926
* @param value - the given value.
@@ -206,7 +213,7 @@ var setRoundComponents = function (api, connection, dbConnectionMap, next) {
206213

207214
async.waterfall([
208215
function (cb) {
209-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
216+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
210217
}, function (cb) {
211218
checkRoundId(api, dbConnectionMap, roundId, cb);
212219
}, function (error, cb) {
@@ -278,7 +285,7 @@ var setRoundTerms = function (api, connection, dbConnectionMap, next) {
278285

279286
async.waterfall([
280287
function (cb) {
281-
cb(helper.checkAdmin(connection, 'Authorized information needed.', 'Admin access only.'));
288+
cb(helper.checkAdminOrWebArenaSuper(connection, UNAUTHORIZED_MESSAGE, NON_ADMIN_OR_WEB_ARENA_SUPER_MESSAGE));
282289
}, function (cb) {
283290
checkRoundId(api, dbConnectionMap, roundId, cb);
284291
}, function (error, cb) {

0 commit comments

Comments
 (0)