@@ -820,36 +820,21 @@ async function validateChallengeTerms (terms = []) {
820
820
*/
821
821
async function _filterChallengesByGroupsAccess ( currentUser , challenges ) {
822
822
const res = [ ]
823
- let userGroups
824
823
const needToCheckForGroupAccess = ! currentUser ? true : ! currentUser . isMachine && ! hasAdminRole ( currentUser )
825
- const subGroupsMap = { }
824
+ if ( ! needToCheckForGroupAccess ) return challenges
825
+
826
+ let userGroups
827
+
826
828
for ( const challenge of challenges ) {
827
829
challenge . groups = _ . filter ( challenge . groups , g => ! _ . includes ( [ 'null' , 'undefined' ] , _ . toString ( g ) . toLowerCase ( ) ) )
828
- let expandedGroups = [ ]
829
830
if ( ! challenge . groups || _ . get ( challenge , 'groups.length' , 0 ) === 0 || ! needToCheckForGroupAccess ) {
830
831
res . push ( challenge )
831
832
} else if ( currentUser ) {
832
- // get user groups if not yet
833
833
if ( _ . isNil ( userGroups ) ) {
834
- userGroups = await getUserGroups ( currentUser . userId )
835
- }
836
- // Expand challenge groups by subGroups
837
- // results are being saved on a hashmap for efficiency
838
- for ( const group of challenge . groups ) {
839
- let subGroups
840
- if ( subGroupsMap [ group ] ) {
841
- subGroups = subGroupsMap [ group ]
842
- } else {
843
- subGroups = await expandWithSubGroups ( group )
844
- subGroupsMap [ group ] = subGroups
845
- }
846
- expandedGroups = [
847
- ..._ . concat ( expandedGroups , subGroups )
848
- ]
834
+ userGroups = await getCompleteUserGroupTreeIds ( currentUser . userId )
849
835
}
850
- // check if there is matched group
851
- // logger.debug('Groups', challenge.groups, userGroups)
852
- if ( _ . find ( expandedGroups , ( group ) => ! ! _ . find ( userGroups , ( ug ) => ug . id === group ) ) ) {
836
+ // get user groups if not yet
837
+ if ( _ . find ( challenge . groups , ( group ) => ! ! _ . find ( userGroups , ( ug ) => ug . id === group ) ) ) {
853
838
res . push ( challenge )
854
839
}
855
840
}
0 commit comments