Skip generated remote share is exact user match found

Whenever user ids are in the format "user@server", entering these in the share
dialog would also generate a remote share entry. Selecting the remote
entry would usually create a federated share to the same server.

In the case a user enters the full id address as share recipient it
is most likely that the intention was to share with the local user.

This fix removes the automatically generated remote id from the sharees
list when such situation occurs to avoid selecting the wrong entry by
mistake.
parent ada8879e
......@@ -334,7 +334,10 @@ class ShareesController extends OCSController {
$this->result['remotes'] = [];
}
if (!$foundRemoteById && substr_count($search, '@') >= 1 && $this->offset === 0) {
if (!$foundRemoteById && substr_count($search, '@') >= 1 && $this->offset === 0
// only add remote user if not found already an exact match (ex: local account like email address)
&& empty($this->result['exact']['users'])
) {
$this->result['exact']['remotes'][] = [
'label' => $search,
'value' => [
......
......@@ -1047,6 +1047,20 @@ class ShareesTest extends TestCase {
[],
true,
],
// if exact user found, skip generated remote entry
[
'test@domain.tld',
[],
true,
[],
[],
true,
[
'users' => [
['label' => 'test@domain.tld', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test@domain.tld']],
]
]
],
];
}
......@@ -1059,8 +1073,16 @@ class ShareesTest extends TestCase {
* @param array $exactExpected
* @param array $expected
* @param bool $reachedEnd
* @param array $previousExact
*/
public function testGetRemote($searchTerm, $contacts, $shareeEnumeration, $exactExpected, $expected, $reachedEnd) {
public function testGetRemote($searchTerm, $contacts, $shareeEnumeration, $exactExpected, $expected, $reachedEnd, $previousExact = []) {
// inject previous results if needed
if (!empty($previousExact)) {
$result = $this->invokePrivate($this->sharees, 'result');
$result['exact'] = array_merge($result['exact'], $previousExact);
$this->invokePrivate($this->sharees, 'result', [$result]);
}
$this->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]);
$this->contactsManager->expects($this->any())
->method('search')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment