|
|
|
@ -21,6 +21,7 @@ |
|
|
|
|
* @author Vincent Petry <vincent@nextcloud.com> |
|
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br> |
|
|
|
|
* @author voxsim "Simon Vocella" |
|
|
|
|
* @author Carl Schwan <carl@carlschwan.eu> |
|
|
|
|
* |
|
|
|
|
* @license AGPL-3.0 |
|
|
|
|
* |
|
|
|
@ -41,6 +42,7 @@ namespace OC\Group; |
|
|
|
|
|
|
|
|
|
use OC\Hooks\PublicEmitter; |
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
|
|
|
|
use OCP\Group\Backend\IGroupDetailsBackend; |
|
|
|
|
use OCP\Group\Events\BeforeGroupCreatedEvent; |
|
|
|
|
use OCP\Group\Events\GroupCreatedEvent; |
|
|
|
|
use OCP\GroupInterface; |
|
|
|
@ -74,10 +76,10 @@ class Manager extends PublicEmitter implements IGroupManager { |
|
|
|
|
private IEventDispatcher $dispatcher; |
|
|
|
|
private LoggerInterface $logger; |
|
|
|
|
|
|
|
|
|
/** @var \OC\Group\Group[] */ |
|
|
|
|
/** @var array<string, IGroup> */ |
|
|
|
|
private $cachedGroups = []; |
|
|
|
|
|
|
|
|
|
/** @var (string[])[] */ |
|
|
|
|
/** @var array<string, list<string>> */ |
|
|
|
|
private $cachedUserGroups = []; |
|
|
|
|
|
|
|
|
|
/** @var \OC\SubAdmin */ |
|
|
|
@ -185,7 +187,7 @@ class Manager extends PublicEmitter implements IGroupManager { |
|
|
|
|
if ($backend->implementsActions(Backend::GROUP_DETAILS)) { |
|
|
|
|
$groupData = $backend->getGroupDetails($gid); |
|
|
|
|
if (is_array($groupData) && !empty($groupData)) { |
|
|
|
|
// take the display name from the first backend that has a non-null one |
|
|
|
|
// take the display name from the last backend that has a non-null one |
|
|
|
|
if (is_null($displayName) && isset($groupData['displayName'])) { |
|
|
|
|
$displayName = $groupData['displayName']; |
|
|
|
|
} |
|
|
|
@ -198,10 +200,57 @@ class Manager extends PublicEmitter implements IGroupManager { |
|
|
|
|
if (count($backends) === 0) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
/** @var GroupInterface[] $backends */ |
|
|
|
|
$this->cachedGroups[$gid] = new Group($gid, $backends, $this->dispatcher, $this->userManager, $this, $displayName); |
|
|
|
|
return $this->cachedGroups[$gid]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @brief Batch method to create group objects |
|
|
|
|
* |
|
|
|
|
* @param list<string> $gids List of groupIds for which we want to create a IGroup object |
|
|
|
|
* @param array<string, string> $displayNames Array containing already know display name for a groupId |
|
|
|
|
* @return array<string, IGroup> |
|
|
|
|
*/ |
|
|
|
|
protected function getGroupsObject(array $gids, array $displayNames = []): array { |
|
|
|
|
$backends = []; |
|
|
|
|
$groups = []; |
|
|
|
|
foreach ($gids as $gid) { |
|
|
|
|
$backends[$gid] = []; |
|
|
|
|
if (!isset($displayNames[$gid])) { |
|
|
|
|
$displayNames[$gid] = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
foreach ($this->backends as $backend) { |
|
|
|
|
if ($backend instanceof IGroupDetailsBackend || $backend->implementsActions(GroupInterface::GROUP_DETAILS)) { |
|
|
|
|
/** @var IGroupDetailsBackend $backend */ |
|
|
|
|
$groupDatas = $backend->getGroupsDetails($gids); |
|
|
|
|
foreach ($groupDatas as $gid => $groupData) { |
|
|
|
|
if (!empty($groupData)) { |
|
|
|
|
// take the display name from the last backend that has a non-null one |
|
|
|
|
if (isset($groupData['displayName'])) { |
|
|
|
|
$displayNames[$gid] = $groupData['displayName']; |
|
|
|
|
} |
|
|
|
|
$backends[$gid][] = $backend; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$existingGroups = $backend->groupsExists($gids); |
|
|
|
|
foreach ($existingGroups as $group) { |
|
|
|
|
$backends[$group][] = $backend; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
foreach ($gids as $gid) { |
|
|
|
|
if (count($backends[$gid]) === 0) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
$this->cachedGroups[$gid] = new Group($gid, $backends[$gid], $this->dispatcher, $this->userManager, $this, $displayNames[$gid]); |
|
|
|
|
$groups[$gid] = $this->cachedGroups[$gid]; |
|
|
|
|
} |
|
|
|
|
return $groups; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param string $gid |
|
|
|
|
* @return bool |
|
|
|
@ -246,13 +295,9 @@ class Manager extends PublicEmitter implements IGroupManager { |
|
|
|
|
$groups = []; |
|
|
|
|
foreach ($this->backends as $backend) { |
|
|
|
|
$groupIds = $backend->getGroups($search, $limit ?? -1, $offset ?? 0); |
|
|
|
|
foreach ($groupIds as $groupId) { |
|
|
|
|
$aGroup = $this->get($groupId); |
|
|
|
|
if ($aGroup instanceof IGroup) { |
|
|
|
|
$groups[$groupId] = $aGroup; |
|
|
|
|
} else { |
|
|
|
|
$this->logger->debug('Group "' . $groupId . '" was returned by search but not found through direct access', ['app' => 'core']); |
|
|
|
|
} |
|
|
|
|
$newGroups = $this->getGroupsObject($groupIds); |
|
|
|
|
foreach ($newGroups as $groupId => $group) { |
|
|
|
|
$groups[$groupId] = $group; |
|
|
|
|
} |
|
|
|
|
if (!is_null($limit) and $limit <= 0) { |
|
|
|
|
return array_values($groups); |
|
|
|
|