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

Commit 8e2a57e

Browse files
committed
Merge pull request #186 from Ghost141/challenges_api_improvement
Challenges api improvement
2 parents 76e852e + c4f81a7 commit 8e2a57e

File tree

190 files changed

+8712
-708
lines changed

Some content is hidden

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

190 files changed

+8712
-708
lines changed

actions/challengeRegistration.js

Lines changed: 22 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
*
44
* The APIs to register a challenge (studio category or software category) for the current logged-in user.
55
*
6-
* @version 1.2
7-
* @author ecnu_haozi, xjtufreeman, TCSASSEMBLER
6+
* @version 1.3
7+
* @author ecnu_haozi, xjtufreeman, bugbuka
88
*
99
* changes in 1.1:
1010
* Combine Challenge Registration API(BUGR-11058)
1111
*
1212
* changes in 1.2:
1313
* Integrate the forums operation(Module Assembly - Integrating Forums Wrapper with Challenge Registration API)
14+
*
15+
* changes in 1.3:
16+
* move common function getForumWrapper, aduitResourceAddition to challengeHelper.js
1417
*/
1518
"use strict";
1619

@@ -26,25 +29,6 @@ var ForbiddenError = require('../errors/ForbiddenError');
2629
*/
2730
var forumWrapper = null;
2831

29-
/**
30-
* Get forum wrapper. It is initialized only once.
31-
* @param {Object} api The api object that is used to access the infrastructure.
32-
* @param {Function<err, forumWrapper>} callback the callback function
33-
*/
34-
var getForumWrapper = function (api, callback) {
35-
if (forumWrapper) {
36-
callback(null, forumWrapper);
37-
} else {
38-
try {
39-
forumWrapper = new ForumWrapper(api.config.general.devForumJNDI);
40-
callback(null, forumWrapper);
41-
} catch (ex) {
42-
api.log('Failed to connect to forum: ' + ex + " " + (ex.stack || ''), 'error');
43-
callback(new Error('Failed to connect to forum'));
44-
}
45-
}
46-
};
47-
4832
//constants
4933
var DESIGN_PROJECT_TYPE = 1,
5034
DEVELOPMENT_PROJECT_TYPE = 2,
@@ -162,27 +146,6 @@ var persistResource = function (api, resourceId, userId, challengeId, dbConnecti
162146
});
163147
};
164148

165-
/**
166-
* Audit the challenge registration on table 'tcs_catalog.project_user_audit'.
167-
*
168-
* @param {Object} api The api object that is used to access the infrastructure.
169-
* @param {Number} userId The current logged-in user's id.
170-
* @param {Number} challengeId The id of the challenge to register.
171-
* @param {Object} dbConnectionMap The database connection map for the current request.
172-
* @param {Function<err, data>} next The callback to be called after this function is done.
173-
*/
174-
var aduitResourceAddition = function (api, userId, challengeId, dbConnectionMap, next) {
175-
api.dataAccess.executeQuery("audit_challenge_registration", {
176-
projectId: challengeId,
177-
resourceUserId: userId,
178-
resourceRoleId: SUBMITTER_RESOURCE_ROLE_ID,
179-
auditActionTypeId: PROJECT_USER_AUDIT_CREATE_TYPE,
180-
actionUserId: userId
181-
},
182-
dbConnectionMap,
183-
next);
184-
};
185-
186149
/**
187150
* Check if the rating suit for software category contests.
188151
* The code logic is duplicated from server-side java code.
@@ -282,7 +245,7 @@ var projectTrack = function (api, userId, challengeId, componentInfo, dbConnecti
282245
function (resourceId, callback) {
283246
async.parallel([
284247
function (cb) {
285-
aduitResourceAddition(api, userId, challengeId, dbConnectionMap, cb);
248+
api.challengeHelper.aduitResourceAddition(api, userId, challengeId, SUBMITTER_RESOURCE_ROLE_ID, PROJECT_USER_AUDIT_CREATE_TYPE, dbConnectionMap, cb);
286249
},
287250
function (cb) {
288251
prepareProjectResult(
@@ -487,7 +450,7 @@ var grantForumAccess = function (api, userId, activeForumCategoryId, next) {
487450
api.log('start to grant user ' + userId + ' forum category ' + activeForumCategoryId + ' access.');
488451
async.waterfall([
489452
function (cb) {
490-
getForumWrapper(api, cb);
453+
api.challengeHelper.getForumWrapper(api, cb);
491454
}, function (forumWrapper, cb) {
492455
forumWrapper.assignRole(userId, "Software_Users_" + activeForumCategoryId, function (err) {
493456
if (err) {
@@ -646,8 +609,8 @@ var timelineNotification = function (api, userId, challengeId, dbConnectionMap,
646609
dbConnectionMap,
647610
cb);
648611
} else {
649-
cb(null);
650-
}
612+
cb(null);
613+
}
651614
}
652615
], next);
653616
};
@@ -685,23 +648,23 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
685648
if (connection.dbConnectionMap) {
686649
api.log("Execute registerSoftwareChallengeAction#run", 'debug');
687650

688-
var challengeId = Number(connection.params.challengeId);
689-
var sqlParams = {
690-
challengeId: challengeId,
691-
user_id: connection.caller.userId
692-
};
693-
var execQuery = function (name) {
694-
return function (cbx) {
695-
api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx);
651+
var challengeId = Number(connection.params.challengeId),
652+
sqlParams = {
653+
challengeId: challengeId,
654+
user_id: connection.caller.userId
655+
},
656+
execQuery = function (name) {
657+
return function (cbx) {
658+
api.dataAccess.executeQuery(name, sqlParams, connection.dbConnectionMap, cbx);
659+
};
696660
};
697-
};
698661
async.waterfall([
699-
function(cb) {
662+
function (cb) {
700663
async.parallel({
701664
isCopilotPosting: execQuery('check_challenge_is_copilot_posting'),
702665
isCopilot: execQuery('check_is_copilot')
703666
}, cb);
704-
}, function(res, cb) {
667+
}, function (res, cb) {
705668
if (res.isCopilotPosting.length > 0 && res.isCopilotPosting[0].challenge_is_copilot) {
706669
if (res.isCopilot.length === 0 || !res.isCopilot[0].user_is_copilot) {
707670
cb(new ForbiddenError('You should be a copilot before register a copilot posting.'));
@@ -713,6 +676,7 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
713676
connection,
714677
challengeId,
715678
"Submitter", //optional value. Here we don't need to provide such value.
679+
true,
716680
connection.dbConnectionMap,
717681
cb
718682
);
@@ -763,6 +727,7 @@ var registerStudioChallengeAction = function (api, connection, next) {
763727
connection,
764728
challengeId,
765729
"Submitter",
730+
true,
766731
connection.dbConnectionMap,
767732
cb
768733
);

0 commit comments

Comments
 (0)