From f97094c532e58a6490121439d12dc282c02b5682 Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Tue, 10 Oct 2023 19:32:30 +0200 Subject: [PATCH 1/6] create .space folder if removed --- .../actions/spaces/useSpaceActionsUploadImage.ts | 10 +++++++++- .../actions/spaces/useSpaceActionsUploadImage.spec.ts | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts index 75cf89ff54e..2d13fe1504b 100644 --- a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts +++ b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts @@ -35,7 +35,7 @@ export const useSpaceActionsUploadImage = ({ unref(spaceImageInput)?.click() } - const uploadImageSpace = (ev) => { + const uploadImageSpace = async (ev) => { const graphClient = clientService.graphAuthenticated const file = ev.currentTarget.files[0] @@ -56,6 +56,14 @@ export const useSpaceActionsUploadImage = ({ extraHeaders['X-OC-Mtime'] = '' + file.lastModified / 1000 } + if (!store.getters['Files/files'].find((file) => file.name === '.space')) { + await clientService.webdav.createFolder(selectedSpace, { path: '.space' }) + await clientService.webdav.putFileContents(selectedSpace, { + path: '.space/readme.md', + content: $gettext('Here you can add a description for this Space.') + }) + } + return loadingService.addTask(() => { return clientService.webdav .putFileContents(selectedSpace, { diff --git a/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts b/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts index dacbcfb7d0e..2fc268737f4 100644 --- a/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts +++ b/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts @@ -82,6 +82,12 @@ function getWrapper({ const storeOptions = defaultStoreMockOptions const store = createStore(storeOptions) + + store.getters['Files/files'].push({ + id: '1fe58d8b-aa69-4c22-baf7-97dd57479f23', + name: '.space' + }) + return { wrapper: getComposableWrapper( () => { From ba9aa72d6707f61b4f7597bcb40a287880fac978 Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Wed, 11 Oct 2023 16:25:01 +0200 Subject: [PATCH 2/6] space folder check by api, updating drive to refresh readme --- .../spaces/useSpaceActionsUploadImage.ts | 27 ++++++++++++++++++- .../spaces/useSpaceActionsUploadImage.spec.ts | 6 ----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts index 2d13fe1504b..ca7bca6eaa9 100644 --- a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts +++ b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts @@ -11,6 +11,7 @@ import { import { eventBus } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' import { SpaceAction, SpaceActionOptions } from '@ownclouders/web-pkg' +import { buildSpace } from '@ownclouders/web-client/src/helpers' export const useSpaceActionsUploadImage = ({ store, @@ -56,12 +57,36 @@ export const useSpaceActionsUploadImage = ({ extraHeaders['X-OC-Mtime'] = '' + file.lastModified / 1000 } - if (!store.getters['Files/files'].find((file) => file.name === '.space')) { + try { + await clientService.webdav.getFileInfo(selectedSpace, { path: '.space' }) + } catch (_) { await clientService.webdav.createFolder(selectedSpace, { path: '.space' }) await clientService.webdav.putFileContents(selectedSpace, { path: '.space/readme.md', content: $gettext('Here you can add a description for this Space.') }) + const file = await clientService.webdav.getFileInfo(selectedSpace, { + path: '.space/readme.md' + }) + const { data: updatedDriveData } = await clientService.graphAuthenticated.drives.updateDrive( + selectedSpace.id as string, + { + special: [ + { + specialFolder: { + name: 'readme' + }, + id: file.id + } + ] + } as Drive, + {} + ) + store.commit('runtime/spaces/UPDATE_SPACE_FIELD', { + id: selectedSpace.id, + field: 'spaceReadmeData', + value: buildSpace(updatedDriveData).spaceReadmeData + }) } return loadingService.addTask(() => { diff --git a/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts b/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts index 2fc268737f4..dacbcfb7d0e 100644 --- a/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts +++ b/packages/web-app-files/tests/unit/composables/actions/spaces/useSpaceActionsUploadImage.spec.ts @@ -82,12 +82,6 @@ function getWrapper({ const storeOptions = defaultStoreMockOptions const store = createStore(storeOptions) - - store.getters['Files/files'].push({ - id: '1fe58d8b-aa69-4c22-baf7-97dd57479f23', - name: '.space' - }) - return { wrapper: getComposableWrapper( () => { From ae4ccd6438f2dba39efbac095132903114f426d5 Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Tue, 17 Oct 2023 19:12:02 +0200 Subject: [PATCH 3/6] bugfix .space folder changelog --- changelog/unreleased/bugfix-hidden-space-folder | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/unreleased/bugfix-hidden-space-folder diff --git a/changelog/unreleased/bugfix-hidden-space-folder b/changelog/unreleased/bugfix-hidden-space-folder new file mode 100644 index 00000000000..455d32c3717 --- /dev/null +++ b/changelog/unreleased/bugfix-hidden-space-folder @@ -0,0 +1,6 @@ +Bugfix: Create .space folder if it does not exist + +Creating .space folder and README.md in space if folder has been removed by user. + +https://github.com/owncloud/web/issues/9788 +https://github.com/owncloud/web/pull/9793 From ba70f7a34cfc8a1a424986d2ad8c89e3acc20042 Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Tue, 17 Oct 2023 19:38:40 +0200 Subject: [PATCH 4/6] creating space config folder in composable --- .../spaces/useSpaceActionsUploadImage.ts | 27 +++---------------- .../src/composables/spaces/useCreateSpace.ts | 27 +++++++++++-------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts index ca7bca6eaa9..323ab94379f 100644 --- a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts +++ b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts @@ -11,7 +11,7 @@ import { import { eventBus } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' import { SpaceAction, SpaceActionOptions } from '@ownclouders/web-pkg' -import { buildSpace } from '@ownclouders/web-client/src/helpers' +import { useCreateSpace } from '@ownclouders/web-pkg' export const useSpaceActionsUploadImage = ({ store, @@ -25,6 +25,7 @@ export const useSpaceActionsUploadImage = ({ const clientService = useClientService() const loadingService = useLoadingService() const previewService = usePreviewService() + const { createDefaultConfigFolder } = useCreateSpace() let selectedSpace: SpaceResource = null const handler = ({ resources }: SpaceActionOptions) => { @@ -60,32 +61,10 @@ export const useSpaceActionsUploadImage = ({ try { await clientService.webdav.getFileInfo(selectedSpace, { path: '.space' }) } catch (_) { - await clientService.webdav.createFolder(selectedSpace, { path: '.space' }) - await clientService.webdav.putFileContents(selectedSpace, { - path: '.space/readme.md', - content: $gettext('Here you can add a description for this Space.') - }) - const file = await clientService.webdav.getFileInfo(selectedSpace, { - path: '.space/readme.md' - }) - const { data: updatedDriveData } = await clientService.graphAuthenticated.drives.updateDrive( - selectedSpace.id as string, - { - special: [ - { - specialFolder: { - name: 'readme' - }, - id: file.id - } - ] - } as Drive, - {} - ) store.commit('runtime/spaces/UPDATE_SPACE_FIELD', { id: selectedSpace.id, field: 'spaceReadmeData', - value: buildSpace(updatedDriveData).spaceReadmeData + value: (await createDefaultConfigFolder(selectedSpace)).spaceReadmeData }) } diff --git a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts index c80fe9c8665..e7b0ea203cb 100644 --- a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts +++ b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts @@ -1,4 +1,4 @@ -import { buildSpace } from '@ownclouders/web-client/src/helpers' +import { buildSpace, SpaceResource } from '@ownclouders/web-client/src/helpers' import { Drive } from '@ownclouders/web-client/src/generated' import { useGettext } from 'vue3-gettext' import { useClientService } from '../clientService' @@ -10,36 +10,41 @@ export const useCreateSpace = () => { const configurationManager = useConfigurationManager() const createSpace = async (name: string) => { - const { graphAuthenticated, webdav } = clientService + const { graphAuthenticated } = clientService const { data: createdSpace } = await graphAuthenticated.drives.createDrive({ name }, {}) const spaceResource = buildSpace({ ...createdSpace, serverUrl: configurationManager.serverUrl }) - await webdav.createFolder(spaceResource, { path: '.space' }) - const markdown = await webdav.putFileContents(spaceResource, { + return await createDefaultConfigFolder(spaceResource) + } + + const createDefaultConfigFolder = async (space: SpaceResource) => { + await clientService.webdav.createFolder(space, { path: '.space' }) + await clientService.webdav.putFileContents(space, { path: '.space/readme.md', content: $gettext('Here you can add a description for this Space.') }) - - const { data: updatedSpace } = await graphAuthenticated.drives.updateDrive( - createdSpace.id, + const file = await clientService.webdav.getFileInfo(space, { + path: '.space/readme.md' + }) + const { data: updatedDriveData } = await clientService.graphAuthenticated.drives.updateDrive( + space.id as string, { special: [ { specialFolder: { name: 'readme' }, - id: markdown.id as string + id: file.id } ] } as Drive, {} ) - - return buildSpace({ ...updatedSpace, serverUrl: configurationManager.serverUrl }) + return buildSpace({ ...updatedDriveData, serverUrl: configurationManager.serverUrl }) } - return { createSpace } + return { createSpace, createDefaultConfigFolder } } From 832c128947b7efc5b092acba750daccb497dd95e Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Wed, 18 Oct 2023 16:40:08 +0200 Subject: [PATCH 5/6] rename createDefaultConfigFolder to createDefaultMetaFolder --- .../actions/spaces/useSpaceActionsUploadImage.ts | 4 ++-- packages/web-pkg/src/composables/spaces/useCreateSpace.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts index 323ab94379f..5ce2fe58074 100644 --- a/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts +++ b/packages/web-app-files/src/composables/actions/spaces/useSpaceActionsUploadImage.ts @@ -25,7 +25,7 @@ export const useSpaceActionsUploadImage = ({ const clientService = useClientService() const loadingService = useLoadingService() const previewService = usePreviewService() - const { createDefaultConfigFolder } = useCreateSpace() + const { createDefaultMetaFolder } = useCreateSpace() let selectedSpace: SpaceResource = null const handler = ({ resources }: SpaceActionOptions) => { @@ -64,7 +64,7 @@ export const useSpaceActionsUploadImage = ({ store.commit('runtime/spaces/UPDATE_SPACE_FIELD', { id: selectedSpace.id, field: 'spaceReadmeData', - value: (await createDefaultConfigFolder(selectedSpace)).spaceReadmeData + value: (await createDefaultMetaFolder(selectedSpace)).spaceReadmeData }) } diff --git a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts index e7b0ea203cb..180289d6792 100644 --- a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts +++ b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts @@ -17,10 +17,10 @@ export const useCreateSpace = () => { serverUrl: configurationManager.serverUrl }) - return await createDefaultConfigFolder(spaceResource) + return await createDefaultMetaFolder(spaceResource) } - const createDefaultConfigFolder = async (space: SpaceResource) => { + const createDefaultMetaFolder = async (space: SpaceResource) => { await clientService.webdav.createFolder(space, { path: '.space' }) await clientService.webdav.putFileContents(space, { path: '.space/readme.md', @@ -46,5 +46,5 @@ export const useCreateSpace = () => { return buildSpace({ ...updatedDriveData, serverUrl: configurationManager.serverUrl }) } - return { createSpace, createDefaultConfigFolder } + return { createSpace, createDefaultMetaFolder } } From 22de7c635b553858039243a5529cef47612b3502 Mon Sep 17 00:00:00 2001 From: Jacob Noah Date: Fri, 20 Oct 2023 15:21:30 +0200 Subject: [PATCH 6/6] useCreateSpace fix --- .../web-pkg/src/composables/spaces/useCreateSpace.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts index 180289d6792..91c662d6cd9 100644 --- a/packages/web-pkg/src/composables/spaces/useCreateSpace.ts +++ b/packages/web-pkg/src/composables/spaces/useCreateSpace.ts @@ -21,15 +21,13 @@ export const useCreateSpace = () => { } const createDefaultMetaFolder = async (space: SpaceResource) => { - await clientService.webdav.createFolder(space, { path: '.space' }) - await clientService.webdav.putFileContents(space, { + const { graphAuthenticated, webdav } = clientService + await webdav.createFolder(space, { path: '.space' }) + const file = await webdav.putFileContents(space, { path: '.space/readme.md', content: $gettext('Here you can add a description for this Space.') }) - const file = await clientService.webdav.getFileInfo(space, { - path: '.space/readme.md' - }) - const { data: updatedDriveData } = await clientService.graphAuthenticated.drives.updateDrive( + const { data: updatedDriveData } = await graphAuthenticated.drives.updateDrive( space.id as string, { special: [ @@ -37,7 +35,7 @@ export const useCreateSpace = () => { specialFolder: { name: 'readme' }, - id: file.id + id: file.id as string } ] } as Drive,