Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use sharing NG for share listings #10392

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .drone.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The version of OCIS to use in pipelines that test against OCIS
OCIS_COMMITID=01d40c27833bf131db0c8251359e7a6cf3087bd0
OCIS_COMMITID=d73351af89b609e06004148c506fce865f3407bd
OCIS_BRANCH=master
7 changes: 6 additions & 1 deletion packages/web-app-files/src/services/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
useConfigStore,
ConfigStore,
ResourcesStore,
useResourcesStore
useResourcesStore,
SharesStore,
useSharesStore
} from '@ownclouders/web-pkg'
import { unref } from 'vue'
import { ClientService } from '@ownclouders/web-pkg'
Expand All @@ -38,6 +40,7 @@ export type TaskContext = {
router: Router
capabilityStore: CapabilityStore
resourcesStore: ResourcesStore
sharesStore: SharesStore
}

export interface FolderLoader {
Expand Down Expand Up @@ -68,6 +71,7 @@ export class FolderService {
const clientService = useClientService()
const configStore = useConfigStore()
const resourcesStore = useResourcesStore()
const sharesStore = useSharesStore()

const loader = this.loaders.find((l) => l.isEnabled() && l.isActive(unref(router)))
if (!loader) {
Expand All @@ -83,6 +87,7 @@ export class FolderService {
spacesStore,
capabilityStore,
resourcesStore,
sharesStore,
router
}
try {
Expand Down
36 changes: 9 additions & 27 deletions packages/web-app-files/src/services/folder/loaderSharedViaLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder'
import { Router } from 'vue-router'
import { useTask } from 'vue-concurrency'
import { isLocationSharesActive } from '@ownclouders/web-pkg'
import { ShareTypes } from '@ownclouders/web-client/src/helpers/share'
import { aggregateResourceShares } from '@ownclouders/web-client/src/helpers/share'
import { buildOutgoingShareResource } from '@ownclouders/web-client/src/helpers/share/functionsNG'

export class FolderLoaderSharedViaLink implements FolderLoader {
public isEnabled(): boolean {
Expand All @@ -15,9 +14,7 @@ export class FolderLoaderSharedViaLink implements FolderLoader {
}

public getTask(context: TaskContext): FolderLoaderTask {
const { userStore, spacesStore, clientService, configStore, capabilityStore, resourcesStore } =
context
const { owncloudSdk: client } = clientService
const { userStore, spacesStore, clientService, configStore, resourcesStore } = context

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return useTask(function* (signal1, signal2) {
Expand All @@ -28,28 +25,13 @@ export class FolderLoaderSharedViaLink implements FolderLoader {
yield spacesStore.loadMountPoints({ graphClient: clientService.graphAuthenticated })
}

let resources = yield client.shares.getShares('', {
share_types: ShareTypes.link.value.toString(),
include_tags: false
})

resources = resources.map((r) => r.shareInfo)
if (resources.length) {
resources = aggregateResourceShares({
shares: resources,
spaces: spacesStore.spaces,
incomingShares: false,
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 {
data: { value }
} = yield clientService.graphAuthenticated.drives.listSharedByMe()

const resources = value
.filter((s) => s.permissions.some(({ link }) => !!link))
.map((driveItem) => buildOutgoingShareResource({ driveItem, user: userStore.user }))

resourcesStore.initResourceList({ currentFolder: null, resources })
})
Expand Down
37 changes: 9 additions & 28 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 { buildIncomingShareResource } 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, resourcesStore, sharesStore } = context

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return useTask(function* (signal1, signal2) {
Expand All @@ -26,31 +25,13 @@ 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
})

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 {
data: { value }
} = yield clientService.graphAuthenticated.drives.listSharedWithMe()

const resources = value.map((driveItem) =>
buildIncomingShareResource({ driveItem, graphRoles: sharesStore.graphRoles })
)

resourcesStore.initResourceList({ currentFolder: null, resources })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder'
import { Router } from 'vue-router'
import { useTask } from 'vue-concurrency'
import { isLocationSharesActive } from '@ownclouders/web-pkg'
import { aggregateResourceShares } from '@ownclouders/web-client/src/helpers/share'
import { peopleRoleDenyFolder, ShareTypes } from '@ownclouders/web-client/src/helpers/share'
import { buildOutgoingShareResource } from '@ownclouders/web-client/src/helpers/share/functionsNG'

export class FolderLoaderSharedWithOthers implements FolderLoader {
public isEnabled(): boolean {
Expand All @@ -15,9 +14,7 @@ export class FolderLoaderSharedWithOthers implements FolderLoader {
}

public getTask(context: TaskContext): FolderLoaderTask {
const { userStore, spacesStore, clientService, configStore, capabilityStore, resourcesStore } =
context
const { owncloudSdk: client } = clientService
const { userStore, spacesStore, clientService, configStore, resourcesStore } = context

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return useTask(function* (signal1, signal2) {
Expand All @@ -28,37 +25,13 @@ export class FolderLoaderSharedWithOthers implements FolderLoader {
yield spacesStore.loadMountPoints({ graphClient: clientService.graphAuthenticated })
}

const shareTypes = ShareTypes.authenticated
.filter(
(type) => ![ShareTypes.spaceUser.value, ShareTypes.spaceGroup.value].includes(type.value)
)
.map((share) => share.value)
.join(',')
const {
data: { value }
} = yield clientService.graphAuthenticated.drives.listSharedByMe()

let resources = yield client.shares.getShares('', {
share_types: shareTypes,
reshares: true,
include_tags: false
})
resources = resources
.filter((r) => parseInt(r.shareInfo.permissions) !== peopleRoleDenyFolder.bitmask(false))
.map((r) => r.shareInfo)
if (resources.length) {
resources = aggregateResourceShares({
shares: resources,
spaces: spacesStore.spaces,
incomingShares: false,
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 = value
.filter((s) => s.permissions.some(({ link }) => !link))
.map((driveItem) => buildOutgoingShareResource({ driveItem, user: userStore.user }))

resourcesStore.initResourceList({ currentFolder: null, resources })
})
Expand Down
8 changes: 5 additions & 3 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ export default defineComponent({
const selectedShareTypes = queryItemAsString(unref(selectedShareTypesQuery))?.split('+')
if (selectedShareTypes?.length) {
result = result.filter(({ shareType }) => {
return selectedShareTypes.map((t) => ShareTypes[t].value).includes(shareType)
result = result.filter(({ shareTypes }) => {
return selectedShareTypes
.map((t) => ShareTypes[t].value)
.some((t) => shareTypes.includes(t))
})
}
Expand Down Expand Up @@ -244,7 +246,7 @@ export default defineComponent({
}
const shareTypes = computed(() => {
const uniqueShareTypes = uniq(unref(paginatedResources).map((i) => i.shareType))
const uniqueShareTypes = uniq(unref(paginatedResources).flatMap((i) => i.shareTypes))
return ShareTypes.getByValues(uniqueShareTypes)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const getResourceMock = ({
shareTypes,
locked,
canEditTags: vi.fn(() => canEditTags),
...(sharedBy && { shareType: 0 })
...(sharedBy && { sharedWith: [] })
})

const selectors = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ describe('SharedWithMe view', () => {
const shareType2 = ShareTypes.group
const { wrapper } = getMountedWrapper({
files: [
mock<ShareResource>({ shareType: shareType1.value }),
mock<ShareResource>({ shareType: shareType2.value })
mock<ShareResource>({ shareTypes: [shareType1.value] }),
mock<ShareResource>({ shareTypes: [shareType2.value] })
]
})
const filterItems = wrapper.findComponent<any>('.share-type-filter').props('items')
Expand All @@ -101,11 +101,11 @@ describe('SharedWithMe view', () => {
files: [
mock<ShareResource>({
sharedBy: collaborator1,
shareType: ShareTypes.user.value
shareTypes: [ShareTypes.user.value]
}),
mock<ShareResource>({
sharedBy: collaborator2,
shareType: ShareTypes.user.value
shareTypes: [ShareTypes.user.value]
})
]
})
Expand All @@ -125,12 +125,12 @@ describe('SharedWithMe view', () => {
mock<ShareResource>({
name: 'share1',
hidden: false,
shareType: ShareTypes.user.value
shareTypes: [ShareTypes.user.value]
}),
mock<ShareResource>({
name: 'share2',
hidden: false,
shareType: ShareTypes.user.value
shareTypes: [ShareTypes.user.value]
})
]
})
Expand Down
18 changes: 17 additions & 1 deletion packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
ApplicationsApiFactory,
UserAppRoleAssignmentApiFactory,
AppRoleAssignment,
ExportPersonalDataRequest
ExportPersonalDataRequest,
MeDriveApiFactory,
RoleManagementApiFactory,
UnifiedRoleDefinition,
CollectionOfDriveItems1
} from './generated'

export interface Graph {
Expand All @@ -39,6 +43,8 @@ export interface Graph {
drives: {
listMyDrives: (orderBy?: string, filter?: string) => Promise<AxiosResponse<CollectionOfDrives>>
listAllDrives: (orderBy?: string, filter?: string) => Promise<AxiosResponse<CollectionOfDrives>>
listSharedWithMe: () => AxiosPromise<CollectionOfDriveItems1>
listSharedByMe: () => AxiosPromise<CollectionOfDriveItems1>
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 @@ -72,6 +78,9 @@ export interface Graph {
addMember: (groupId: string, userId: string, server: string) => AxiosPromise<void>
deleteMember: (groupId: string, userId: string) => AxiosPromise<void>
}
roleManagement: {
listPermissionRoleDefinitions: () => AxiosPromise<UnifiedRoleDefinition>
}
}

export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
Expand All @@ -84,6 +93,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 All @@ -101,6 +111,7 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
const groupsApiFactory = GroupsApiFactory(config, config.basePath, axiosClient)
const drivesApiFactory = DrivesApiFactory(config, config.basePath, axiosClient)
const tagsApiFactory = TagsApiFactory(config, config.basePath, axiosClient)
const roleManagementApiFactory = RoleManagementApiFactory(config, config.basePath, axiosClient)

return <Graph>{
applications: {
Expand All @@ -117,6 +128,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 Expand Up @@ -174,6 +187,9 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
groupApiFactory.addMember(groupId, { '@odata.id': `${server}graph/v1.0/users/${userId}` }),
deleteMember: (groupId: string, userId: string) =>
groupApiFactory.deleteMember(groupId, userId)
},
roleManagement: {
listPermissionRoleDefinitions: () => roleManagementApiFactory.listPermissionRoleDefinitions()
}
}
}
10 changes: 6 additions & 4 deletions packages/web-client/src/helpers/share/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import path from 'path'
import { SHARE_JAIL_ID, SpaceResource, buildWebDavSpacesPath } from '../space'
import { ShareStatus } from './status'
import { SharePermissions } from './permission'
import { Share } from './share'
import { buildSpaceShare } from './space'
import { LinkShareRoles, PeopleShareRoles } from './role'
import { ShareResource } from './types'
import { ShareResource, Share } from './types'

export const isShareResource = (resource: Resource): resource is ShareResource => {
return Object.hasOwn(resource, 'shareType')
return Object.hasOwn(resource, 'sharedWith')
}

/**
* Transforms given shares into a resource format and returns only their unique occurences
*
* @deprecated
*/
export function aggregateResourceShares({
shares,
Expand Down Expand Up @@ -133,6 +134,7 @@ function addMatchingSpaceToShares(shares, spaces) {
return resources
}

/** @deprecated */
export function buildSharedResource(
share,
incomingShares = false,
Expand All @@ -155,7 +157,7 @@ export function buildSharedResource(
path: undefined,
webDavPath: undefined,
processing: share.processing || false,
shareType: parseInt(share.share_type),
shareTypes: [parseInt(share.share_type)],
owner: { id: share.uid_owner, displayName: share.displayname_owner },
sharedBy: { id: share.uid_owner, displayName: share.displayname_owner },
sharedWith: share.sharedWith || []
Expand Down
Loading