3
3
*
4
4
* The APIs to register a challenge (studio category or software category) for the current logged-in user.
5
5
*
6
- * @version 1.2
7
- * @author ecnu_haozi, xjtufreeman, TCSASSEMBLER
6
+ * @version 1.3
7
+ * @author ecnu_haozi, xjtufreeman, bugbuka
8
8
*
9
9
* changes in 1.1:
10
10
* Combine Challenge Registration API(BUGR-11058)
11
11
*
12
12
* changes in 1.2:
13
13
* 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
14
17
*/
15
18
"use strict" ;
16
19
@@ -26,25 +29,6 @@ var ForbiddenError = require('../errors/ForbiddenError');
26
29
*/
27
30
var forumWrapper = null ;
28
31
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
-
48
32
//constants
49
33
var DESIGN_PROJECT_TYPE = 1 ,
50
34
DEVELOPMENT_PROJECT_TYPE = 2 ,
@@ -162,27 +146,6 @@ var persistResource = function (api, resourceId, userId, challengeId, dbConnecti
162
146
} ) ;
163
147
} ;
164
148
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
-
186
149
/**
187
150
* Check if the rating suit for software category contests.
188
151
* The code logic is duplicated from server-side java code.
@@ -282,7 +245,7 @@ var projectTrack = function (api, userId, challengeId, componentInfo, dbConnecti
282
245
function ( resourceId , callback ) {
283
246
async . parallel ( [
284
247
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 ) ;
286
249
} ,
287
250
function ( cb ) {
288
251
prepareProjectResult (
@@ -487,7 +450,7 @@ var grantForumAccess = function (api, userId, activeForumCategoryId, next) {
487
450
api . log ( 'start to grant user ' + userId + ' forum category ' + activeForumCategoryId + ' access.' ) ;
488
451
async . waterfall ( [
489
452
function ( cb ) {
490
- getForumWrapper ( api , cb ) ;
453
+ api . challengeHelper . getForumWrapper ( api , cb ) ;
491
454
} , function ( forumWrapper , cb ) {
492
455
forumWrapper . assignRole ( userId , "Software_Users_" + activeForumCategoryId , function ( err ) {
493
456
if ( err ) {
@@ -646,8 +609,8 @@ var timelineNotification = function (api, userId, challengeId, dbConnectionMap,
646
609
dbConnectionMap ,
647
610
cb ) ;
648
611
} else {
649
- cb ( null ) ;
650
- }
612
+ cb ( null ) ;
613
+ }
651
614
}
652
615
] , next ) ;
653
616
} ;
@@ -685,23 +648,23 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
685
648
if ( connection . dbConnectionMap ) {
686
649
api . log ( "Execute registerSoftwareChallengeAction#run" , 'debug' ) ;
687
650
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
+ } ;
696
660
} ;
697
- } ;
698
661
async . waterfall ( [
699
- function ( cb ) {
662
+ function ( cb ) {
700
663
async . parallel ( {
701
664
isCopilotPosting : execQuery ( 'check_challenge_is_copilot_posting' ) ,
702
665
isCopilot : execQuery ( 'check_is_copilot' )
703
666
} , cb ) ;
704
- } , function ( res , cb ) {
667
+ } , function ( res , cb ) {
705
668
if ( res . isCopilotPosting . length > 0 && res . isCopilotPosting [ 0 ] . challenge_is_copilot ) {
706
669
if ( res . isCopilot . length === 0 || ! res . isCopilot [ 0 ] . user_is_copilot ) {
707
670
cb ( new ForbiddenError ( 'You should be a copilot before register a copilot posting.' ) ) ;
@@ -713,6 +676,7 @@ var registerSoftwareChallengeAction = function (api, connection, next) {
713
676
connection ,
714
677
challengeId ,
715
678
"Submitter" , //optional value. Here we don't need to provide such value.
679
+ true ,
716
680
connection . dbConnectionMap ,
717
681
cb
718
682
) ;
@@ -763,6 +727,7 @@ var registerStudioChallengeAction = function (api, connection, next) {
763
727
connection ,
764
728
challengeId ,
765
729
"Submitter" ,
730
+ true ,
766
731
connection . dbConnectionMap ,
767
732
cb
768
733
) ;
0 commit comments