Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use sharing NG for the shared views
Browse files Browse the repository at this point in the history
JammingBen committed Jan 29, 2024
1 parent fc28ba7 commit a7dbb6a
Showing 28 changed files with 351 additions and 453 deletions.
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=33360327c0c6902849b30c1f016d02efe7c17211
OCIS_BRANCH=master
5 changes: 0 additions & 5 deletions .drone.star
Original file line number Diff line number Diff line change
@@ -138,8 +138,6 @@ config = {
],
"oCISSharingAutocompletionResharing": [
"webUISharingAutocompletion",
"webUIResharing1",
"webUIResharing2",
],
"oCISSharingPerm1": [
"webUISharingPermissionsUsers",
@@ -193,7 +191,6 @@ config = {
# These list contains all the test suites that are present
# When adding new test suites, make sure to update these lists
rootSharingTestSuites = [
"webUIResharingToRoot",
"webUISharingAcceptSharesToRoot",
"webUISharingInternalGroupsToRoot",
"webUISharingInternalGroupsToRootEdgeCases",
@@ -221,8 +218,6 @@ basicTestSuites = [
"webUIPrivateLinks",
"webUIRenameFiles",
"webUIRenameFolders",
"webUIResharing1",
"webUIResharing2",
"webUISharingAcceptShares",
"webUISharingAutocompletion",
"webUISharingFilePermissionMultipleUsers",
7 changes: 6 additions & 1 deletion packages/web-app-files/src/services/folder.ts
Original file line number Diff line number Diff line change
@@ -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'
@@ -38,6 +40,7 @@ export type TaskContext = {
router: Router
capabilityStore: CapabilityStore
resourcesStore: ResourcesStore
sharesStore: SharesStore
}

export interface FolderLoader {
@@ -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) {
@@ -83,6 +87,7 @@ export class FolderService {
spacesStore,
capabilityStore,
resourcesStore,
sharesStore,
router
}
try {
35 changes: 9 additions & 26 deletions packages/web-app-files/src/services/folder/loaderSharedViaLink.ts
Original file line number Diff line number Diff line change
@@ -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 {
@@ -15,9 +14,8 @@ export class FolderLoaderSharedViaLink implements FolderLoader {
}

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

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return useTask(function* (signal1, signal2) {
@@ -28,28 +26,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 })
})
36 changes: 9 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 { buildIncomingShareResource } from '@ownclouders/web-client/src/helpers/share/functionsNG'
import { isLocationSharesActive } from '@ownclouders/web-pkg'

export class FolderLoaderSharedWithMe implements FolderLoader {
@@ -14,7 +14,7 @@ export class FolderLoaderSharedWithMe implements FolderLoader {
}

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

// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -26,31 +26,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 })
})
Original file line number Diff line number Diff line change
@@ -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 {
@@ -15,9 +14,8 @@ export class FolderLoaderSharedWithOthers implements FolderLoader {
}

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

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return useTask(function* (signal1, signal2) {
@@ -28,37 +26,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 })
})
12 changes: 9 additions & 3 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
@@ -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))
})
}
@@ -244,7 +246,11 @@ export default defineComponent({
}
const shareTypes = computed(() => {
const uniqueShareTypes = uniq(unref(paginatedResources).map((i) => i.shareType))
const uniqueShareTypes = uniq(
unref(paginatedResources)
.map((i) => i.shareTypes)
.flat()
)
return ShareTypes.getByValues(uniqueShareTypes)
})
Original file line number Diff line number Diff line change
@@ -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')
@@ -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]
})
]
})
@@ -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]
})
]
})
18 changes: 17 additions & 1 deletion packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
@@ -24,7 +24,11 @@ import {
ApplicationsApiFactory,
UserAppRoleAssignmentApiFactory,
AppRoleAssignment,
ExportPersonalDataRequest
ExportPersonalDataRequest,
MeDriveApiFactory,
RoleManagementApiFactory,
UnifiedRoleDefinition,
CollectionOfDriveItems1
} from './generated'

export interface Graph {
@@ -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>
@@ -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 => {
@@ -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,
@@ -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: {
@@ -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),
@@ -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()
}
}
}
Loading

0 comments on commit a7dbb6a

Please sign in to comment.