@@ -345,7 +345,7 @@ public function extractRangeData($result, $attribute) {
345345 }
346346 return [];
347347 }
348-
348+
349349 /**
350350 * Set password for an LDAP user identified by a DN
351351 *
@@ -646,6 +646,8 @@ public function mapAndAnnounceIfApplicable(
646646 if ($ this ->ncUserManager instanceof PublicEmitter && $ isUser ) {
647647 $ this ->cacheUserExists ($ name );
648648 $ this ->ncUserManager ->emit ('\OC\User ' , 'assignedUserId ' , [$ name ]);
649+ } elseif (!$ isUser ) {
650+ $ this ->cacheGroupExists ($ name );
649651 }
650652 return true ;
651653 }
@@ -749,6 +751,13 @@ public function cacheUserExists($ocName) {
749751 $ this ->connection ->writeToCache ('userExists ' .$ ocName , true );
750752 }
751753
754+ /**
755+ * caches a group as existing
756+ */
757+ public function cacheGroupExists (string $ gid ): void {
758+ $ this ->connection ->writeToCache ('groupExists ' .$ gid , true );
759+ }
760+
752761 /**
753762 * caches the user display name
754763 * @param string $ocName the internal Nextcloud username
@@ -938,7 +947,15 @@ public function batchApplyUserAttributes(array $ldapRecords){
938947 * @return array
939948 */
940949 public function fetchListOfGroups ($ filter , $ attr , $ limit = null , $ offset = null ) {
941- return $ this ->fetchList ($ this ->searchGroups ($ filter , $ attr , $ limit , $ offset ), $ this ->manyAttributes ($ attr ));
950+ $ groupRecords = $ this ->searchGroups ($ filter , $ attr , $ limit , $ offset );
951+ array_walk ($ groupRecords , function ($ record ) {
952+ $ newlyMapped = false ;
953+ $ gid = $ this ->dn2ocname ($ record ['dn ' ][0 ], null , false , $ newlyMapped , $ record );
954+ if (!$ newlyMapped && is_string ($ gid )) {
955+ $ this ->cacheGroupExists ($ gid );
956+ }
957+ });
958+ return $ this ->fetchList ($ groupRecords , $ this ->manyAttributes ($ attr ));
942959 }
943960
944961 /**
0 commit comments