Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return correct list of managers for a user #48538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 36 additions & 2 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeUserRemovedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\Group\ISubAdmin;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IImage;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager;
use OCP\User\Backend\IGetHomeBackend;
use OCP\User\Backend\IPasswordHashBackend;
Expand Down Expand Up @@ -78,6 +82,18 @@ class User implements IUser {
/** @var IURLGenerator */
private $urlGenerator;

/** @var IUserSession */
private $userSession;

/** @var IUserManager */
private $userManager;

/** @var ISubAdmin */
private $subAdminManager;

/** @var IGroupManager */
private $groupManager;

public function __construct(string $uid, ?UserInterface $backend, IEventDispatcher $dispatcher, $emitter = null, ?IConfig $config = null, $urlGenerator = null) {
$this->uid = $uid;
$this->backend = $backend;
Expand All @@ -91,6 +107,10 @@ public function __construct(string $uid, ?UserInterface $backend, IEventDispatch
$this->urlGenerator = \OC::$server->getURLGenerator();
}
$this->dispatcher = $dispatcher;
$this->userSession = \OCP\Server::get(IUserSession::class);
$this->userManager = \OCP\Server::get(IUserManager::class);
$this->subAdminManager = \OCP\Server::get(ISubAdmin::class);
$this->groupManager = \OCP\Server::get(IGroupManager::class);
}

/**
Expand Down Expand Up @@ -536,13 +556,27 @@ public function setQuota($quota) {
}

public function getManagerUids(): array {
$user = $this->userSession->getUser();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it cleared as there is already a lot of reference to user in this file.

Suggested change
$user = $this->userSession->getUser();
$connectedUser = $this->userSession->getUser();

if (!($user instanceof IUser)) {
return [];
}
$encodedUids = $this->config->getUserValue(
$this->uid,
'settings',
self::CONFIG_KEY_MANAGERS,
'[]'
'[]',
);
return json_decode($encodedUids, false, 512, JSON_THROW_ON_ERROR);
/** @var string[] $managerUids */
$managerUids = json_decode($encodedUids, false, 512, JSON_THROW_ON_ERROR);
$userId = $user->getUID();
if ($this->groupManager->isAdmin($userId) || $this->groupManager->isDelegatedAdmin($userId)) {
return $managerUids;
}
$accessibleManagers = array_values(array_filter(
$managerUids,
fn (string $managerUid) => $this->subAdminManager->isUserAccessible($user, $this->userManager->get($managerUid)),
));
return $accessibleManagers;
}

public function setManagerUids(array $uids): void {
Expand Down
Loading