Skip to content

Commit 8b8c2f8

Browse files
committed
feat: add api to get users for share
Signed-off-by: Robin Appelman <[email protected]>
1 parent 68b9108 commit 8b8c2f8

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@
817817
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
818818
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
819819
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
820+
'OCP\\Share\\IShareProviderGetUsers' => $baseDir . '/lib/public/Share/IShareProviderGetUsers.php',
820821
'OCP\\Share\\IShareProviderSupportsAccept' => $baseDir . '/lib/public/Share/IShareProviderSupportsAccept.php',
821822
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => $baseDir . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
822823
'OCP\\Share\\IShareProviderWithNotification' => $baseDir . '/lib/public/Share/IShareProviderWithNotification.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
858858
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
859859
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
860860
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
861+
'OCP\\Share\\IShareProviderGetUsers' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderGetUsers.php',
861862
'OCP\\Share\\IShareProviderSupportsAccept' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAccept.php',
862863
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
863864
'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',

lib/private/Share20/DefaultShareProvider.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCP\Share\IAttributes;
3434
use OCP\Share\IManager;
3535
use OCP\Share\IShare;
36+
use OCP\Share\IShareProviderGetUsers;
3637
use OCP\Share\IShareProviderSupportsAccept;
3738
use OCP\Share\IShareProviderSupportsAllSharesInFolder;
3839
use OCP\Share\IShareProviderWithNotification;
@@ -44,7 +45,10 @@
4445
*
4546
* @package OC\Share20
4647
*/
47-
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept, IShareProviderSupportsAllSharesInFolder {
48+
class DefaultShareProvider implements IShareProviderWithNotification,
49+
IShareProviderSupportsAccept,
50+
IShareProviderSupportsAllSharesInFolder,
51+
IShareProviderGetUsers {
4852
public function __construct(
4953
private IDBConnection $dbConn,
5054
private IUserManager $userManager,
@@ -1678,4 +1682,15 @@ protected function formatShareAttributes(?IAttributes $attributes): ?string {
16781682
}
16791683
return \json_encode($compressedAttributes);
16801684
}
1685+
1686+
public function getUsersForShare(IShare $share): iterable {
1687+
if ($share->getShareType() === IShare::TYPE_USER) {
1688+
return [new LazyUser($share->getSharedWith(), $this->userManager)];
1689+
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
1690+
$group = $this->groupManager->get($share->getSharedWith());
1691+
return $group->getUsers();
1692+
} else {
1693+
return [];
1694+
}
1695+
}
16811696
}

lib/private/Share20/Manager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,4 +2097,13 @@ private function dispatchEvent(Event $event, string $name): void {
20972097
$this->logger->error("Error while sending ' . $name . ' event", ['exception' => $e]);
20982098
}
20992099
}
2100+
2101+
public function getUsersForShare(IShare $share): iterable {
2102+
$provider = $this->factory->getProviderForType($share->getShareType());
2103+
if ($provider instanceof Share\IShareProviderGetUsers) {
2104+
return $provider->getUsersForShare($share);
2105+
} else {
2106+
return [];
2107+
}
2108+
}
21002109
}

lib/public/Share/IManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,13 @@ public function getAllShares(): iterable;
559559
* @since 31.0.0
560560
*/
561561
public function generateToken(): string;
562+
563+
/**
564+
* Get all users with access to a share
565+
*
566+
* @param IShare $share
567+
* @return iterable<IUser>
568+
* @since 33.0.0
569+
*/
570+
public function getUsersForShare(IShare $share): iterable;
562571
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCP\Share;
8+
9+
use OCP\IUser;
10+
11+
/**
12+
* Interface IShareProviderSupportsAccept
13+
*
14+
* This interface allows to define IShareProvider that can list users for share with the getUsersForShare method,
15+
* which is available since Nextcloud 17.
16+
*
17+
* @since 33.0.0
18+
*/
19+
interface IShareProviderGetUsers extends IShareProvider {
20+
/**
21+
* Get all users with access to a share
22+
*
23+
* @param IShare $share
24+
* @return iterable<IUser>
25+
* @since 33.0.0
26+
*/
27+
public function getUsersForShare(IShare $share): iterable;
28+
}

0 commit comments

Comments
 (0)