Skip to content

Commit c614a13

Browse files
authored
Merge pull request #57158 from nextcloud/users-for-share
feat: add api to get users for share
2 parents 32327c6 + bbabf50 commit c614a13

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@
824824
'OCP\\Share\\IShare' => $baseDir . '/lib/public/Share/IShare.php',
825825
'OCP\\Share\\IShareHelper' => $baseDir . '/lib/public/Share/IShareHelper.php',
826826
'OCP\\Share\\IShareProvider' => $baseDir . '/lib/public/Share/IShareProvider.php',
827+
'OCP\\Share\\IShareProviderGetUsers' => $baseDir . '/lib/public/Share/IShareProviderGetUsers.php',
827828
'OCP\\Share\\IShareProviderSupportsAccept' => $baseDir . '/lib/public/Share/IShareProviderSupportsAccept.php',
828829
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => $baseDir . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
829830
'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
@@ -865,6 +865,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
865865
'OCP\\Share\\IShare' => __DIR__ . '/../../..' . '/lib/public/Share/IShare.php',
866866
'OCP\\Share\\IShareHelper' => __DIR__ . '/../../..' . '/lib/public/Share/IShareHelper.php',
867867
'OCP\\Share\\IShareProvider' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProvider.php',
868+
'OCP\\Share\\IShareProviderGetUsers' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderGetUsers.php',
868869
'OCP\\Share\\IShareProviderSupportsAccept' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAccept.php',
869870
'OCP\\Share\\IShareProviderSupportsAllSharesInFolder' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderSupportsAllSharesInFolder.php',
870871
'OCP\\Share\\IShareProviderWithNotification' => __DIR__ . '/../../..' . '/lib/public/Share/IShareProviderWithNotification.php',

lib/private/Share20/DefaultShareProvider.php

Lines changed: 17 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,11 @@
4445
*
4546
* @package OC\Share20
4647
*/
47-
class DefaultShareProvider implements IShareProviderWithNotification, IShareProviderSupportsAccept, IShareProviderSupportsAllSharesInFolder {
48+
class DefaultShareProvider implements
49+
IShareProviderWithNotification,
50+
IShareProviderSupportsAccept,
51+
IShareProviderSupportsAllSharesInFolder,
52+
IShareProviderGetUsers {
4853
public function __construct(
4954
private IDBConnection $dbConn,
5055
private IUserManager $userManager,
@@ -1678,4 +1683,15 @@ protected function formatShareAttributes(?IAttributes $attributes): ?string {
16781683
}
16791684
return \json_encode($compressedAttributes);
16801685
}
1686+
1687+
public function getUsersForShare(IShare $share): iterable {
1688+
if ($share->getShareType() === IShare::TYPE_USER) {
1689+
return [new LazyUser($share->getSharedWith(), $this->userManager)];
1690+
} elseif ($share->getShareType() === IShare::TYPE_GROUP) {
1691+
$group = $this->groupManager->get($share->getSharedWith());
1692+
return $group->getUsers();
1693+
} else {
1694+
return [];
1695+
}
1696+
}
16811697
}

lib/private/Share20/Manager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,4 +1881,13 @@ private function dispatchEvent(Event $event, string $name): void {
18811881
$this->logger->error("Error while sending ' . $name . ' event", ['exception' => $e]);
18821882
}
18831883
}
1884+
1885+
public function getUsersForShare(IShare $share): iterable {
1886+
$provider = $this->factory->getProviderForType($share->getShareType());
1887+
if ($provider instanceof Share\IShareProviderGetUsers) {
1888+
return $provider->getUsersForShare($share);
1889+
} else {
1890+
return [];
1891+
}
1892+
}
18841893
}

lib/public/Share/IManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,13 @@ public function getAllShares(): iterable;
518518
* @since 31.0.0
519519
*/
520520
public function generateToken(): string;
521+
522+
/**
523+
* Get all users with access to a share
524+
*
525+
* @param IShare $share
526+
* @return iterable<IUser>
527+
* @since 33.0.0
528+
*/
529+
public function getUsersForShare(IShare $share): iterable;
521530
}
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)