Extend data returned when searching remote shares

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2019-05-23 17:03:04 +02:00 committed by Daniel Calviño Sánchez
parent 3b8f83f5af
commit ea6f423e2c
5 changed files with 32 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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,
],
];
}

View File

@ -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,
],