Skip to content

Commit 6f73b1d

Browse files
committed
Only call getGroupDetails if the group exists in the backend
1 parent 3eebf7b commit 6f73b1d

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

changelog/unreleased/40261

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

lib/private/Group/Manager.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff 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
}

tests/lib/Group/ManagerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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([

0 commit comments

Comments
 (0)