Skip to content

Commit

Permalink
Merge pull request #9747 from owncloud/undo-store-webdav-injection
Browse files Browse the repository at this point in the history
refactor: pass user and capabilities to webdav abstraction
  • Loading branch information
JammingBen authored Sep 28, 2023
2 parents 706a7bd + 0f1d75e commit 0a7be23
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
3 changes: 1 addition & 2 deletions packages/web-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@casl/ability": "^6.3.3",
"axios": "^0.27.2 || ^1.0.0",
"lodash-es": "^4.17.21",
"luxon": "^3.0.1",
"vuex": "4.1.0"
"luxon": "^3.0.1"
}
}
10 changes: 4 additions & 6 deletions packages/web-client/src/webdav/clearTrashBin.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { unref } from 'vue'
import {
Resource,
SpaceResource,
buildWebDavFilesTrashPath,
buildWebDavSpacesTrashPath
} from '../helpers'
import { WebDavOptions } from './types'
import { User } from '../helpers'

interface ClearTrashBinOptions {
id?: Resource['id']
}

export const ClearTrashBinFactory = ({ sdk, store }: WebDavOptions) => {
export const ClearTrashBinFactory = ({ sdk, capabilities, user }: WebDavOptions) => {
return {
clearTrashBin(space: SpaceResource, { id }: ClearTrashBinOptions = {}): Promise<void> {
const hasShareJail = store.getters.capabilities?.spaces?.share_jail === true
const user = store.getters.user as User

const hasShareJail = unref(capabilities)?.spaces?.share_jail === true
const path = hasShareJail
? buildWebDavSpacesTrashPath(space.id)
: buildWebDavFilesTrashPath(user.id)
: buildWebDavFilesTrashPath(unref(user).id)
return sdk.fileTrash.clearTrashBin(path, id)
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/web-client/src/webdav/getFileUrl.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { unref } from 'vue'
import { Resource, SpaceResource } from '../helpers'
import { urlJoin } from '../utils'
import { GetFileContentsFactory } from './getFileContents'
import { WebDavOptions } from './types'

export const GetFileUrlFactory = (
getFileContentsFactory: ReturnType<typeof GetFileContentsFactory>,
{ sdk, store }: WebDavOptions
{ sdk, capabilities }: WebDavOptions
) => {
return {
async getFileUrl(
Expand All @@ -20,7 +21,7 @@ export const GetFileUrlFactory = (
}
): Promise<string> {
const inlineDisposition = disposition === 'inline'
const isUrlSigningEnabled = store.getters.capabilities?.core['support-url-signing'] === true
const isUrlSigningEnabled = unref(capabilities)?.core['support-url-signing'] === true
const { path } = resource
let { downloadURL } = resource

Expand Down
5 changes: 3 additions & 2 deletions packages/web-client/src/webdav/search.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { unref } from 'vue'
import { Resource, buildResource } from '../helpers'
import { WebDavOptions } from './types'
import { DavProperties, DavProperty } from './constants'
Expand All @@ -16,13 +17,13 @@ export type SearchResult = {
totalResults: number
}

export const SearchFactory = ({ sdk, store }: WebDavOptions) => {
export const SearchFactory = ({ sdk, capabilities }: WebDavOptions) => {
return {
async search(
term: string,
{ davProperties = DavProperties.Default, searchLimit }: SearchOptions
): Promise<SearchResult> {
const useSpacesEndpoint = store.getters.capabilities?.spaces?.enabled === true
const useSpacesEndpoint = unref(capabilities)?.spaces?.enabled === true
const { range, results } = await sdk.files.search(
term,
searchLimit,
Expand Down
7 changes: 5 additions & 2 deletions packages/web-client/src/webdav/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Store } from 'vuex'
import { OwnCloudSdk } from '../types'
import { CreateFolderFactory } from './createFolder'
import { GetFileContentsFactory } from './getFileContents'
Expand All @@ -15,10 +14,14 @@ import { RestoreFileVersionFactory } from './restoreFileVersion'
import { ClearTrashBinFactory } from './clearTrashBin'
import { SearchFactory } from './search'
import { GetPathForFileIdFactory } from './getPathForFileId'
import { Capabilities } from '../ocs'
import { User } from '../helpers'
import { Ref } from 'vue'

export interface WebDavOptions {
sdk: OwnCloudSdk
store: Store<unknown>
capabilities: Ref<Capabilities['capabilities']>
user: Ref<User>
}

export interface WebDAV {
Expand Down
5 changes: 3 additions & 2 deletions packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RuntimeConfiguration } from './types'
import { buildApplication, NextApplication } from './application'
import { Store } from 'vuex'
import { Router } from 'vue-router'
import { App, unref } from 'vue'
import { App, computed, unref } from 'vue'
import { loadTheme } from '../helpers/theme'
import OwnCloud from 'owncloud-sdk'
import { createGettext, GetTextOptions, Language } from 'vue3-gettext'
Expand Down Expand Up @@ -344,7 +344,8 @@ export const announceClientService = ({
app.config.globalProperties.$clientService.owncloudSdk = sdk
app.config.globalProperties.$clientService.webdav = webdav({
sdk,
store
capabilities: computed(() => store.getters.capabilities),
user: computed(() => store.getters.user)
})

app.provide('$client', sdk)
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a7be23

Please sign in to comment.