From 65ce1b0ddc5da197084270c6c4d7c61b8755b585 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 22 Jan 2024 13:34:42 +0100 Subject: [PATCH] refactor: use sharing NG for the shared views --- .../SideBar/Details/FileDetails.vue | 20 +---- .../src/services/folder/loaderSharedWithMe.ts | 39 +++------- .../src/views/shares/SharedWithMe.vue | 21 +++-- packages/web-client/src/graph.ts | 9 ++- .../src/helpers/resource/functions.ts | 7 +- .../web-client/src/helpers/resource/types.ts | 31 +++----- .../web-client/src/helpers/share/functions.ts | 27 +++---- .../src/helpers/share/functionsNG.ts | 78 +++++++++++++++++++ .../web-client/src/helpers/share/index.ts | 1 + .../web-client/src/helpers/share/types.ts | 5 ++ .../web-client/src/helpers/space/functions.ts | 6 +- .../components/FilesList/ResourceTable.vue | 65 ++++++++++------ .../src/helpers/share/triggerShareAction.ts | 2 +- 13 files changed, 186 insertions(+), 125 deletions(-) create mode 100644 packages/web-client/src/helpers/share/functionsNG.ts create mode 100644 packages/web-client/src/helpers/share/types.ts diff --git a/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue b/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue index 526f4fc7ef2..146c86142b5 100644 --- a/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue +++ b/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue @@ -74,9 +74,6 @@

{{ ownerDisplayName }} (me) - ({{ ownerAdditionalInfo }})

