Skip to content

Commit

Permalink
refactor: use sharing NG for the shared views
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Jan 23, 2024
1 parent 09584db commit 6962f2f
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@
<p class="oc-m-rm">
{{ ownerDisplayName }}
<span v-if="ownedByCurrentUser" v-translate>(me)</span>
<span v-if="!ownedByCurrentUser && ownerAdditionalInfo"
>({{ ownerAdditionalInfo }})</span
>
</p>
</td>
</tr>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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: {
Expand Down
41 changes: 14 additions & 27 deletions packages/web-app-files/src/services/folder/loaderSharedWithMe.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand All @@ -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 })
})
Expand Down
21 changes: 9 additions & 12 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<template #image="{ item }">
<avatar-image :width="32" :userid="item.username" :user-name="item.displayName" />
<avatar-image :width="32" :userid="item.id" :user-name="item.displayName" />
</template>
<template #item="{ item }">
<span class="oc-ml-s" v-text="item.displayName" />
Expand Down Expand Up @@ -109,7 +109,6 @@ import { AppBar, ItemFilterInline } from '@ownclouders/web-pkg'
import { queryItemAsString, useRouteQuery } from '@ownclouders/web-pkg'
import SharedWithMeSection from '../../components/Shares/SharedWithMeSection.vue'
import { computed, defineComponent, onMounted, ref, unref, watch } from 'vue'
import { Resource } from '@ownclouders/web-client'
import FilesViewWrapper from '../../components/FilesViewWrapper.vue'
import { useGetMatchingSpace, useSort } from '@ownclouders/web-pkg'
import { useGroupingSettings } from '@ownclouders/web-pkg'
Expand Down Expand Up @@ -147,7 +146,7 @@ export default defineComponent({
isSideBarOpen,
storeItems,
scrollToResourceFromRoute
} = useResourcesViewDefaults<Resource, any, any[]>()
} = useResourcesViewDefaults()
const { $gettext } = useGettext()
Expand Down Expand Up @@ -182,16 +181,14 @@ export default defineComponent({
const selectedShareTypes = queryItemAsString(unref(selectedShareTypesQuery))?.split('+')
if (selectedShareTypes?.length) {
result = result.filter(({ share }) => {
return selectedShareTypes.map((t) => ShareTypes[t].value).includes(share.shareType)
result = result.filter(({ shareType }) => {
return selectedShareTypes.map((t) => ShareTypes[t].value).includes(shareType)
})
}
const selectedSharedBy = queryItemAsString(unref(selectedSharedByQuery))?.split('+')
if (selectedSharedBy?.length) {
result = result.filter(({ owner }) =>
owner.some(({ username }) => selectedSharedBy.includes(username))
)
result = result.filter(({ owner }) => selectedSharedBy.includes(owner.id))
}
if (unref(filterTerm).trim()) {
Expand Down Expand Up @@ -247,15 +244,15 @@ export default defineComponent({
}
const shareTypes = computed(() => {
const uniqueShareTypes = uniq(unref(storeItems).map((i) => i.share?.shareType))
const uniqueShareTypes = uniq(unref(storeItems).map((i) => i.shareType))
return ShareTypes.getByValues(uniqueShareTypes)
})
const fileOwners = computed(() => {
const flatList = unref(storeItems)
.map((i) => i.owner)
.map((i) => i.sharedBy)
.flat()
return [...new Map(flatList.map((item) => [item.username, item])).values()]
return [...new Map(flatList.map((item) => [item.displayName, item])).values()]
})
onMounted(() => {
Expand Down
9 changes: 8 additions & 1 deletion packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
ApplicationsApiFactory,
UserAppRoleAssignmentApiFactory,
AppRoleAssignment,
ExportPersonalDataRequest
ExportPersonalDataRequest,
MeDriveApiFactory,
DriveItem
} from './generated'

export interface Graph {
Expand All @@ -39,6 +41,8 @@ export interface Graph {
drives: {
listMyDrives: (orderBy?: string, filter?: string) => Promise<AxiosResponse<CollectionOfDrives>>
listAllDrives: (orderBy?: string, filter?: string) => Promise<AxiosResponse<CollectionOfDrives>>
listSharedWithMe: () => AxiosPromise<{ data: { value: DriveItem[] } }>
listSharedByMe: () => AxiosPromise<{ data: { value: DriveItem[] } }>
getDrive: (id: string) => AxiosPromise<Drive>
createDrive: (drive: Drive, options: any) => AxiosPromise<Drive>
updateDrive: (id: string, drive: Drive, options: any) => AxiosPromise<Drive>
Expand Down Expand Up @@ -84,6 +88,7 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
const meDrivesApi = new MeDrivesApi(config, config.basePath, axiosClient)
const allDrivesApi = new DrivesGetDrivesApi(config, config.basePath, axiosClient)
const meUserApiFactory = MeUserApiFactory(config, config.basePath, axiosClient)
const meDriveApiFactory = MeDriveApiFactory(config, config.basePath, axiosClient)
const meChangepasswordApiFactory = MeChangepasswordApiFactory(
config,
config.basePath,
Expand Down Expand Up @@ -117,6 +122,8 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
meDrivesApi.listMyDrives(orderBy, filter),
listAllDrives: (orderBy?: string, filter?: string) =>
allDrivesApi.listAllDrives(orderBy, filter),
listSharedWithMe: () => meDriveApiFactory.listSharedWithMe(),
listSharedByMe: () => meDriveApiFactory.listSharedByMe(),
getDrive: (id: string) => drivesApiFactory.getDrive(id),
createDrive: (drive: Drive, options: any): AxiosPromise<Drive> =>
drivesApiFactory.createDrive(drive, options),
Expand Down
7 changes: 4 additions & 3 deletions packages/web-client/src/helpers/resource/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ export function buildResource(resource: WebDavResponseResource): Resource {
permissions: resource.props[DavProperty.Permissions] || '',
starred: resource.props[DavProperty.IsFavorite] !== 0,
etag: resource.props[DavProperty.ETag],
sharePermissions: resource.props[DavProperty.SharePermissions],
shareTypes,
privateLink: resource.props[DavProperty.PrivateLink],
downloadURL: resource.props[DavProperty.DownloadURL],
shareId: resource.props[DavProperty.ShareId],
shareRoot: resource.props[DavProperty.ShareRoot],
ownerId: resource.props[DavProperty.OwnerId],
ownerDisplayName: resource.props[DavProperty.OwnerDisplayName],
owner: {
id: resource.props[DavProperty.OwnerId],
displayName: resource.props[DavProperty.OwnerDisplayName]
},
tags: (resource.props[DavProperty.Tags] || '').split(',').filter(Boolean),
audio: resource.props[DavProperty.Audio],
location: resource.props[DavProperty.Location],
Expand Down
27 changes: 12 additions & 15 deletions packages/web-client/src/helpers/resource/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DavFileInfoResponse } from '@ownclouders/web-client/src/webdav/constants'
import { User } from '../../generated'
import { DriveItem, Identity, IdentitySet, User } from '../../generated'
import { User as LegacyUser } from '../user'
import { MongoAbility, SubjectRawRule } from '@casl/ability'
import { DAVResultResponseProps, FileStat } from 'webdav'
import { Audio, GeoCoordinates } from '../../generated'
import { ShareType, ShareTypes } from '../share'

export type AbilityActions =
| 'create'
Expand Down Expand Up @@ -58,7 +59,6 @@ export interface Resource {
downloadURL?: string
type?: string
thumbnail?: string
status?: number
processing?: boolean
locked?: boolean
lockOwnerName?: string
Expand All @@ -78,7 +78,6 @@ export interface Resource {
permissions?: string
starred?: boolean
etag?: string
sharePermissions?: number | string // FIXME
shareId?: string
shareRoot?: string
shareTypes?: number[]
Expand All @@ -105,28 +104,26 @@ export interface Resource {
canEditSpaceQuota?(): boolean
canEditTags?(): boolean

isReceivedShare?(): boolean
isMounted?(): boolean

isReceivedShare?(): boolean
isShareRoot?(): boolean

isMounted?(): boolean

getDomSelector?(): string
matchingSpace?: any

resourceOwner?: LegacyUser
owner?: LegacyUser[]
ownerDisplayName?: string
ownerId?: string
sharedWith?: string
shareOwner?: string
shareOwnerDisplayname?: string
hidden?: boolean
owner?: Identity

extension?: string
share?: any

ddate?: string

share?: any // FIXME: DriveItem & move to ShareResource OR remove?!
status?: number //FIXME: remove?
sharedWith?: Identity[] // FIXME move to ShareResource
sharedBy?: Identity // FIXME move to ShareResource
shareType?: number // FIXME move to ShareResource
hidden?: boolean // FIXME move to ShareResource
}

// These interfaces have empty (unused) __${type}SpaceResource properties which are only
Expand Down
27 changes: 11 additions & 16 deletions packages/web-client/src/helpers/share/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,21 @@ export function buildSharedResource(
tags: [],
path: undefined,
webDavPath: undefined,
processing: share.processing || false
processing: share.processing || false,
shareType: parseInt(share.share_type),
sharedBy: { id: share.uid_owner, displayName: share.displayname_owner },
sharedWith: (share.sharedWith || []).map((s) => ({
id: s.username,
displayName: s.displayName
}))
}

if (incomingShares) {
resource.resourceOwner = {
username: share.uid_file_owner as string,
displayName: share.displayname_file_owner as string
resource.owner = {
id: share.uid_file_owner,
displayName: share.displayname_file_owner
}
resource.owner = [
{
username: share.uid_owner as string,
displayName: share.displayname_owner as string,
avatar: undefined,
shareType: ShareTypes.user.value
}
]
resource.sharedWith = share.sharedWith || []

resource.status = parseInt(share.state)
resource.hidden = share.hidden === 'true' || share.hidden === true
resource.name = isRemoteShare ? share.name : path.basename(share.file_target)
Expand All @@ -197,9 +195,6 @@ export function buildSharedResource(
parseInt(share.state) === ShareStatus.accepted &&
SharePermissions.update.enabled(share.permissions)
} else {
resource.sharedWith = share.sharedWith || []
resource.shareOwner = share.uid_owner
resource.shareOwnerDisplayname = share.displayname_owner
resource.name = isRemoteShare ? share.name : path.basename(share.path)
resource.path = share.path
resource.webDavPath = hasShareJail
Expand Down
Loading

0 comments on commit 6962f2f

Please sign in to comment.