From 69ede350b8128400a5d9b660b927ece7f042f44f Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Thu, 5 Mar 2020 14:39:24 +0100 Subject: [PATCH] Sort collaborators by type, direct, name, creation time Adjusted order of collaborators --- .../src/components/FileSharingSidebar.vue | 52 +++++++++---------- .../shareWithGroups.feature | 2 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/apps/files/src/components/FileSharingSidebar.vue b/apps/files/src/components/FileSharingSidebar.vue index c4cf9af86ea..f172248d8f4 100644 --- a/apps/files/src/components/FileSharingSidebar.vue +++ b/apps/files/src/components/FileSharingSidebar.vue @@ -22,7 +22,7 @@ -
+
-
  • +
  • -
    -
    -
    -
      -
    • - -
    • -
    @@ -175,7 +167,7 @@ export default { }) // make them unique then sort - ownerAsCollaborator.resharers = Array.from(resharers.values()).sort(this.$_collaboratorsComparator.bind(this)) + ownerAsCollaborator.resharers = Array.from(resharers.values()).sort(this.collaboratorsComparator.bind(this)) return ownerAsCollaborator }, @@ -211,10 +203,9 @@ export default { return allShares }, - $_directOutgoingShares () { - // direct outgoing shares - return [...this.currentFileOutgoingCollaborators] - .sort(this.$_collaboratorsComparator) + collaborators () { + return [...this.currentFileOutgoingCollaborators, ...this.$_indirectOutgoingShares] + .sort(this.collaboratorsComparator) .map(collaborator => { collaborator.key = 'collaborator-' + collaborator.id if (collaborator.owner.name !== collaborator.fileOwner.name && collaborator.owner.name !== this.user.id) { @@ -294,25 +285,30 @@ export default { $_isCollaboratorShare (collaborator) { return userShareTypes.includes(collaborator.shareType) }, - $_collaboratorsComparator (c1, c2) { - // resharer entries have displayName on first level, - // but shares/collaborators have it under the collaborator attribute + collaboratorsComparator (c1, c2) { + // Sorted by: type, direct, display name, creation date const c1DisplayName = c1.collaborator ? c1.collaborator.displayName : c1.displayName const c2DisplayName = c2.collaborator ? c2.collaborator.displayName : c2.displayName const name1 = c1DisplayName.toLowerCase().trim() const name2 = c2DisplayName.toLowerCase().trim() - // sorting priority 1: display name (lower case, ascending), 2: share type (groups first), 3: id (ascending) - if (name1 === name2) { - const c1GroupShare = c1.shareType === shareTypes.group - const c2GroupShare = c2.shareType === shareTypes.group - if (c1GroupShare === c2GroupShare) { - return textUtils.naturalSortCompare(c1.id + '', c2.id + '') - } else { - return c1GroupShare ? -1 : 1 + const c1UserShare = c1.shareType === shareTypes.user || c1.shareType === shareTypes.remote + const c2UserShare = c2.shareType === shareTypes.user || c1.shareType === shareTypes.remote + const c1DirectShare = !c1.outgoing + const c2DirectShare = !c2.outgoing + + if (c1UserShare === c2UserShare) { + if (c1DirectShare === c2DirectShare) { + if (name1 === name2) { + return textUtils.naturalSortCompare(c1.stime + '', c2.stime + '') + } + + return textUtils.naturalSortCompare(name1, name2) } - } else { - return textUtils.naturalSortCompare(name1, name2) + + return c1DirectShare ? -1 : 1 } + + return c1UserShare ? -1 : 1 }, $_ocCollaborators_addShare () { this.transitionGroupActive = true diff --git a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature index 88289b8bd23..f1a90dd879a 100644 --- a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature +++ b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature @@ -22,7 +22,7 @@ Feature: Sharing files and folders with internal groups And the user shares folder "simple-folder" with user "User Two" as "Viewer" using the webUI And the user shares folder "simple-folder" with group "grp1" as "Viewer" using the webUI And the user shares folder "simple-folder" with user "User One" as "Viewer" using the webUI - Then the current collaborators list should have order "User Three,grp1,grp11,User One,User Two" + Then the current collaborators list should have order "User Three,User One,User Two,grp1,grp11" Scenario Outline: share a file & folder with another internal user Given user "user3" has logged in using the webUI