Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,7 @@
'OC\\Group\\Database' => $baseDir . '/lib/private/Group/Database.php',
'OC\\Group\\DisplayNameCache' => $baseDir . '/lib/private/Group/DisplayNameCache.php',
'OC\\Group\\Group' => $baseDir . '/lib/private/Group/Group.php',
'OC\\Group\\LazyGroup' => $baseDir . '/lib/private/Group/LazyGroup.php',
'OC\\Group\\Manager' => $baseDir . '/lib/private/Group/Manager.php',
'OC\\Group\\MetaData' => $baseDir . '/lib/private/Group/MetaData.php',
'OC\\HintException' => $baseDir . '/lib/private/HintException.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Group\\Database' => __DIR__ . '/../../..' . '/lib/private/Group/Database.php',
'OC\\Group\\DisplayNameCache' => __DIR__ . '/../../..' . '/lib/private/Group/DisplayNameCache.php',
'OC\\Group\\Group' => __DIR__ . '/../../..' . '/lib/private/Group/Group.php',
'OC\\Group\\LazyGroup' => __DIR__ . '/../../..' . '/lib/private/Group/LazyGroup.php',
'OC\\Group\\Manager' => __DIR__ . '/../../..' . '/lib/private/Group/Manager.php',
'OC\\Group\\MetaData' => __DIR__ . '/../../..' . '/lib/private/Group/MetaData.php',
'OC\\HintException' => __DIR__ . '/../../..' . '/lib/private/HintException.php',
Expand Down
121 changes: 121 additions & 0 deletions lib/private/Group/LazyGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

Comment thread
CarlSchwan marked this conversation as resolved.
declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OC\Group;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;

class LazyGroup implements IGroup {
private ?IGroup $group = null;

public function __construct(
private string $gid,
private IGroupManager $groupManager,
) {
}

#[\Override]
public function getGID(): string {
return $this->gid;
}

private function getGroup(): IGroup {
if ($this->group === null) {
$this->group = $this->groupManager->get($this->gid);
}
if ($this->group === null) {
Server::get(LoggerInterface::class)->error('Trying to use the deleted group: "' . $this->gid . '"', ['app' => 'core']);
$this->group = new Group($this->gid, [], Server::get(IEventDispatcher::class), Server::get(IUserManager::class));
}
return $this->group;
}

#[\Override]
public function getDisplayName(): string {
// Use display name cache from IGroupManager
return $this->groupManager->getDisplayName($this->gid) ?? $this->gid;
}

#[\Override]
public function setDisplayName(string $displayName): bool {
return $this->getGroup()->setDisplayName($displayName);
}

#[\Override]
public function getUsers(): array {
return $this->getGroup()->getUsers();
}

#[\Override]
public function inGroup(IUser $user): bool {
return $this->getGroup()->inGroup($user);
}

#[\Override]
public function addUser(IUser $user): void {
$this->getGroup()->addUser($user);
}

#[\Override]
public function removeUser(IUser $user): void {
$this->getGroup()->removeUser($user);
}

#[\Override]
public function searchUsers(string $search, ?int $limit = null, ?int $offset = null): array {
return $this->getGroup()->searchUsers($search, $limit, $offset);
}

#[\Override]
public function count($search = ''): int|bool {
return $this->getGroup()->count($search);
}

#[\Override]
public function countDisabled(): int|bool {
return $this->getGroup()->countDisabled();
}

#[\Override]
public function searchDisplayName(string $search, ?int $limit = null, ?int $offset = null): array {
return $this->getGroup()->searchDisplayName($search, $limit, $offset);
}

#[\Override]
public function getBackendNames(): array {
return $this->getGroup()->getBackendNames();
}

#[\Override]
public function delete(): bool {
return $this->getGroup()->delete();
}

#[\Override]
public function canRemoveUser(): bool {
return $this->getGroup()->canRemoveUser();
}

#[\Override]
public function canAddUser(): bool {
return $this->getGroup()->canAddUser();
}

#[\Override]
public function hideFromCollaboration(): bool {
return $this->getGroup()->hideFromCollaboration();
}
}
19 changes: 1 addition & 18 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,7 @@ public function getUserIdGroups(string $uid): array {
$groups = [];

foreach ($this->getUserIdGroupIds($uid) as $groupId) {
$aGroup = $this->get($groupId);
if ($aGroup instanceof IGroup) {
$groups[$groupId] = $aGroup;
} else {
$this->logger->debug('User "' . $uid . '" belongs to deleted group: "' . $groupId . '"', ['app' => 'core']);
Comment thread
CarlSchwan marked this conversation as resolved.
}
$groups[$groupId] = new LazyGroup($groupId, $this);
}

return $groups;
Expand Down Expand Up @@ -401,18 +396,6 @@ public function getDisplayName(string $groupId): ?string {
return $this->displayNameCache->getDisplayName($groupId);
}

/**
* get an array of groupid and displayName for a user
*
* @param IUser $user
* @return array ['displayName' => displayname]
*/
public function getUserGroupNames(IUser $user) {
return array_map(function ($group) {
return ['displayName' => $this->displayNameCache->getDisplayName($group->getGID())];
}, $this->getUserGroups($user));
}

#[\Override]
public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid);
Expand Down
Loading
Loading