Skip to content

Commit

Permalink
Merge pull request #23017 from nextcloud/enh/distinguish-users
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Dec 14, 2020
2 parents 39bee79 + 8b13fd4 commit b56d7f9
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 28 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/files_sharing/js/dist/files_sharing_tab.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
$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()]);
Expand Down
5 changes: 4 additions & 1 deletion apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -402,6 +402,9 @@ export default {
p {
color: var(--color-text-maxcontrast);
}
&-unique {
color: var(--color-text-maxcontrast);
}
}
&__actions {
margin-left: auto;
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/src/components/SharingEntrySimple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default {
type: String,
default: '',
},
isUnique: {
type: Boolean,
default: true,
},
},
}
Expand Down
23 changes: 22 additions & 1 deletion apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,27 @@ export default {
// if there is a condition specified, filter it
const externalResults = this.externalResults.filter(result => !result.condition || result.condition(this))
this.suggestions = exactSuggestions.concat(suggestions).concat(externalResults).concat(lookupEntry)
const allSuggestions = exactSuggestions.concat(suggestions).concat(externalResults).concat(lookupEntry)
// Count occurances of display names in order to provide a distinguishable description if needed
const nameCounts = allSuggestions.reduce((nameCounts, result) => {
if (!result.displayName) {
return nameCounts
}
if (!nameCounts[result.displayName]) {
nameCounts[result.displayName] = 0
}
nameCounts[result.displayName]++
return nameCounts
}, {})
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.shareWithDisplayNameUnique }
}
return item
})
this.loading = false
console.info('suggestions', this.suggestions)
Expand Down Expand Up @@ -398,6 +418,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),
}
},
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default {
type: Share,
default: null,
},
isUnique: {
type: Boolean,
default: true,
},
},

data() {
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/src/models/Share.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions apps/files_sharing/src/views/SharingList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
:key="share.id"
:file-info="fileInfo"
:share="share"
:is-unique="isUnique(share)"
@remove:share="removeShare" />
</ul>
</template>
Expand All @@ -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',
Expand All @@ -42,6 +44,8 @@ export default {
SharingEntry,
},
mixins: [ShareTypes],
props: {
fileInfo: {
type: Object,
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ public function dataGetShare() {
'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',
Expand Down Expand Up @@ -782,6 +783,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$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');
Expand Down Expand Up @@ -3440,6 +3442,8 @@ public function dataFormatShare() {
$initiator->method('getDisplayName')->willReturn('initiatorDN');
$recipient = $this->getMockBuilder(IUser::class)->getMock();
$recipient->method('getDisplayName')->willReturn('recipientDN');
$recipient->method('getEmailAddress')->willReturn('recipient');


$result = [];

Expand Down Expand Up @@ -3479,6 +3483,7 @@ public function dataFormatShare() {
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipient',
'share_with_displayname_unique' => 'recipient',
'note' => 'personal note',
'label' => null,
'mail_send' => 0,
Expand Down Expand Up @@ -3516,6 +3521,7 @@ public function dataFormatShare() {
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipientDN',
'share_with_displayname_unique' => 'recipient',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
Expand Down Expand Up @@ -3567,6 +3573,7 @@ public function dataFormatShare() {
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipient',
'share_with_displayname_unique' => 'recipient',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
Expand Down Expand Up @@ -3614,6 +3621,7 @@ public function dataFormatShare() {
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipient',
'share_with_displayname_unique' => 'recipient',
'mail_send' => 0,
'mimetype' => 'myMimeType',
'has_preview' => false,
Expand Down Expand Up @@ -4162,6 +4170,7 @@ public function dataFormatShare() {
'file_target' => 'myTarget',
'share_with' => 'recipient',
'share_with_displayname' => 'recipient',
'share_with_displayname_unique' => 'recipient',
'mail_send' => 0,
'mimetype' => 'mimeWithPreview',
'has_preview' => true,
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $cloud->getUser(),
],
'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()

]];
$searchResult->addResultSet($userType, [], $singleResult);
$searchResult->markExactIdMatch($emailType);
Expand Down Expand Up @@ -170,6 +172,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $cloud->getUser(),
],
'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser()
];
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Collaboration/Collaborators/RemotePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'value' => [
'shareType' => IShare::TYPE_USER,
'shareWith' => $remoteUser
]
],
'shareWithDisplayNameUnique' => $contact['EMAIL'] !== null && $contact['EMAIL'] !== '' ? $contact['EMAIL'] : $contact['UID'],
];
}

Expand Down
5 changes: 5 additions & 0 deletions lib/private/Collaboration/Collaborators/UserPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
'shareWithDisplayNameUnique' => !empty($userEmail) ? $userEmail : $uid,
'status' => $status,
];
} else {
Expand All @@ -186,6 +187,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $uid,
],
'shareWithDisplayNameUnique' => !empty($userEmail) ? $userEmail : $uid,
'status' => $status,
];
}
Expand All @@ -207,6 +209,8 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {

if ($addUser) {
$status = [];
$uid = $user->getUID();
$userEmail = $user->getEMailAddress();
if (array_key_exists($user->getUID(), $userStatuses)) {
$userStatus = $userStatuses[$user->getUID()];
$status = [
Expand All @@ -227,6 +231,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
'shareType' => IShare::TYPE_USER,
'shareWith' => $user->getUID(),
],
'shareWithDisplayNameUnique' => $userEmail !== null && $userEmail !== '' ? $userEmail : $uid,
'status' => $status,
];
}
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/Collaboration/Collaborators/MailPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public function dataGetEmail() {
]
],
false,
['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'],]]]],
['users' => [], 'exact' => ['users' => [['uuid' => 'uid1', 'name' => 'User', 'label' => 'User (test@example.com)','value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test'], 'shareWithDisplayNameUnique' => 'test@example.com']]]],
true,
false,
],
Expand Down Expand Up @@ -443,8 +443,8 @@ public function dataGetEmail() {
],
true,
['users' => [
['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1']],
['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2']],
['uuid' => 'uid1', 'name' => 'User1', 'label' => 'User1 (test@example.com)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test1'], 'shareWithDisplayNameUnique' => 'test@example.com'],
['uuid' => 'uid2', 'name' => 'User2', 'label' => 'User2 (test@example.de)', 'value' => ['shareType' => IShare::TYPE_USER, 'shareWith' => 'test2'], 'shareWithDisplayNameUnique' => 'test@example.de'],
], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]],
false,
true,
Expand Down Expand Up @@ -603,7 +603,7 @@ public function dataGetEmailGroupsOnly() {
'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,
[
Expand Down
Loading

0 comments on commit b56d7f9

Please sign in to comment.