diff options
author | Björn Schießle <bjoern@schiessle.org> | 2018-10-15 12:14:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 12:14:04 +0200 |
commit | 1ce86722763ac2c3aa299de67955005024e3ee5c (patch) | |
tree | 69dffde7e883f08d35b78d361855db416c06f685 /lib | |
parent | 8177fdb0f67a7fdfc86c27b3995afd9e5adfdce8 (diff) | |
parent | 1b0b15968500fa1a5e67f872183e41134e16236d (diff) | |
download | nextcloud-server-1ce86722763ac2c3aa299de67955005024e3ee5c.tar.gz nextcloud-server-1ce86722763ac2c3aa299de67955005024e3ee5c.zip |
Merge pull request #11714 from nextcloud/lookupserver-and-global-scale
always query the lookup server in a global scale setup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Collaboration/Collaborators/LookupPlugin.php | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php index 3a6a0943772..ae5f7fd0cbc 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -27,8 +27,11 @@ namespace OC\Collaboration\Collaborators; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; +use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\ILogger; +use OCP\IUserSession; use OCP\Share; class LookupPlugin implements ISearchPlugin { @@ -37,14 +40,31 @@ class LookupPlugin implements ISearchPlugin { private $config; /** @var IClientService */ private $clientService; + /** @var string remote part of the current user's cloud id */ + private $currentUserRemote; + /** @var ICloudIdManager */ + private $cloudIdManager; + /** @var ILogger */ + private $logger; - public function __construct(IConfig $config, IClientService $clientService) { + public function __construct(IConfig $config, + IClientService $clientService, + IUserSession $userSession, + ICloudIdManager $cloudIdManager, + ILogger $logger) { $this->config = $config; $this->clientService = $clientService; + $this->cloudIdManager = $cloudIdManager; + $currentUserCloudId = $userSession->getUser()->getCloudId(); + $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); + $this->logger = $logger; } public function search($search, $limit, $offset, ISearchResult $searchResult) { - if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') { + $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); + $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes'; + // if case of Global Scale we always search the lookup server + if (!$isLookupServerEnabled && !$isGlobalScaleEnabled) { return false; } @@ -65,8 +85,20 @@ class LookupPlugin implements ISearchPlugin { $body = json_decode($response->getBody(), true); foreach ($body as $lookup) { + try { + $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); + } catch (\Exception $e) { + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"'); + $this->logger->error($e->getMessage()); + continue; + } + if ($this->currentUserRemote === $remote) { + continue; + } + $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; + $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; $result[] = [ - 'label' => $lookup['federationId'], + 'label' => $label, 'value' => [ 'shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $lookup['federationId'], |