@@ -326,14 +323,7 @@ export default defineComponent({ return this.resource.mdate?.length > 0 }, ownerDisplayName() { - return ( - this.resource.ownerDisplayName || - this.resource.shareOwnerDisplayname || - this.resource.owner?.[0].displayName - ) - }, - ownerAdditionalInfo() { - return this.resource.owner?.[0].additionalInfo + return this.resource.owner?.displayName }, resourceSize() { return formatFileSize(this.resource.size, this.$language.current) @@ -362,17 +352,13 @@ export default defineComponent({ ) }, ownedByCurrentUser() { - return ( - this.resource.ownerId === this.user?.onPremisesSamAccountName || - this.resource.owner?.[0].username === this.user?.onPremisesSamAccountName || - this.resource.shareOwner === this.user?.onPremisesSamAccountName - ) + return this.resource.owner?.id === this.user?.onPremisesSamAccountName }, shareIndicators() { return getIndicators({ resource: this.resource, ancestorMetaData: this.ancestorMetaData }) }, sharedByDisplayName() { - return this.resource.share?.fileOwner?.displayName + return this.resource.sharedBy?.displayName } }, methods: { diff --git a/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts b/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts index 8ee2231cf07..13164ca794d 100644 --- a/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts +++ b/packages/web-app-files/src/services/folder/loaderSharedWithMe.ts @@ -1,7 +1,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder' import { Router } from 'vue-router' import { useTask } from 'vue-concurrency' -import { aggregateResourceShares } from '@ownclouders/web-client/src/helpers/share' +import { aggregateResourceShares } from '@ownclouders/web-client/src/helpers/share/functionsNG' import { isLocationSharesActive } from '@ownclouders/web-pkg' export class FolderLoaderSharedWithMe implements FolderLoader { @@ -14,8 +14,7 @@ export class FolderLoaderSharedWithMe implements FolderLoader { } public getTask(context: TaskContext): FolderLoaderTask { - const { userStore, spacesStore, clientService, configStore, capabilityStore, resourcesStore } = - context + const { spacesStore, clientService, configStore, capabilityStore, resourcesStore } = context // eslint-disable-next-line @typescript-eslint/no-unused-vars return useTask(function* (signal1, signal2) { @@ -26,31 +25,17 @@ export class FolderLoaderSharedWithMe implements FolderLoader { yield spacesStore.loadMountPoints({ graphClient: clientService.graphAuthenticated }) } - let resources = yield clientService.owncloudSdk.shares.getShares('', { - state: 'all', - include_tags: false, - shared_with_me: true, - show_hidden: true - }) + const { + data: { value } + } = yield clientService.graphAuthenticated.drives.listSharedWithMe() - resources = resources.map((r) => r.shareInfo) - - if (resources.length) { - resources = aggregateResourceShares({ - shares: resources, - spaces: spacesStore.spaces, - incomingShares: true, - allowSharePermission: capabilityStore.sharingResharing, - hasShareJail: capabilityStore.spacesShareJail, - fullShareOwnerPaths: configStore.options.routing.fullShareOwnerPaths - }).map((resource) => { - // info: in oc10 we have no storageId in resources. All resources are mounted into the personal space. - if (!resource.storageId) { - resource.storageId = userStore.user.onPremisesSamAccountName - } - return resource - }) - } + const resources = aggregateResourceShares({ + driveItems: value, + spaces: spacesStore.spaces, + incomingShares: true, + allowSharePermission: capabilityStore.sharingResharing, + fullShareOwnerPaths: configStore.options.routing.fullShareOwnerPaths + }) resourcesStore.initResourceList({ currentFolder: null, resources }) }) diff --git a/packages/web-app-files/src/views/shares/SharedWithMe.vue b/packages/web-app-files/src/views/shares/SharedWithMe.vue index 4cf16c774f0..3fb1591d168 100644 --- a/packages/web-app-files/src/views/shares/SharedWithMe.vue +++ b/packages/web-app-files/src/views/shares/SharedWithMe.vue @@ -45,13 +45,13 @@ :items="fileOwners" :option-filter-label="$gettext('Filter shared by')" :show-option-filter="true" - id-attribute="username" + id-attribute="id" class="shared-by-filter oc-ml-s" display-name-attribute="displayName" filter-name="sharedBy" > @@ -187,7 +187,7 @@ !u.link).length - const linkCount = resource.sharedWith.filter((u) => !!u.link).length + + const count = resource.sharedWith.length + + if (resource.shareType === ShareTypes.link.value) { + const linkText = + count > 0 + ? this.$ngettext( + 'This %{ resourceType } is shared via %{ count } link', + 'This %{ resourceType } is shared via %{ count } links', + count + ) + : '' + + return this.$gettext(linkText, { + resourceType, + count: count.toString() + }) + } + const shareText = - shareCount > 0 + count > 0 ? this.$ngettext( - 'This %{ resourceType } is shared via %{ shareCount } invite', - 'This %{ resourceType } is shared via %{ shareCount } invites', - shareCount + 'This %{ resourceType } is shared via %{ count } invite', + 'This %{ resourceType } is shared via %{ count } invites', + count ) : '' - const linkText = - linkCount > 0 - ? this.$ngettext( - 'This %{ resourceType } is shared via %{ linkCount } link', - 'This %{ resourceType } is shared via %{ linkCount } links', - linkCount - ) - : '' - const description = [shareText, linkText].join(' ') - return this.$gettext(description, { + + return this.$gettext(shareText, { resourceType, - shareCount, - linkCount + count: count.toString() }) }, getOwnerAvatarDescription(resource: Resource) { @@ -1047,8 +1056,16 @@ export default defineComponent({ resource.type === 'folder' ? this.$gettext('folder') : this.$gettext('file') return this.$gettext('This %{ resourceType } is owned by %{ ownerName }', { resourceType, - ownerName: resource.owner[0].displayName + ownerName: resource.owner.displayName }) + }, + getSharedWithItems(resource: Resource) { + return resource.sharedWith.map((s) => ({ + displayName: s.displayName, + name: s.displayName, + shareType: resource.shareType, + username: s.id + })) } } }) diff --git a/packages/web-pkg/src/helpers/share/triggerShareAction.ts b/packages/web-pkg/src/helpers/share/triggerShareAction.ts index 9eb33b7a18d..3a08e5dffdd 100644 --- a/packages/web-pkg/src/helpers/share/triggerShareAction.ts +++ b/packages/web-pkg/src/helpers/share/triggerShareAction.ts @@ -27,7 +27,7 @@ export async function triggerShareAction({ throw new Error('invalid new share status') } - let action = `api/v1/shares/pending/${resource.share.id}` + let action = `api/v1/shares/pending/${resource.shareId}` if (hidden !== undefined) { action += `?hidden=${hidden ? 'true' : 'false'}` }