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

Release #435

Merged
merged 11 commits into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions actions/challengeRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,12 @@ exports.registerChallenge = {
if (error) {
console.log("error: " + error);
cb(error);
} else {
console.log("error11: " + error);
api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
} else {
api.helper.checkUserActivated(connection.caller.handle, api, connection.dbConnectionMap, function (err, inactive) {
var fail = err || inactive;
if (fail) cb(fail);
else api.dataAccess.executeQuery('check_challenge_exists', {challengeId: challengeId}, connection.dbConnectionMap, cb);
}, "You must activate your account in order to participate. Please check your e-mail in order to complete the activation process, or contact support@topcoder.com if you did not receive an e-mail.");
}
}, function (result, cb) {
if (result.length > 0) {
Expand Down
20 changes: 16 additions & 4 deletions actions/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ var QUERY_PATH = './queries/';
*/
var TECHNOLOGY_FILTER = ' AND EXISTS (SELECT DISTINCT 1 FROM comp_technology ct WHERE ct.comp_vers_id = pi1.value ' +
'AND ct.technology_type_id IN (@filter@))';


var EXT_TECHNOLOGY_FILTER = ' AND (pn.value LIKE ("%@tech@%") OR EXISTS (SELECT DISTINCT 1 FROM comp_technology ct WHERE ct.comp_vers_id = pi1.value ' +
'AND ct.technology_type_id IN (@filter@)))';
/**
* The platform filter for challenges api.
* @since 1.23
Expand Down Expand Up @@ -745,14 +747,15 @@ function transferResultV2(src, helper) {
* @param {String} content - the content that need in template.
* @since 1.23
*/
var editSql = function (sql, template, content) {
var editSql = function (sql, template, content, tech) {
// For empty sql just return it.
if (sql.length === 0) {
return sql;
}
var index = sql.toLowerCase().indexOf('order by');
if (!_.isUndefined(template)) {
template = template.replace('@filter@', content);
template = template.replace('@tech@', tech);
}
return sql.slice(0, index) + template + sql.slice(index, sql.length);
};
Expand All @@ -776,8 +779,13 @@ var addFilter = function (sql, filter, isMyChallenges, helper, caller) {

if (_.isDefined(filter.technologies)) {
technology = filter.technologies.join(', ');
sql.count = editSql(sql.count, TECHNOLOGY_FILTER, technology);
sql.data = editSql(sql.data, TECHNOLOGY_FILTER, technology);
if (filter.tech) {
sql.count = editSql(sql.count, EXT_TECHNOLOGY_FILTER, technology, filter.tech);
sql.data = editSql(sql.data, EXT_TECHNOLOGY_FILTER, technology, filter.tech);
} else {
sql.count = editSql(sql.count, TECHNOLOGY_FILTER, technology);
sql.data = editSql(sql.data, TECHNOLOGY_FILTER, technology);
}
}

if (_.isDefined(filter.challengeType)) {
Expand Down Expand Up @@ -3708,6 +3716,10 @@ var getChallenges = function (api, connection, listType, isMyChallenges, next) {
},
function (cb) {
validateInputParameterV2(helper, caller, type, query, filter, pageIndex, pageSize, sortColumn, sortOrder, listType, dbConnectionMap, cb);

if (filter.technologies) {
filter.tech = filter.technologies.split(',')[0];
}
}, function (cb) {
if (pageIndex === -1) {
pageIndex = 1;
Expand Down
2 changes: 1 addition & 1 deletion apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -9946,7 +9946,7 @@ Request
}

## Register for a software/studio challenge [/challenges/{challengeId}/register]
### Register for a software/studio challenge [GET]
### Register for a software/studio challenge [POST]

+ Parameters
+ challengeId (required, number, `1234567`) ... The challenge for which to register
Expand Down
5 changes: 3 additions & 2 deletions initializers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ helper.checkUserExists = function (handle, api, dbConnectionMap, callback) {
* @param {Object} dbConnectionMap - the database connection map
* @param {Function<err>} callback - the callback function
*/
helper.checkUserActivated = function (handle, api, dbConnectionMap, callback) {
helper.checkUserActivated = function (handle, api, dbConnectionMap, callback, textResponse) {
api.dataAccess.executeQuery('check_user_activated', { handle: handle }, dbConnectionMap, function (err, result) {
if (err) {
callback(err, null);
Expand All @@ -1634,7 +1634,8 @@ helper.checkUserActivated = function (handle, api, dbConnectionMap, callback) {
if (result && result[0] && result[0].status === 'A') {
callback(err, null);
} else {
callback(err, new BadRequestError('User is not activated.'));
var message = textResponse || 'User is not activated.';
callback(err, new BadRequestError(message));
}
});
};
Expand Down