File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 1+ Bugfix: Only call getGroupDetails when the group exists
2+
3+ When getting a group, the getGroupDetails method could be called for a group
4+ that does not exist. That is unnecessary and may cause a group backend implementation
5+ to log an error. The code has been refactored to avoid this happening.
6+
7+ https://github.com/owncloud/core/pull/40261
Original file line number Diff line number Diff line change @@ -176,17 +176,17 @@ public function get($gid) {
176176 protected function getGroupObject ($ gid , $ displayName = null ) {
177177 $ backends = [];
178178 foreach ($ this ->backends as $ backend ) {
179- if ($ backend ->implementsActions (\OC \Group \Backend::GROUP_DETAILS )) {
180- /* @phan-suppress-next-line PhanUndeclaredMethod */
181- $ groupData = $ backend ->getGroupDetails ($ gid );
182- if (\is_array ($ groupData )) {
183- // take the display name from the first backend that has a non-null one
184- if ($ displayName === null && isset ($ groupData ['displayName ' ])) {
185- $ displayName = $ groupData ['displayName ' ];
179+ if ($ backend ->groupExists ($ gid )) {
180+ if ($ backend ->implementsActions (\OC \Group \Backend::GROUP_DETAILS )) {
181+ /* @phan-suppress-next-line PhanUndeclaredMethod */
182+ $ groupData = $ backend ->getGroupDetails ($ gid );
183+ if (\is_array ($ groupData )) {
184+ // take the display name from the first backend that has a non-null one
185+ if ($ displayName === null && isset ($ groupData ['displayName ' ])) {
186+ $ displayName = $ groupData ['displayName ' ];
187+ }
186188 }
187- $ backends [] = $ backend ;
188189 }
189- } elseif ($ backend ->groupExists ($ gid )) {
190190 $ backends [] = $ backend ;
191191 }
192192 }
Original file line number Diff line number Diff line change @@ -1158,6 +1158,9 @@ public function testGroupDisplayName() {
11581158 GroupInterface::DELETE_GROUP |
11591159 GroupInterface::GROUP_DETAILS
11601160 );
1161+ $ backend ->expects ($ this ->any ())
1162+ ->method ('groupExists ' )
1163+ ->will ($ this ->returnValue (true ));
11611164 $ backend ->expects ($ this ->any ())
11621165 ->method ('getGroupDetails ' )
11631166 ->will ($ this ->returnValueMap ([
You can’t perform that action at this time.
0 commit comments