From 102402bfcbad8a0c1730b4d88172bcee28c50df7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julius=20H=C3=A4rtl?= <jus@bitgrid.net>
Date: Wed, 7 Oct 2020 12:32:16 +0200
Subject: [PATCH] Show unique displayname context in the user share list
 entries
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Julius Härtl <jus@bitgrid.net>
---
 .../lib/Controller/ShareAPIController.php             |  3 +++
 apps/files_sharing/src/components/SharingEntry.vue    |  5 ++++-
 .../src/components/SharingEntrySimple.vue             |  4 ++++
 apps/files_sharing/src/mixins/SharesMixin.js          |  4 ++++
 apps/files_sharing/src/models/Share.js                |  4 ++++
 apps/files_sharing/src/views/SharingList.vue          | 11 +++++++++++
 .../tests/Controller/ShareAPIControllerTest.php       |  9 +++++++++
 7 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 65de654be92..16b0e8fcc68 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -235,6 +235,9 @@ class ShareAPIController extends OCSController {
 			$sharedWith = $this->userManager->get($share->getSharedWith());
 			$result['share_with'] = $share->getSharedWith();
 			$result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith();
+			$result['share_with_displayname_unique'] = $sharedWith !== null ? (
+				 $sharedWith->getEMailAddress() !== '' ? $sharedWith->getEMailAddress() : $sharedWith->getUID()
+			) : $share->getSharedWith();
 			$result['status'] = [];
 
 			$userStatuses = $this->userStatusManager->getUserStatuses([$share->getSharedWith()]);
diff --git a/apps/files_sharing/src/components/SharingEntry.vue b/apps/files_sharing/src/components/SharingEntry.vue
index 407221037dc..c66dfc5c802 100644
--- a/apps/files_sharing/src/components/SharingEntry.vue
+++ b/apps/files_sharing/src/components/SharingEntry.vue
@@ -33,7 +33,7 @@
 			:href="share.shareWithLink"
 			v-tooltip.auto="tooltip"
 			class="sharing-entry__desc">
-			<h5>{{ title }}</h5>
+			<h5>{{ title }}<span v-if="!isUnique" class="sharing-entry__desc-unique"> ({{ share.shareWithDisplayNameUnique }})</span></h5>
 			<p v-if="hasStatus">
 				<span>{{ share.status.icon || '' }}</span>
 				<span>{{ share.status.message || '' }}</span>
@@ -402,6 +402,9 @@ export default {
 		p {
 			color: var(--color-text-maxcontrast);
 		}
+		&-unique {
+			color: var(--color-text-maxcontrast);
+		}
 	}
 	&__actions {
 		margin-left: auto;
diff --git a/apps/files_sharing/src/components/SharingEntrySimple.vue b/apps/files_sharing/src/components/SharingEntrySimple.vue
index 5cdce17bf0c..de545a497a8 100644
--- a/apps/files_sharing/src/components/SharingEntrySimple.vue
+++ b/apps/files_sharing/src/components/SharingEntrySimple.vue
@@ -64,6 +64,10 @@ export default {
 			type: String,
 			default: '',
 		},
+		isUnique: {
+			type: Boolean,
+			default: true,
+		},
 	},
 
 }
diff --git a/apps/files_sharing/src/mixins/SharesMixin.js b/apps/files_sharing/src/mixins/SharesMixin.js
index b35ebd8359e..aef543a5fc6 100644
--- a/apps/files_sharing/src/mixins/SharesMixin.js
+++ b/apps/files_sharing/src/mixins/SharesMixin.js
@@ -42,6 +42,10 @@ export default {
 			type: Share,
 			default: null,
 		},
