From 6962f2f58390496f32c4d07634391c8bd2466e34 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 | 41 +++----- .../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 | 27 +++--- .../web-client/src/helpers/share/functions.ts | 27 +++--- .../src/helpers/share/functionsNG.ts | 93 +++++++++++++++++++ .../web-client/src/helpers/share/index.ts | 1 + .../web-client/src/helpers/share/types.ts | 5 + .../web-client/src/helpers/space/functions.ts | 9 +- .../components/FilesList/ResourceTable.vue | 68 +++++++++----- .../src/helpers/share/triggerShareAction.ts | 15 ++- 13 files changed, 221 insertions(+), 122 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..e5375483b93 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.shareOwner?.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..dd781dc703b 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,19 @@ 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 - }) - } + console.log('raw drive response', value) + + 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 +1057,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..0d0dafbc685 100644 --- a/packages/web-pkg/src/helpers/share/triggerShareAction.ts +++ b/packages/web-pkg/src/helpers/share/triggerShareAction.ts @@ -2,6 +2,7 @@ import { Resource, SpaceResource } from '@ownclouders/web-client/src' import { aggregateResourceShares, ShareStatus } from '@ownclouders/web-client/src/helpers/share' import { HttpError } from '@ownclouders/web-client/src/errors' import { OwnCloudSdk } from '@ownclouders/web-client/src/types' +import { ShareResource } from '@ownclouders/web-client/src/helpers' export async function triggerShareAction({ resource, @@ -13,7 +14,7 @@ export async function triggerShareAction({ spaces = [], fullShareOwnerPaths = false }: { - resource: Resource + resource: ShareResource status: ShareStatus hasResharing: boolean hasShareJail: boolean @@ -27,7 +28,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'}` } @@ -45,6 +46,16 @@ export async function triggerShareAction({ response = await response.json() if ((response as any).ocs.data.length > 0) { const share = (response as any).ocs.data[0] + // console.log( + // aggregateResourceShares({ + // shares: [share], + // spaces, + // incomingShares: true, + // allowSharePermission: hasResharing, + // hasShareJail, + // fullShareOwnerPaths + // })[0] + // ) return aggregateResourceShares({ shares: [share], spaces,