From 68a0639450489bc4eb4034349c13e950d896bb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 7 Oct 2020 12:31:30 +0200 Subject: [PATCH] Show unique displayname context in the sharing input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../src/components/SharingInput.vue | 3 +- .../Collaborators/MailPlugin.php | 3 ++ .../Collaborators/RemotePlugin.php | 3 +- .../Collaborators/UserPlugin.php | 5 +++ .../Collaborators/MailPluginTest.php | 8 ++--- .../Collaborators/UserPluginTest.php | 34 +++++++++---------- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/apps/files_sharing/src/components/SharingInput.vue b/apps/files_sharing/src/components/SharingInput.vue index 1b2c3ad4ce4..6de6bf74cd5 100644 --- a/apps/files_sharing/src/components/SharingInput.vue +++ b/apps/files_sharing/src/components/SharingInput.vue @@ -257,7 +257,7 @@ export default { this.suggestions = allSuggestions.map(item => { // Make sure that items with duplicate displayName get the shareWith applied as a description if (nameCounts[item.displayName] > 1 && !item.desc) { - return { ...item, desc: item.shareWith } + return { ...item, desc: item.shareWithDisplayNameUnique } } return item }) @@ -413,6 +413,7 @@ export default { isNoUser: result.value.shareType !== this.SHARE_TYPES.SHARE_TYPE_USER, displayName: result.name || result.label, desc, + shareWithDisplayNameUnique: result.shareWithDisplayNameUnique || '', icon: this.shareTypeToIcon(result.value.shareType), } }, diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index d5ee407b82f..8e7220329a9 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -135,6 +135,8 @@ class MailPlugin implements ISearchPlugin { 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $cloud->getUser(), ], + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() + ]]; $searchResult->addResultSet($userType, [], $singleResult); $searchResult->markExactIdMatch($emailType); @@ -158,6 +160,7 @@ class MailPlugin implements ISearchPlugin { 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $cloud->getUser(), ], + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() ]; } } diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index 5cbecf5385b..a0e2502acd6 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -103,7 +103,8 @@ class RemotePlugin implements ISearchPlugin { 'value' => [ 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $remoteUser - ] + ], + 'shareWithDisplayNameUnique' => $contact['EMAIL'] !== null && $contact['EMAIL'] !== '' ? $contact['EMAIL'] : $contact['UID'], ]; } diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 1d6e0fc0c06..9c6618cac08 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -114,6 +114,7 @@ class UserPlugin implements ISearchPlugin { 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid, ], + 'shareWithDisplayNameUnique' => !empty($userEmail) ? $userEmail : $uid, ]; } else { $result['wide'][] = [ @@ -122,6 +123,7 @@ class UserPlugin implements ISearchPlugin { 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $uid, ], + 'shareWithDisplayNameUnique' => !empty($userEmail) ? $userEmail : $uid, ]; } } @@ -140,12 +142,15 @@ class UserPlugin implements ISearchPlugin { } if ($addUser) { + $uid = $user->getUID(); + $userEmail = $user->getEMailAddress(); $result['exact'][] = [ 'label' => $user->getDisplayName(), 'value' => [ 'shareType' => Share::SHARE_TYPE_USER, 'shareWith' => $user->getUID(), ], + 'shareWithDisplayNameUnique' => $userEmail !== null && $userEmail !== '' ? $userEmail : $uid, ]; } } diff --git a/tests/lib/Collaboration/Collaborators/MailPluginTest.php b/tests/lib/Collaboration/Collaborators/MailPluginTest.php index 9cf308cd414..c3cccc3c377 100644 --- a/tests/lib/Collaboration/Collaborators/MailPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/MailPluginTest.php @@ -383,7 +383,7 @@ class MailPluginTest extends TestCase { ] ], false, - ['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'],]]]], + ['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test@example.com']]]], true, false, ], @@ -441,8 +441,8 @@ class MailPluginTest extends TestCase { ], true, ['users' => [ - ['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], - ['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test@example.com'], + ['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test@example.de'], ], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]], false, true, @@ -597,7 +597,7 @@ class MailPluginTest extends TestCase { 'UID' => 'User' ] ], - ['users' => [['label' => 'User (test@example.com)', 'uuid' => 'User', 'name' => 'User', 'value' => ['shareType' => 0, 'shareWith' => 'test'],]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]], + ['users' => [['label' => 'User (test@example.com)', 'uuid' => 'User', 'name' => 'User', 'value' => ['shareType' => 0, 'shareWith' => 'test'],'shareWithDisplayNameUnique' => 'test@example.com',]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]], false, false, [ diff --git a/tests/lib/Collaboration/Collaborators/UserPluginTest.php b/tests/lib/Collaboration/Collaborators/UserPluginTest.php index c73277c946b..8e297d4d351 100644 --- a/tests/lib/Collaboration/Collaborators/UserPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/UserPluginTest.php @@ -127,13 +127,13 @@ class UserPluginTest extends TestCase { [ 'test', false, true, [], [], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [], true, $this->getUserMock('test', 'Test'), ], [ 'test', false, false, [], [], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [], true, $this->getUserMock('test', 'Test'), ], [ @@ -147,13 +147,13 @@ class UserPluginTest extends TestCase { [ 'test', true, true, ['test-group'], [['test-group', 'test', 2, 0, []]], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [], true, $this->getUserMock('test', 'Test'), ], [ 'test', true, false, ['test-group'], [['test-group', 'test', 2, 0, []]], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [], true, $this->getUserMock('test', 'Test'), ], [ @@ -166,7 +166,7 @@ class UserPluginTest extends TestCase { ], [], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test1'], ], true, false, @@ -195,8 +195,8 @@ class UserPluginTest extends TestCase { ], [], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], - ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test1'], + ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test2'], ], false, false, @@ -226,11 +226,11 @@ class UserPluginTest extends TestCase { $this->getUserMock('test2', 'Test Two'), ], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0'], 'shareWithDisplayNameUnique' => 'test0'], ], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], - ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test1'], + ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test2'], ], false, false, @@ -246,7 +246,7 @@ class UserPluginTest extends TestCase { $this->getUserMock('test2', 'Test Two'), ], [ - ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0']], + ['label' => 'Test', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test0'], 'shareWithDisplayNameUnique' => 'test0'], ], [], true, @@ -263,7 +263,7 @@ class UserPluginTest extends TestCase { ], [], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test1'], ], true, false, @@ -301,8 +301,8 @@ class UserPluginTest extends TestCase { ], [], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']], - ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test1'], + ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test2'], ], false, false, @@ -349,10 +349,10 @@ class UserPluginTest extends TestCase { ]], ], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [ - ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']], + ['label' => 'Test Two', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test2'], ], false, false, @@ -375,7 +375,7 @@ class UserPluginTest extends TestCase { ]], ], [ - ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test']], + ['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test'], ], [], true,