File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -895,10 +895,27 @@ async function validateChallengeTerms(terms = []) {
895
895
*/
896
896
async function _filterChallengesByGroupsAccess ( currentUser , challenges ) {
897
897
const res = [ ] ;
898
- const needToCheckForGroupAccess = ! currentUser
899
- ? true
900
- : ! currentUser . isMachine && ! hasAdminRole ( currentUser ) ;
901
- if ( ! needToCheckForGroupAccess ) return challenges ;
898
+ if ( currentUser && ! currentUser . isMachine && ! hasAdminRole ( currentUser ) )
899
+ {
900
+ for ( const challenge of challenges ) {
901
+ if ( challenge && challenge . groups && challenge . groups . length > 0 ) {
902
+ const promises = [ ] ;
903
+ _ . each ( challenge . groups , ( g ) => {
904
+ promises . push (
905
+ ( async ( ) => {
906
+ const group = await getGroupById ( g ) ;
907
+ if ( ! group || ! group . status === 'active' ) {
908
+ throw new errors . BadRequestError ( "The groups provided are invalid " + g ) ;
909
+ }
910
+ } ) ( )
911
+ ) ;
912
+ } ) ;
913
+ await Promise . all ( promises ) ;
914
+ res . push ( challenge ) ;
915
+ }
916
+ }
917
+ return res ;
918
+ }
902
919
903
920
let userGroups ;
904
921
@@ -909,8 +926,7 @@ async function _filterChallengesByGroupsAccess(currentUser, challenges) {
909
926
) ;
910
927
if (
911
928
! challenge . groups ||
912
- _ . get ( challenge , "groups.length" , 0 ) === 0 ||
913
- ! needToCheckForGroupAccess
929
+ _ . get ( challenge , "groups.length" , 0 ) === 0
914
930
) {
915
931
res . push ( challenge ) ;
916
932
} else if ( currentUser ) {
You can’t perform that action at this time.
0 commit comments