@@ -110,6 +110,25 @@ public function deleteSubAdmin(IUser $user, IGroup $group): void {
110110 * @return IGroup[]
111111 */
112112 public function getSubAdminsGroups (IUser $ user ): array {
113+ $ groupIds = $ this ->getSubAdminsGroupIds ($ user );
114+
115+ $ groups = [];
116+ foreach ($ groupIds as $ groupId ) {
117+ $ group = $ this ->groupManager ->get ($ groupId );
118+ if ($ group !== null ) {
119+ $ groups [$ group ->getGID ()] = $ group ;
120+ }
121+ }
122+
123+ return $ groups ;
124+ }
125+
126+ /**
127+ * Get group ids of a SubAdmin
128+ * @param IUser $user the SubAdmin
129+ * @return string[]
130+ */
131+ public function getSubAdminsGroupIds (IUser $ user ): array {
113132 $ qb = $ this ->dbConn ->getQueryBuilder ();
114133
115134 $ result = $ qb ->select ('gid ' )
@@ -119,10 +138,7 @@ public function getSubAdminsGroups(IUser $user): array {
119138
120139 $ groups = [];
121140 while ($ row = $ result ->fetch ()) {
122- $ group = $ this ->groupManager ->get ($ row ['gid ' ]);
123- if (!is_null ($ group )) {
124- $ groups [$ group ->getGID ()] = $ group ;
125- }
141+ $ groups [] = $ row ['gid ' ];
126142 }
127143 $ result ->closeCursor ();
128144
@@ -255,13 +271,11 @@ public function isUserAccessible(IUser $subadmin, IUser $user): bool {
255271 if ($ this ->groupManager ->isAdmin ($ user ->getUID ())) {
256272 return false ;
257273 }
258- $ accessibleGroups = $ this ->getSubAdminsGroups ($ subadmin );
259- foreach ($ accessibleGroups as $ accessibleGroup ) {
260- if ($ accessibleGroup ->inGroup ($ user )) {
261- return true ;
262- }
263- }
264- return false ;
274+
275+ $ accessibleGroups = $ this ->getSubAdminsGroupIds ($ subadmin );
276+ $ userGroups = $ this ->groupManager ->getUserGroupIds ($ user );
277+
278+ return !empty (array_intersect ($ accessibleGroups , $ userGroups ));
265279 }
266280
267281 /**
0 commit comments