@@ -3,6 +3,7 @@ const RegistrationDAO = require('../dao/RegistrationDAO')
3
3
const SequenceDAO = require ( '../dao/SequenceDAO' )
4
4
const logger = require ( '../common/logger' )
5
5
const config = require ( 'config' )
6
+ const { find, toString } = require ( 'lodash' )
6
7
7
8
/**
8
9
* Assign the given roleId to the specified userId in the given project.
@@ -51,38 +52,23 @@ async function assignRole (legacyChallengeId, roleId, userId, handle) {
51
52
52
53
/**
53
54
* Assign the given roleId to the specified userId in the given project.
54
- * @param operatorId
55
55
* @param legacyChallengeId
56
56
* the id of the contest/challenge.
57
57
* @param roleId
58
58
* the id of the role.
59
59
* @param userId
60
60
* the id of the user.
61
- * @param phase
62
- * the <code>Phase</code> associated with the resource.
63
- * @param addNotification
64
- * whether to add notification.
65
- * @param addForumWatch
66
- * whether to add forum watch.
67
- * @param isStudio
68
- * whether assign to studio contest.
69
- * @param checkTerm
70
- * whether to check terms and conditions.
71
61
*/
72
62
async function removeRole ( legacyChallengeId , roleId , userId ) {
73
- logger . debug ( 'Checking that User ' + userId + ' has role ' + roleId + ' for the project ' + legacyChallengeId )
74
- let found = await ProjectServices . resourceExists ( legacyChallengeId , roleId , userId )
75
- if ( ! found ) {
63
+ const resources = await ProjectServices . searchResources ( legacyChallengeId , roleId )
64
+ const existingResource = find ( resources , r => toString ( r . userid ) === toString ( userId ) )
65
+
66
+ if ( ! existingResource ) {
76
67
logger . error ( 'removeRole Resource Not Found' )
77
68
throw new Error ( 'User ' + userId + ' does not have role ' + roleId + ' for the project ' + legacyChallengeId )
78
69
}
79
- const resources = await ProjectServices . searchResources ( legacyChallengeId , roleId )
80
- for ( const resource of resources ) {
81
- logger . debug ( `removeRole - Loop ${ JSON . stringify ( resource ) } ` )
82
- if ( + resource . userid === userId ) {
83
- await ProjectServices . removeResource ( resource )
84
- }
85
- }
70
+
71
+ await ProjectServices . removeResource ( existingResource )
86
72
}
87
73
88
74
/**
0 commit comments