diff options
author | Joas Schilling <coding@schilljs.com> | 2021-11-05 10:44:51 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-11-09 10:10:53 +0100 |
commit | fa036b2001e0505006b6f9fe24d3fc56af937b06 (patch) | |
tree | 7d102e103cf131ccf3ec8d5650b6a3de13e835e6 /lib | |
parent | f4307ef4b16ffa1ea5a9e4697b57be36660a7953 (diff) | |
download | nextcloud-server-fa036b2001e0505006b6f9fe24d3fc56af937b06.tar.gz nextcloud-server-fa036b2001e0505006b6f9fe24d3fc56af937b06.zip |
Move common logic to share manager
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Server.php | 3 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 44 | ||||
-rw-r--r-- | lib/public/Share/IManager.php | 11 |
3 files changed, 56 insertions, 2 deletions
diff --git a/lib/private/Server.php b/lib/private/Server.php index 635bd80d4f8..baebbe7558d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1253,7 +1253,8 @@ class Server extends ServerContainer implements IServerContainer { $c->get(IURLGenerator::class), $c->get('ThemingDefaults'), $c->get(IEventDispatcher::class), - $c->get(IUserSession::class) + $c->get(IUserSession::class), + $c->get(KnownUserService::class) ); return $manager; diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index ccc2d454a94..1891e3a1283 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -43,6 +43,7 @@ namespace OC\Share20; use OC\Cache\CappedMemoryCache; use OC\Files\Mount\MoveableMount; +use OC\KnownUser\KnownUserService; use OC\Share20\Exception\ProviderException; use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Sharing\ISharedStorage; @@ -118,7 +119,10 @@ class Manager implements IManager { private $defaults; /** @var IEventDispatcher */ private $dispatcher; + /** @var IUserSession */ private $userSession; + /** @var KnownUserService */ + private $knownUserService; public function __construct( ILogger $logger, @@ -137,7 +141,8 @@ class Manager implements IManager { IURLGenerator $urlGenerator, \OC_Defaults $defaults, IEventDispatcher $dispatcher, - IUserSession $userSession + IUserSession $userSession, + KnownUserService $knownUserService ) { $this->logger = $logger; $this->config = $config; @@ -160,6 +165,7 @@ class Manager implements IManager { $this->defaults = $defaults; $this->dispatcher = $dispatcher; $this->userSession = $userSession; + $this->knownUserService = $knownUserService; } /** @@ -1909,6 +1915,42 @@ class Manager implements IManager { return $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; } + public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool { + if ($this->allowEnumerationFullMatch()) { + return true; + } + + if (!$this->allowEnumeration()) { + return false; + } + + if (!$this->limitEnumerationToPhone() && !$this->limitEnumerationToGroups()) { + // Enumeration is enabled and not restricted: OK + return true; + } + + if (!$currentUser instanceof IUser) { + // Enumeration restrictions require an account + return false; + } + + // Enumeration is limited to phone match + if ($this->limitEnumerationToPhone() && $this->knownUserService->isKnownToUser($currentUser->getUID(), $targetUser->getUID())) { + return true; + } + + // Enumeration is limited to groups + if ($this->limitEnumerationToGroups()) { + $currentUserGroupIds = $this->groupManager->getUserGroupIds($currentUser); + $targetUserGroupIds = $this->groupManager->getUserGroupIds($targetUser); + if (!empty(array_intersect($currentUserGroupIds, $targetUserGroupIds))) { + return true; + } + } + + return false; + } + /** * Copied from \OC_Util::isSharingDisabledForUser * diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 77a9980a894..8b1f5144b9a 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -32,6 +32,7 @@ namespace OCP\Share; use OCP\Files\Folder; use OCP\Files\Node; +use OCP\IUser; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; @@ -448,6 +449,16 @@ interface IManager { public function allowEnumerationFullMatch(): bool; /** + * Check if the current user can enumerate the target user + * + * @param IUser|null $currentUser + * @param IUser $targetUser + * @return bool + * @since 23.0.0 + */ + public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $targetUser): bool; + + /** * Check if sharing is disabled for the given user * * @param string $userId |