From bbabf5098480341f089b9399403cb758d5485583 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 17 Dec 2025 20:56:24 +0100 Subject: [PATCH] feat: add api to get users for share Signed-off-by: Robin Appelman --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Share20/DefaultShareProvider.php | 18 ++++++++++++- lib/private/Share20/Manager.php | 9 +++++++ lib/public/Share/IManager.php | 9 +++++++ lib/public/Share/IShareProviderGetUsers.php | 28 ++++++++++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 lib/public/Share/IShareProviderGetUsers.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 0b6dd29f204..5d515c66dd3 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9c34d2cd4de..d25b0f94870 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.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', diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index bc74002fcbc..3104ac7eff7 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.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 []; + } + } } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 1dada16de4e..72da67ec91b 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -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 []; + } + } } diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 92bd7b825f3..8b238abc13f 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -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 + * @since 33.0.0 + */ + public function getUsersForShare(IShare $share): iterable; } diff --git a/lib/public/Share/IShareProviderGetUsers.php b/lib/public/Share/IShareProviderGetUsers.php new file mode 100644 index 00000000000..44e2d8eab70 --- /dev/null +++ b/lib/public/Share/IShareProviderGetUsers.php @@ -0,0 +1,28 @@ + + * @since 33.0.0 + */ + public function getUsersForShare(IShare $share): iterable; +}