mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 14:23:17 -04:00
feat: add api to get users for share
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
22ca454130
commit
bbabf50984
6 changed files with 65 additions and 1 deletions
|
|
@ -824,6 +824,7 @@ return array(
|
|||
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
|
||||
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
|
||||
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
|
||||
'OCP\\Share\\IShareProviderGetUsers' => $baseDir . '/lib/public/Share/IShareProviderGetUsers.php',
|
||||
'OCP\\Share\\IShareProviderSupportsAccept' => $baseDir . '/lib/public/Share/IShareProviderSupportsAccept.php',
|
||||
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => $baseDir . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
|
||||
'OCP\\Share\\IShareProviderWithNotification' => $baseDir . '/lib/public/Share/IShareProviderWithNotification.php',
|
||||
|
|
|
|||
|
|
@ -865,6 +865,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
|
||||
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
|
||||
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
|
||||
'OCP\\Share\\IShareProviderGetUsers' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderGetUsers.php',
|
||||
'OCP\\Share\\IShareProviderSupportsAccept' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAccept.php',
|
||||
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
|
||||
'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use OCP\Share\Exceptions\ShareNotFound;
|
|||
use OCP\Share\IAttributes;
|
||||
use OCP\Share\IManager;
|
||||
use OCP\Share\IShare;
|
||||
use OCP\Share\IShareProviderGetUsers;
|
||||
use OCP\Share\IShareProviderSupportsAccept;
|
||||
use OCP\Share\IShareProviderSupportsAllSharesInFolder;
|
||||
use OCP\Share\IShareProviderWithNotification;
|
||||
|
|
@ -44,7 +45,11 @@ use function str_starts_with;
|
|||
*
|
||||
* @package OC\Share20
|
||||
*/
|
||||
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept, IShareProviderSupportsAllSharesInFolder {
|
||||
class DefaultShareProvider implements
|
||||
IShareProviderWithNotification,
|
||||
IShareProviderSupportsAccept,
|
||||
IShareProviderSupportsAllSharesInFolder,
|
||||
IShareProviderGetUsers {
|
||||
public function __construct(
|
||||
private IDBConnection $dbConn,
|
||||
private IUserManager $userManager,
|
||||
|
|
@ -1678,4 +1683,15 @@ class DefaultShareProvider implements IShareProviderWithNotification, IShareProv
|
|||
}
|
||||
return \json_encode($compressedAttributes);
|
||||
}
|
||||
|
||||
public function getUsersForShare(IShare $share): iterable {
|
||||
if ($share->getShareType() === IShare::TYPE_USER) {
|
||||
return [new LazyUser($share->getSharedWith(), $this->userManager)];
|
||||
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
|
||||
$group = $this->groupManager->get($share->getSharedWith());
|
||||
return $group->getUsers();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1884,4 +1884,13 @@ class Manager implements IManager {
|
|||
$this->logger->error("Error while sending ' . $name . ' event", ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getUsersForShare(IShare $share): iterable {
|
||||
$provider = $this->factory->getProviderForType($share->getShareType());
|
||||
if ($provider instanceof Share\IShareProviderGetUsers) {
|
||||
return $provider->getUsersForShare($share);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -518,4 +518,13 @@ interface IManager {
|
|||
* @since 31.0.0
|
||||
*/
|
||||
public function generateToken(): string;
|
||||
|
||||
/**
|
||||
* Get all users with access to a share
|
||||
*
|
||||
* @param IShare $share
|
||||
* @return iterable<IUser>
|
||||
* @since 33.0.0
|
||||
*/
|
||||
public function getUsersForShare(IShare $share): iterable;
|
||||
}
|
||||
|
|
|
|||
28
lib/public/Share/IShareProviderGetUsers.php
Normal file
28
lib/public/Share/IShareProviderGetUsers.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCP\Share;
|
||||
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* Interface IShareProviderSupportsAccept
|
||||
*
|
||||
* This interface allows to define IShareProvider that can list users for share with the getUsersForShare method,
|
||||
* which is available since Nextcloud 17.
|
||||
*
|
||||
* @since 33.0.0
|
||||
*/
|
||||
interface IShareProviderGetUsers extends IShareProvider {
|
||||
/**
|
||||
* Get all users with access to a share
|
||||
*
|
||||
* @param IShare $share
|
||||
* @return iterable<IUser>
|
||||
* @since 33.0.0
|
||||
*/
|
||||
public function getUsersForShare(IShare $share): iterable;
|
||||
}
|
||||
Loading…
Reference in a new issue