+		isUnique: {
+			type: Boolean,
+			default: true,
+		},
 	},
 
 	data() {
diff --git a/apps/files_sharing/src/models/Share.js b/apps/files_sharing/src/models/Share.js
index d36484f064a..db9351fb52c 100644
--- a/apps/files_sharing/src/models/Share.js
+++ b/apps/files_sharing/src/models/Share.js
@@ -150,6 +150,10 @@ export default class Share {
 			|| this.#share.share_with
 	}
 
+	get shareWithDisplayNameUnique() {
+		return this.#share.share_with_displayname_unique || this.#share.share_with
+	}
+
 	/**
 	 * Get the share with entity link
 	 *
diff --git a/apps/files_sharing/src/views/SharingList.vue b/apps/files_sharing/src/views/SharingList.vue
index b8f12f6ef15..5c2a21c8bf8 100644
--- a/apps/files_sharing/src/views/SharingList.vue
+++ b/apps/files_sharing/src/views/SharingList.vue
@@ -26,6 +26,7 @@
 			:key="share.id"
 			:file-info="fileInfo"
 			:share="share"
+			:is-unique="isUnique(share)"
 			@remove:share="removeShare" />
 	</ul>
 </template>
@@ -34,6 +35,7 @@
 // eslint-disable-next-line no-unused-vars
 import Share from '../models/Share'
 import SharingEntry from '../components/SharingEntry'
+import ShareTypes from '../mixins/ShareTypes'
 
 export default {
 	name: 'SharingList',
@@ -42,6 +44,8 @@ export default {
 		SharingEntry,
 	},
 
+	mixins: [ShareTypes],
+
 	props: {
 		fileInfo: {
 			type: Object,
@@ -59,6 +63,13 @@ export default {
 		hasShares() {
 			return this.shares.length === 0
 		},
+		isUnique() {
+			return (share) => {
+				return [...this.shares].filter((item) => {
+					return share.type === this.SHARE_TYPES.SHARE_TYPE_USER && share.shareWithDisplayName === item.shareWithDisplayName
+				}).length <= 1
+			}
+		},
 	},
 
 	methods: {
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index a2a6ab59809..ff3429ca71c 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -583,6 +583,7 @@ class ShareAPIControllerTest extends TestCase {
 			'share_type' => IShare::TYPE_USER,
 			'share_with' => 'userId',
 			'share_with_displayname' => 'userDisplay',
+			'share_with_displayname_unique' => 'userId@example.com',
 			'uid_owner' => 'initiatorId',
 			'displayname_owner' => 'initiatorDisplay',
 			'item_type' => 'file',
@@ -782,6 +783,7 @@ class ShareAPIControllerTest extends TestCase {
 		$user = $this->getMockBuilder(IUser::class)->getMock();
 		$user->method('getUID')->willReturn('userId');
 		$user->method('getDisplayName')->willReturn('userDisplay');
+		$user->method('getEMailAddress')->willReturn('userId@example.com');
 
 		$group = $this->getMockBuilder('OCP\IGroup')->getMock();
 		$group->method('getGID')->willReturn('groupId');
@@ -3440,6 +3442,8 @@ class ShareAPIControllerTest extends TestCase {
 		$initiator->method('getDisplayName')->willReturn('initiatorDN');
 		$recipient = $this->getMockBuilder(IUser::class)->getMock();
 		$recipient->method('getDisplayName')->willReturn('recipientDN');
+		$recipient->method('getEmailAddress')->willReturn('recipient');
+
 
 		$result = [];
 
@@ -3479,6 +3483,7 @@ class ShareAPIControllerTest extends TestCase {
 				'file_target' => 'myTarget',
 				'share_with' => 'recipient',
 				'share_with_displayname' => 'recipient',
+				'share_with_displayname_unique' => 'recipient',
 				'note' => 'personal note',
 				'label' => null,
 				'mail_send' => 0,
@@ -3516,6 +3521,7 @@ class ShareAPIControllerTest extends TestCase {
 				'file_target' => 'myTarget',
 				'share_with' => 'recipient',
 				'share_with_displayname' => 'recipientDN',
+				'share_with_displayname_unique' => 'recipient',
 				'mail_send' => 0,
 				'mimetype' => 'myMimeType',
 				'has_preview' => false,
@@ -3567,6 +3573,7 @@ class ShareAPIControllerTest extends TestCase {
 				'file_target' => 'myTarget',
 				'share_with' => 'recipient',
 				'share_with_displayname' => 'recipient',
+				'share_with_displayname_unique' => 'recipient',
 				'mail_send' => 0,
 				'mimetype' => 'myMimeType',
 				'has_preview' => false,
@@ -3614,6 +3621,7 @@ class ShareAPIControllerTest extends TestCase {
 				'file_target' => 'myTarget',
 				'share_with' => 'recipient',
 				'share_with_displayname' => 'recipient',
+				'share_with_displayname_unique' => 'recipient',
 				'mail_send' => 0,
 				'mimetype' => 'myMimeType',
 				'has_preview' => false,
@@ -4162,6 +4170,7 @@ class ShareAPIControllerTest extends TestCase {
 				'file_target' => 'myTarget',
 				'share_with' => 'recipient',
 				'share_with_displayname' => 'recipient',
+				'share_with_displayname_unique' => 'recipient',
 				'mail_send' => 0,
 				'mimetype' => 'mimeWithPreview',
 				'has_preview' => true,
-- 
GitLab