From ea6f423e2c8e50cf1357a0e2182dc4c9a9bf981e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Thu, 23 May 2019 17:03:04 +0200 Subject: [PATCH] Extend data returned when searching remote shares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .../sharees_features/sharees.feature | 2 +- .../sharees_provisioningapiv2.feature | 2 +- .../Collaborators/RemoteGroupPlugin.php | 22 ++++++++++++++++++- .../Collaborators/RemotePlugin.php | 5 ++++- .../Collaborators/RemotePluginTest.php | 10 ++++----- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build/integration/sharees_features/sharees.feature b/build/integration/sharees_features/sharees.feature index 58570cfc5f..5a6291d1e2 100644 --- a/build/integration/sharees_features/sharees.feature +++ b/build/integration/sharees_features/sharees.feature @@ -206,7 +206,7 @@ Feature: sharees Then "exact groups" sharees returned is empty Then "groups" sharees returned is empty Then "exact remotes" sharees returned are - | test@localhost | 6 | test@localhost | + | test (localhost) | 6 | test@localhost | Then "remotes" sharees returned is empty Scenario: Remote sharee for calendars not allowed diff --git a/build/integration/sharees_features/sharees_provisioningapiv2.feature b/build/integration/sharees_features/sharees_provisioningapiv2.feature index 37ab896ee2..6f2b8df8e0 100644 --- a/build/integration/sharees_features/sharees_provisioningapiv2.feature +++ b/build/integration/sharees_features/sharees_provisioningapiv2.feature @@ -206,7 +206,7 @@ Feature: sharees_provisioningapiv2 Then "exact groups" sharees returned is empty Then "groups" sharees returned is empty Then "exact remotes" sharees returned are - | test@localhost | 6 | test@localhost | + | test (localhost) | 6 | test@localhost | Then "remotes" sharees returned is empty Scenario: Remote sharee for calendars not allowed diff --git a/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php b/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php index 6e0979fe41..d9e1f2fd49 100644 --- a/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php +++ b/lib/private/Collaboration/Collaborators/RemoteGroupPlugin.php @@ -57,11 +57,15 @@ class RemoteGroupPlugin implements ISearchPlugin { $resultType = new SearchResultType('remote_groups'); if ($this->enabled && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) { + list($remoteGroup, $serverUrl) = $this->splitGroupRemote($search); $result['exact'][] = [ - 'label' => $search, + 'label' => $remoteGroup . " ($serverUrl)", + 'guid' => $remoteGroup, + 'name' => $remoteGroup, 'value' => [ 'shareType' => Share::SHARE_TYPE_REMOTE_GROUP, 'shareWith' => $search, + 'server' => $serverUrl, ], ]; } @@ -71,4 +75,20 @@ class RemoteGroupPlugin implements ISearchPlugin { return true; } + /** + * split group and remote from federated cloud id + * + * @param string $address federated share address + * @return array [user, remoteURL] + * @throws \InvalidArgumentException + */ + public function splitGroupRemote($address) { + try { + $cloudId = $this->cloudIdManager->resolveCloudId($address); + return [$cloudId->getUser(), $cloudId->getRemote()]; + } catch (\InvalidArgumentException $e) { + throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e); + } + } + } diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index d877346b15..fd14e7e03b 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -152,10 +152,13 @@ class RemotePlugin implements ISearchPlugin { $localUser = $this->userManager->get($remoteUser); if ($localUser === null || $search !== $localUser->getCloudId()) { $result['exact'][] = [ - 'label' => $search, + 'label' => $remoteUser . " ($serverUrl)", + 'uuid' => $remoteUser, + 'name' => $remoteUser, 'value' => [ 'shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $search, + 'server' => $serverUrl, ], ]; } diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index aff6818576..560e72a984 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -152,7 +152,7 @@ class RemotePluginTest extends TestCase { 'test@remote', [], true, - ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]], + ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], false, true, ], @@ -160,7 +160,7 @@ class RemotePluginTest extends TestCase { 'test@remote', [], false, - ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]], + ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], false, true, ], @@ -238,7 +238,7 @@ class RemotePluginTest extends TestCase { ], ], true, - ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]], + ['remotes' => [['name' => 'User @ Localhost', 'label' => 'User @ Localhost (username@localhost)', 'uuid' => 'uid', 'type' => '', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'username@localhost', 'server' => 'localhost']]], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], false, true, ], @@ -264,7 +264,7 @@ class RemotePluginTest extends TestCase { ], ], false, - ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote']]]]], + ['remotes' => [], 'exact' => ['remotes' => [['label' => 'test (remote)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'test@remote', 'server' => 'remote'], 'uuid' => 'test', 'name' => 'test']]]], false, true, ], @@ -370,7 +370,7 @@ class RemotePluginTest extends TestCase { ], ], false, - ['remotes' => [], 'exact' => ['remotes' => [['label' => 'user space@remote', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user space@remote']]]]], + ['remotes' => [], 'exact' => ['remotes' => [['label' => 'user space (remote)', 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => 'user space@remote', 'server' => 'remote'], 'uuid' => 'user space', 'name' => 'user space']]]], false, true, ],