From 79498bd7b823b5d7ea4c4c6faf89914314fa4cbb Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 12:32:17 +0200 Subject: [PATCH 01/13] update space quota on upload and delete --- .../src/components/AppBar/CreateAndUpload.vue | 14 ++++++++-- .../src/mixins/deleteResources.js | 28 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 98c2040c9a3..f0772f798e9 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -122,6 +122,8 @@ import MixinFileActions, { EDITOR_MODE_CREATE } from '../../mixins/fileActions' import { buildResource, buildWebDavFilesPath, buildWebDavSpacesPath } from '../../helpers/resources' import { isLocationPublicActive, isLocationSpacesActive } from '../../router' import { useActiveLocation } from '../../composables' +import { useGraphClient } from 'web-client/src/composables' + import { useRequest, useCapabilityShareJailEnabled, @@ -173,6 +175,7 @@ export default defineComponent({ }), ...useUploadHelpers(), ...useRequest(), + ...useGraphClient(), isPersonalLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-personal'), isPublicLocation: useActiveLocation(isLocationPublicActive, 'files-public-files'), isSpacesProjectsLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-projects'), @@ -278,7 +281,7 @@ export default defineComponent({ 'setModalInputErrorMessage', 'hideModal' ]), - ...mapMutations('Files', ['UPSERT_RESOURCE']), + ...mapMutations('Files', ['UPSERT_RESOURCE', 'UPDATE_SPACE_FIELD']), ...mapMutations(['SET_QUOTA']), onFileSuccess() { @@ -287,7 +290,7 @@ export default defineComponent({ } }, - onUploadComplete(result) { + async onUploadComplete(result) { if (result.successful) { const file = result.successful[0] @@ -295,6 +298,13 @@ export default defineComponent({ return } + const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + let pathFileWasUploadedTo = file.meta.currentFolder if (file.meta.relativeFolder) { pathFileWasUploadedTo += file.meta.relativeFolder diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index 8a9b8b5fea6..abcf027f3c1 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -4,6 +4,7 @@ import { isSameResource } from '../helpers/resource' import { buildWebDavFilesTrashPath, buildWebDavSpacesTrashPath } from '../helpers/resources' import PQueue from 'p-queue' import { isLocationTrashActive } from '../router' +import { clientService } from 'web-pkg/src/services' export default { data: () => ({ @@ -16,6 +17,8 @@ export default { ...mapGetters('Files', ['selectedFiles']), ...mapGetters(['user']), ...mapGetters('runtime/auth', { isPublicLinkContext: 'isPublicLinkContextReady' }), + ...mapGetters(['configuration']), + ...mapGetters('runtime/auth', ['accessToken']), $_deleteResources_isInTrashbin() { return ( @@ -97,6 +100,7 @@ export default { methods: { ...mapActions('Files', ['pushResourcesToDeleteList', 'removeFilesFromTrashbin', 'deleteFiles']), ...mapActions(['showMessage', 'toggleModalConfirmButton', 'hideModal', 'createModal']), + ...mapMutations('Files', ['UPDATE_SPACE_FIELD']), ...mapMutations(['SET_QUOTA']), $_deleteResources_trashbin_deleteOp(resource) { @@ -142,14 +146,14 @@ export default { this.deleteResources_deleteOps.push(p) } - Promise.all(this.deleteResources_deleteOps).then(() => { + return Promise.all(this.deleteResources_deleteOps).then(() => { this.hideModal() this.toggleModalConfirmButton() }) }, $_deleteResources_filesList_delete() { - this.deleteFiles({ + return this.deleteFiles({ client: this.$client, files: this.$_deleteResources_resources, isPublicLinkContext: this.isPublicLinkContext, @@ -185,12 +189,26 @@ export default { }) }, - $_deleteResources_delete() { + async $_deleteResources_delete() { this.toggleModalConfirmButton() this.$_deleteResources_isInTrashbin - ? this.$_deleteResources_trashbin_delete() - : this.$_deleteResources_filesList_delete() + ? await this.$_deleteResources_trashbin_delete() + : await this.$_deleteResources_filesList_delete() + + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) + + const driveResponse = await graphClient.drives.getDrive( + this.$_deleteResources_resources[0].storageId + ) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) }, $_deleteResources_displayDialog(resources) { From 57d87be9dacdf934049aa8f4aa21a9cddbab0b16 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 12:42:49 +0200 Subject: [PATCH 02/13] Check if spaces enabled --- .../src/components/AppBar/CreateAndUpload.vue | 16 ++++++---- .../src/mixins/deleteResources.js | 29 ++++++++++--------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index f0772f798e9..01bb2de00ac 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -127,6 +127,7 @@ import { useGraphClient } from 'web-client/src/composables' import { useRequest, useCapabilityShareJailEnabled, + useCapabilitySpacesEnabled, useStore, usePublicLinkPassword, useUserContext @@ -182,6 +183,7 @@ export default defineComponent({ isSpacesProjectLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-project'), isSpacesShareLocation: useActiveLocation(isLocationSpacesActive, 'files-spaces-share'), hasShareJail: useCapabilityShareJailEnabled(), + hasSpaces: useCapabilitySpacesEnabled(), publicLinkPassword: usePublicLinkPassword({ store }), isUserContext: useUserContext({ store }) } @@ -298,12 +300,14 @@ export default defineComponent({ return } - const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) + if (this.hasSpaces) { + const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + } let pathFileWasUploadedTo = file.meta.currentFolder if (file.meta.relativeFolder) { diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index abcf027f3c1..85e676526df 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -15,9 +15,8 @@ export default { computed: { ...mapGetters('Files', ['selectedFiles']), - ...mapGetters(['user']), + ...mapGetters(['user', 'configuration', 'capabilities']), ...mapGetters('runtime/auth', { isPublicLinkContext: 'isPublicLinkContextReady' }), - ...mapGetters(['configuration']), ...mapGetters('runtime/auth', ['accessToken']), $_deleteResources_isInTrashbin() { @@ -196,19 +195,21 @@ export default { ? await this.$_deleteResources_trashbin_delete() : await this.$_deleteResources_filesList_delete() - const graphClient = clientService.graphAuthenticated( - this.configuration.server, - this.accessToken - ) + if (this.capabilities.spaces?.enabled) { + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) - const driveResponse = await graphClient.drives.getDrive( - this.$_deleteResources_resources[0].storageId - ) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) + const driveResponse = await graphClient.drives.getDrive( + this.$_deleteResources_resources[0].storageId + ) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + } }, $_deleteResources_displayDialog(resources) { From 5d18a0f1d8e6f94de0137e729f33288d50294a34 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 15:36:34 +0200 Subject: [PATCH 03/13] Refresh quota on restore file --- .../src/components/AppBar/CreateAndUpload.vue | 16 ++++--- .../src/mixins/actions/restore.js | 36 +++++++++++++++- .../src/mixins/deleteResources.js | 42 ++++++++++--------- 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 01bb2de00ac..337a590572f 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -301,12 +301,16 @@ export default defineComponent({ } if (this.hasSpaces) { - const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) + try { + const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + } catch (e) { + console.error(e) + } } let pathFileWasUploadedTo = file.meta.currentFolder diff --git a/packages/web-app-files/src/mixins/actions/restore.js b/packages/web-app-files/src/mixins/actions/restore.js index 8727d86e353..ce342ed2324 100644 --- a/packages/web-app-files/src/mixins/actions/restore.js +++ b/packages/web-app-files/src/mixins/actions/restore.js @@ -1,4 +1,4 @@ -import { mapActions, mapState } from 'vuex' +import { mapActions, mapGetters, mapMutations, mapState } from 'vuex' import PQueue from 'p-queue' import { isLocationTrashActive } from '../../router' import { @@ -7,10 +7,14 @@ import { buildWebDavSpacesTrashPath, buildWebDavSpacesPath } from '../../helpers/resources' +import { clientService } from 'web-pkg/src/services' export default { computed: { ...mapState(['user']), + ...mapState('Files', ['spaces']), + ...mapGetters(['capabilities', 'configuration']), + ...mapGetters('runtime/auth', ['accessToken']), $_restore_items() { return [ @@ -41,6 +45,8 @@ export default { methods: { ...mapActions('Files', ['removeFilesFromTrashbin']), ...mapActions(['showMessage']), + ...mapMutations('Files', ['UPDATE_SPACE_FIELD']), + ...mapMutations(['SET_QUOTA']), async $_restore_trigger({ resources }) { const restoredResources = [] @@ -102,6 +108,34 @@ export default { status: 'danger' }) } + + // Load quota + if (this.user?.id) { + const user = await this.$client.users.getUser(this.user.id) + this.SET_QUOTA(user.quota) + } + + if (this.capabilities.spaces?.enabled) { + try { + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) + + const driveId = isLocationTrashActive(this.$router, 'files-trash-spaces-project') + ? this.$route.params.storageId + : this.spaces.find((s) => s.driveType === 'personal').id + + const driveResponse = await graphClient.drives.getDrive(driveId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + } catch (e) { + console.error(e) + } + } } } } diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index 85e676526df..0e0d336aa98 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -168,6 +168,26 @@ export default { this.SET_QUOTA(user.quota) } + if (this.capabilities.spaces?.enabled) { + try { + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) + + const driveResponse = await graphClient.drives.getDrive( + this.$_deleteResources_resources[0].storageId + ) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) + } catch (e) { + console.error(e) + } + } + let parentFolderPath if ( this.resourcesToDelete.length && @@ -188,28 +208,12 @@ export default { }) }, - async $_deleteResources_delete() { + $_deleteResources_delete() { this.toggleModalConfirmButton() this.$_deleteResources_isInTrashbin - ? await this.$_deleteResources_trashbin_delete() - : await this.$_deleteResources_filesList_delete() - - if (this.capabilities.spaces?.enabled) { - const graphClient = clientService.graphAuthenticated( - this.configuration.server, - this.accessToken - ) - - const driveResponse = await graphClient.drives.getDrive( - this.$_deleteResources_resources[0].storageId - ) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) - } + ? this.$_deleteResources_trashbin_delete() + : this.$_deleteResources_filesList_delete() }, $_deleteResources_displayDialog(resources) { From 93c5ad58068200098b46d782c5445d67ed2c5f81 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 16:35:35 +0200 Subject: [PATCH 04/13] Fix tests --- packages/web-app-files/src/mixins/actions/restore.js | 2 +- packages/web-app-files/src/mixins/deleteResources.js | 2 +- .../web-app-files/tests/unit/mixins/actions/restore.spec.js | 6 +++++- .../web-app-files/tests/unit/mixins/deleteResources.spec.js | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/web-app-files/src/mixins/actions/restore.js b/packages/web-app-files/src/mixins/actions/restore.js index ce342ed2324..f37e6c05365 100644 --- a/packages/web-app-files/src/mixins/actions/restore.js +++ b/packages/web-app-files/src/mixins/actions/restore.js @@ -115,7 +115,7 @@ export default { this.SET_QUOTA(user.quota) } - if (this.capabilities.spaces?.enabled) { + if (this.capabilities?.spaces?.enabled) { try { const graphClient = clientService.graphAuthenticated( this.configuration.server, diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index 0e0d336aa98..de362e93328 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -168,7 +168,7 @@ export default { this.SET_QUOTA(user.quota) } - if (this.capabilities.spaces?.enabled) { + if (this.capabilities?.spaces?.enabled) { try { const graphClient = clientService.graphAuthenticated( this.configuration.server, diff --git a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js index 521a512cb1d..ff3a1d0b6b5 100644 --- a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js +++ b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js @@ -101,7 +101,8 @@ function getWrapper({ invalidLocation = false, resolveClearTrashBin: resolveRest getters: { configuration: () => ({ server: 'https://example.com' - }) + }), + capabilities: jest.fn() }, modules: { user: { @@ -119,6 +120,9 @@ function getWrapper({ invalidLocation = false, resolveClearTrashBin: resolveRest removeFilesFromTrashbin: jest.fn() } } + }, + mutations: { + SET_QUOTA: () => jest.fn() } }) }) diff --git a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js index 6c9acb38c3e..bc6f48c5410 100644 --- a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js +++ b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js @@ -67,7 +67,8 @@ function getWrapper(resourcesToDelete) { getters: { user: () => { return { id: 'marie' } - } + }, + capabilities: jest.fn() }, modules: { Files: { From 6bcb59faffd049cc95dbba7ab25537aa74f99127 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 17:19:30 +0200 Subject: [PATCH 05/13] WIP --- .../src/components/AppBar/CreateAndUpload.vue | 18 ++++----- .../src/mixins/actions/restore.js | 35 +++++++---------- .../src/mixins/deleteResources.js | 38 +++++++++---------- .../tests/unit/mixins/actions/restore.spec.js | 3 +- .../tests/unit/mixins/deleteResources.spec.js | 20 +++++++--- packages/web-runtime/src/store/user.ts | 4 ++ 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 337a590572f..61c9602fac3 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -300,17 +300,13 @@ export default defineComponent({ return } - if (this.hasSpaces) { - try { - const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) - } catch (e) { - console.error(e) - } + if (this.hasSpaces && (this.isSpacesProjectLocation || this.isPersonalLocation)) { + const driveResponse = await this.graphClient.drives.getDrive(file.meta.routeStorageId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) } let pathFileWasUploadedTo = file.meta.currentFolder diff --git a/packages/web-app-files/src/mixins/actions/restore.js b/packages/web-app-files/src/mixins/actions/restore.js index f37e6c05365..1903fd9edbb 100644 --- a/packages/web-app-files/src/mixins/actions/restore.js +++ b/packages/web-app-files/src/mixins/actions/restore.js @@ -13,7 +13,7 @@ export default { computed: { ...mapState(['user']), ...mapState('Files', ['spaces']), - ...mapGetters(['capabilities', 'configuration']), + ...mapGetters(['configuration', 'capabilities']), ...mapGetters('runtime/auth', ['accessToken']), $_restore_items() { @@ -114,27 +114,20 @@ export default { const user = await this.$client.users.getUser(this.user.id) this.SET_QUOTA(user.quota) } - if (this.capabilities?.spaces?.enabled) { - try { - const graphClient = clientService.graphAuthenticated( - this.configuration.server, - this.accessToken - ) - - const driveId = isLocationTrashActive(this.$router, 'files-trash-spaces-project') - ? this.$route.params.storageId - : this.spaces.find((s) => s.driveType === 'personal').id - - const driveResponse = await graphClient.drives.getDrive(driveId) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) - } catch (e) { - console.error(e) - } + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) + const driveId = isLocationTrashActive(this.$router, 'files-trash-spaces-project') + ? this.$route.params.storageId + : this.spaces.find((s) => s.driveType === 'personal').id + const driveResponse = await graphClient.drives.getDrive(driveId) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) } } } diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index de362e93328..1b88339daa5 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -3,7 +3,7 @@ import { cloneStateObject } from '../helpers/store' import { isSameResource } from '../helpers/resource' import { buildWebDavFilesTrashPath, buildWebDavSpacesTrashPath } from '../helpers/resources' import PQueue from 'p-queue' -import { isLocationTrashActive } from '../router' +import { isLocationTrashActive, isLocationSpacesActive } from '../router' import { clientService } from 'web-pkg/src/services' export default { @@ -167,25 +167,23 @@ export default { const user = await this.$client.users.getUser(this.user.id) this.SET_QUOTA(user.quota) } - - if (this.capabilities?.spaces?.enabled) { - try { - const graphClient = clientService.graphAuthenticated( - this.configuration.server, - this.accessToken - ) - - const driveResponse = await graphClient.drives.getDrive( - this.$_deleteResources_resources[0].storageId - ) - this.UPDATE_SPACE_FIELD({ - id: driveResponse.data.id, - field: 'spaceQuota', - value: driveResponse.data.quota - }) - } catch (e) { - console.error(e) - } + if ( + (this.capabilities?.spaces?.enabled && + isLocationSpacesActive(this.$router, 'files-spaces-project')) || + isLocationSpacesActive(this.$router, 'files-spaces-personal') + ) { + const graphClient = clientService.graphAuthenticated( + this.configuration.server, + this.accessToken + ) + const driveResponse = await graphClient.drives.getDrive( + this.$_deleteResources_resources[0].storageId + ) + this.UPDATE_SPACE_FIELD({ + id: driveResponse.data.id, + field: 'spaceQuota', + value: driveResponse.data.quota + }) } let parentFolderPath diff --git a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js index ff3a1d0b6b5..bd8f8c67365 100644 --- a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js +++ b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js @@ -101,8 +101,7 @@ function getWrapper({ invalidLocation = false, resolveClearTrashBin: resolveRest getters: { configuration: () => ({ server: 'https://example.com' - }), - capabilities: jest.fn() + }) }, modules: { user: { diff --git a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js index bc6f48c5410..e41c977eebb 100644 --- a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js +++ b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js @@ -2,6 +2,7 @@ import Vuex from 'vuex' import { createStore } from 'vuex-extensions' import { mount, createLocalVue } from '@vue/test-utils' import deleteResources from '@files/src/mixins/deleteResources.js' +import { createLocationSpaces } from '../../../src/router' const localVue = createLocalVue() localVue.use(Vuex) @@ -27,9 +28,10 @@ describe('deleteResources', () => { const resourcesToDelete = [{ id: 2, path: '/' }] const wrapper = getWrapper(resourcesToDelete) const spyHideModalStub = jest.spyOn(wrapper.vm, 'hideModal') + const spyRouterPushStub = jest.spyOn(wrapper.vm.$router, 'push') await wrapper.vm.$_deleteResources_filesList_delete() await wrapper.vm.$nextTick() - expect(wrapper.vm.$router.length).toBeGreaterThanOrEqual(0) + expect(spyRouterPushStub).toHaveBeenCalledTimes(0) expect(spyHideModalStub).toHaveBeenCalledTimes(1) }) @@ -37,9 +39,10 @@ describe('deleteResources', () => { const resourcesToDelete = [currentFolder] const wrapper = getWrapper(resourcesToDelete) const spyHideModalStub = jest.spyOn(wrapper.vm, 'hideModal') + const spyRouterPushStub = jest.spyOn(wrapper.vm.$router, 'push') await wrapper.vm.$_deleteResources_filesList_delete() await wrapper.vm.$nextTick() - expect(wrapper.vm.$router.length).toBeGreaterThanOrEqual(1) + expect(spyRouterPushStub).toHaveBeenCalledTimes(1) expect(spyHideModalStub).toHaveBeenCalledTimes(1) }) }) @@ -52,7 +55,15 @@ function getWrapper(resourcesToDelete) { $route: { name: 'files-personal' }, - $router: [], + $router: { + currentRoute: createLocationSpaces('files-spaces-personal'), + resolve: (r) => { + return { + href: r.name + } + }, + push: jest.fn() + }, $client: { users: { getUser: jest.fn(() => user) @@ -67,8 +78,7 @@ function getWrapper(resourcesToDelete) { getters: { user: () => { return { id: 'marie' } - }, - capabilities: jest.fn() + } }, modules: { Files: { diff --git a/packages/web-runtime/src/store/user.ts b/packages/web-runtime/src/store/user.ts index 5e5f2f6a95e..0b4fe99aa6b 100644 --- a/packages/web-runtime/src/store/user.ts +++ b/packages/web-runtime/src/store/user.ts @@ -46,6 +46,10 @@ const mutations = { state.language = user.language state.role = user.role sentrySetUser({ username: user.id }) + + if (user.quota) { + this.commit('SET_QUOTA', user.quota) + } }, SET_CAPABILITIES(state, data) { state.capabilities = data.capabilities From 636a1b9e705346c16bb308b977b0881521974c72 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 18:13:44 +0200 Subject: [PATCH 06/13] Fix tests --- packages/web-app-files/src/mixins/deleteResources.js | 6 +++--- .../web-app-files/tests/unit/mixins/actions/restore.spec.js | 3 ++- .../web-app-files/tests/unit/mixins/deleteResources.spec.js | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index 1b88339daa5..bd950152c2f 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -168,9 +168,9 @@ export default { this.SET_QUOTA(user.quota) } if ( - (this.capabilities?.spaces?.enabled && - isLocationSpacesActive(this.$router, 'files-spaces-project')) || - isLocationSpacesActive(this.$router, 'files-spaces-personal') + this.capabilities?.spaces?.enabled && + (isLocationSpacesActive(this.$router, 'files-spaces-project') || + isLocationSpacesActive(this.$router, 'files-spaces-personal')) ) { const graphClient = clientService.graphAuthenticated( this.configuration.server, diff --git a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js index bd8f8c67365..53a137942e9 100644 --- a/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js +++ b/packages/web-app-files/tests/unit/mixins/actions/restore.spec.js @@ -101,7 +101,8 @@ function getWrapper({ invalidLocation = false, resolveClearTrashBin: resolveRest getters: { configuration: () => ({ server: 'https://example.com' - }) + }), + capabilities: () => {} }, modules: { user: { diff --git a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js index e41c977eebb..549ec37e524 100644 --- a/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js +++ b/packages/web-app-files/tests/unit/mixins/deleteResources.spec.js @@ -78,7 +78,11 @@ function getWrapper(resourcesToDelete) { getters: { user: () => { return { id: 'marie' } - } + }, + configuration: () => ({ + server: 'https://example.com' + }), + capabilities: () => {} }, modules: { Files: { From a07a76bf5709c6827934d1a09e7fe33cc1af995a Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 18:15:33 +0200 Subject: [PATCH 07/13] No need of return promises --- packages/web-app-files/src/mixins/deleteResources.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index bd950152c2f..76ac988425c 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -145,14 +145,14 @@ export default { this.deleteResources_deleteOps.push(p) } - return Promise.all(this.deleteResources_deleteOps).then(() => { + Promise.all(this.deleteResources_deleteOps).then(() => { this.hideModal() this.toggleModalConfirmButton() }) }, $_deleteResources_filesList_delete() { - return this.deleteFiles({ + this.deleteFiles({ client: this.$client, files: this.$_deleteResources_resources, isPublicLinkContext: this.isPublicLinkContext, From 81c32c9d585e4bbc090d0ecf6d37b237d85fb947 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Mon, 8 Aug 2022 18:32:28 +0200 Subject: [PATCH 08/13] Add changelog items --- changelog/unreleased/bugfix-re-fetch-quota | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/bugfix-re-fetch-quota diff --git a/changelog/unreleased/bugfix-re-fetch-quota b/changelog/unreleased/bugfix-re-fetch-quota new file mode 100644 index 00000000000..442b03d8c48 --- /dev/null +++ b/changelog/unreleased/bugfix-re-fetch-quota @@ -0,0 +1,8 @@ +Bugfix: Re-fetch quota + +We've fixed a bug where uploading, deleting or restoring resources doesn't always re-fetch the quota and therefore +was falsy displayed. + +https://github.com/owncloud/web/pull/7415 +https://github.com/owncloud/web/issues/6930 +https://github.com/owncloud/web/issues/7389 From 0bc87f8ff481f1741e564c045b01d3d22cac4a53 Mon Sep 17 00:00:00 2001 From: JanAckermann Date: Tue, 9 Aug 2022 12:32:48 +0200 Subject: [PATCH 09/13] Only call SET_QUOTA if no spaces are set --- .../src/components/AppBar/CreateAndUpload.vue | 2 +- .../src/mixins/actions/restore.js | 8 ++-- .../src/mixins/deleteResources.js | 2 +- .../services/folder/legacy/loaderPersonal.ts | 6 --- .../services/folder/spaces/loaderPersonal.ts | 6 --- .../src/components/Topbar/UserMenu.vue | 37 ++++++++++++++++--- .../src/services/auth/userManager.ts | 14 +++++-- packages/web-runtime/src/store/user.ts | 10 +++-- 8 files changed, 53 insertions(+), 32 deletions(-) diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index 61c9602fac3..b0241bb4ba2 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -287,7 +287,7 @@ export default defineComponent({ ...mapMutations(['SET_QUOTA']), onFileSuccess() { - if (this.user?.quota) { + if (!this.hasSpaces && this.user?.quota) { this.SET_QUOTA(this.user.quota) } }, diff --git a/packages/web-app-files/src/mixins/actions/restore.js b/packages/web-app-files/src/mixins/actions/restore.js index 1903fd9edbb..be7609cd78d 100644 --- a/packages/web-app-files/src/mixins/actions/restore.js +++ b/packages/web-app-files/src/mixins/actions/restore.js @@ -109,11 +109,6 @@ export default { }) } - // Load quota - if (this.user?.id) { - const user = await this.$client.users.getUser(this.user.id) - this.SET_QUOTA(user.quota) - } if (this.capabilities?.spaces?.enabled) { const graphClient = clientService.graphAuthenticated( this.configuration.server, @@ -128,6 +123,9 @@ export default { field: 'spaceQuota', value: driveResponse.data.quota }) + } else if (this.user?.id) { + const user = await this.$client.users.getUser(this.user.id) + this.SET_QUOTA(user.quota) } } } diff --git a/packages/web-app-files/src/mixins/deleteResources.js b/packages/web-app-files/src/mixins/deleteResources.js index 76ac988425c..c3003adafb3 100644 --- a/packages/web-app-files/src/mixins/deleteResources.js +++ b/packages/web-app-files/src/mixins/deleteResources.js @@ -163,7 +163,7 @@ export default { this.toggleModalConfirmButton() // Load quota - if (this.user?.id) { + if (!this.capabilities?.spaces?.enabled && this.user?.id) { const user = await this.$client.users.getUser(this.user.id) this.SET_QUOTA(user.quota) } diff --git a/packages/web-app-files/src/services/folder/legacy/loaderPersonal.ts b/packages/web-app-files/src/services/folder/legacy/loaderPersonal.ts index e6159aa6a5b..1e13c0f5215 100644 --- a/packages/web-app-files/src/services/folder/legacy/loaderPersonal.ts +++ b/packages/web-app-files/src/services/folder/legacy/loaderPersonal.ts @@ -55,12 +55,6 @@ export class FolderLoaderLegacyPersonal implements FolderLoader { currentFolder, files: resources }) - - // fetch user quota - ;(async () => { - const user = await client.users.getUser(router.currentRoute.params.storageId) - store.commit('SET_QUOTA', user.quota) - })() } catch (error) { store.commit('Files/SET_CURRENT_FOLDER', null) console.error(error) diff --git a/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts b/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts index 3bd64974445..1062f4b9a24 100644 --- a/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts +++ b/packages/web-app-files/src/services/folder/spaces/loaderPersonal.ts @@ -51,12 +51,6 @@ export class FolderLoaderSpacesPersonal implements FolderLoader { currentFolder, files: resources }) - - // fetch user quota - ;(async () => { - const user = await clientService.owncloudSdk.users.getUser(ref.user.id) - store.commit('SET_QUOTA', user.quota) - })() } catch (error) { store.commit('Files/SET_CURRENT_FOLDER', null) console.error(error) diff --git a/packages/web-runtime/src/components/Topbar/UserMenu.vue b/packages/web-runtime/src/components/Topbar/UserMenu.vue index ac5057d0d3d..e9ed24513dd 100644 --- a/packages/web-runtime/src/components/Topbar/UserMenu.vue +++ b/packages/web-runtime/src/components/Topbar/UserMenu.vue @@ -64,7 +64,7 @@