@@ -80,6 +80,25 @@ class ChallengeHelper {
80
80
}
81
81
}
82
82
83
+ /**
84
+ * Validate Challenge groups.
85
+ * @param {Object } groups the group of a challenge
86
+ */
87
+ async validateGroups ( groups ) {
88
+ const promises = [ ] ;
89
+ _ . each ( groups , ( g ) => {
90
+ promises . push (
91
+ ( async ( ) => {
92
+ const group = await helper . getGroupById ( g ) ;
93
+ if ( ! group || group . status !== "active" ) {
94
+ throw new errors . BadRequestError ( "The groups provided are invalid " + g ) ;
95
+ }
96
+ } ) ( )
97
+ ) ;
98
+ } ) ;
99
+ await Promise . all ( promises ) ;
100
+ }
101
+
83
102
async validateCreateChallengeRequest ( currentUser , challenge ) {
84
103
// projectId is required for non self-service challenges
85
104
if ( challenge . legacy . selfService == null && challenge . projectId == null ) {
@@ -98,7 +117,13 @@ class ChallengeHelper {
98
117
// helper.ensureNoDuplicateOrNullElements(challenge.events, 'events')
99
118
100
119
// check groups authorization
101
- await helper . ensureAccessibleByGroupsAccess ( currentUser , challenge ) ;
120
+ if ( challenge . groups && challenge . groups . length > 0 ) {
121
+ if ( currentUser . isMachine || hasAdminRole ( currentUser ) ) {
122
+ await this . validateGroups ( challenge . groups ) ;
123
+ } else {
124
+ await helper . ensureAccessibleByGroupsAccess ( currentUser , challenge ) ;
125
+ }
126
+ }
102
127
103
128
if ( challenge . constraints ) {
104
129
await ChallengeHelper . validateChallengeConstraints ( challenge . constraints ) ;
@@ -118,8 +143,12 @@ class ChallengeHelper {
118
143
}
119
144
120
145
// check groups access to be updated group values
121
- if ( data . groups ) {
122
- await ensureAcessibilityToModifiedGroups ( currentUser , data , challenge ) ;
146
+ if ( data . groups && data . groups . length > 0 ) {
147
+ if ( currentUser . isMachine || hasAdminRole ( currentUser ) ) {
148
+ await this . validateGroups ( data . groups ) ;
149
+ } else {
150
+ await ensureAcessibilityToModifiedGroups ( currentUser , data , challenge ) ;
151
+ }
123
152
}
124
153
125
154
// Ensure descriptionFormat is either 'markdown' or 'html'
0 commit comments