From 0bca7e6faa3f4a1857b29028f6cabec5526320f6 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 17 Jan 2024 09:09:11 +0100 Subject: [PATCH] refactor: move shares from vuex store to pinia --- .../Modals/SetLinkPasswordModal.vue | 8 +- .../InviteCollaboratorForm.vue | 96 +++-- .../SideBar/Shares/Collaborators/ListItem.vue | 39 +- .../components/SideBar/Shares/FileLinks.vue | 31 +- .../components/SideBar/Shares/FileShares.vue | 30 +- .../components/SideBar/Shares/SharesPanel.vue | 9 +- .../web-app-files/src/composables/index.ts | 1 - .../src/composables/shares/index.ts | 1 - .../src/composables/shares/useShares.ts | 12 - packages/web-app-files/src/store/actions.ts | 275 +------------- packages/web-app-files/src/store/getters.ts | 17 - packages/web-app-files/src/store/mutations.ts | 31 -- packages/web-app-files/src/store/state.ts | 7 - .../Modals/SetLinkPasswordModal.spec.ts | 8 +- .../Shares/Collaborators/ListItem.spec.ts | 29 +- .../SideBar/Shares/FileLinks.spec.ts | 28 +- .../SideBar/Shares/FileShares.spec.ts | 5 +- .../SideBar/Shares/SharesPanel.spec.ts | 6 +- .../tests/unit/store/actions.spec.ts | 198 +--------- .../tests/unit/store/mutations.spec.ts | 46 --- .../src/components/SideBar/FileSideBar.vue | 17 +- .../SideBar/Spaces/Details/SpaceDetails.vue | 12 +- .../helpers/useFileActionsDeleteResources.ts | 7 +- .../src/composables/links/useCreateLink.ts | 9 +- .../src/composables/piniaStores/index.ts | 1 + .../composables/piniaStores/shares/index.ts | 2 + .../composables/piniaStores/shares/shares.ts | 352 ++++++++++++++++++ .../composables/piniaStores/shares/types.ts | 69 ++++ .../Spaces/Details/SpaceDetails.spec.ts | 5 +- .../composables/piniaStores/shares.spec.ts | 218 +++++++++++ .../web-runtime/src/container/bootstrap.ts | 5 +- packages/web-test-helpers/src/mocks/pinia.ts | 3 + .../src/mocks/store/filesModuleMockOptions.ts | 11 +- 33 files changed, 872 insertions(+), 716 deletions(-) delete mode 100644 packages/web-app-files/src/composables/shares/index.ts delete mode 100644 packages/web-app-files/src/composables/shares/useShares.ts create mode 100644 packages/web-pkg/src/composables/piniaStores/shares/index.ts create mode 100644 packages/web-pkg/src/composables/piniaStores/shares/shares.ts create mode 100644 packages/web-pkg/src/composables/piniaStores/shares/types.ts create mode 100644 packages/web-pkg/tests/unit/composables/piniaStores/shares.spec.ts diff --git a/packages/web-app-files/src/components/Modals/SetLinkPasswordModal.vue b/packages/web-app-files/src/components/Modals/SetLinkPasswordModal.vue index 746b3da2a49..0f757f6c071 100644 --- a/packages/web-app-files/src/components/Modals/SetLinkPasswordModal.vue +++ b/packages/web-app-files/src/components/Modals/SetLinkPasswordModal.vue @@ -24,7 +24,7 @@ import { useClientService, useMessages, usePasswordPolicyService, - useStore + useSharesStore } from '@ownclouders/web-pkg' import { Share } from '@ownclouders/web-client/src/helpers' @@ -36,11 +36,11 @@ export default defineComponent({ }, emits: ['confirm', 'update:confirmDisabled'], setup(props, { expose }) { - const store = useStore() const { showMessage, showErrorMessage } = useMessages() const clientService = useClientService() const passwordPolicyService = usePasswordPolicyService() const { $gettext } = useGettext() + const { updateLink } = useSharesStore() const password = ref('') const errorMessage = ref() @@ -52,9 +52,9 @@ export default defineComponent({ const onConfirm = async () => { try { - await store.dispatch('Files/updateLink', { + await updateLink({ id: props.link.id, - client: clientService.owncloudSdk, + clientService: clientService, params: { ...props.link, password: unref(password) } }) showMessage({ title: $gettext('Link was updated successfully') }) diff --git a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue index 7e707347ee0..2b7efd71412 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/InviteCollaborator/InviteCollaboratorForm.vue @@ -132,9 +132,6 @@ import { debounce } from 'lodash-es' import PQueue from 'p-queue' import { storeToRefs } from 'pinia' - -import { mapActions } from 'vuex' - import AutocompleteItem from './AutocompleteItem.vue' import RoleDropdown from '../RoleDropdown.vue' import RecipientContainer from './RecipientContainer.vue' @@ -153,12 +150,13 @@ import { useUserStore, useMessages, useSpacesStore, - useConfigStore + useConfigStore, + useSharesStore, + useStore } from '@ownclouders/web-pkg' import { computed, defineComponent, inject, ref, unref, watch, onMounted } from 'vue' import { Resource } from '@ownclouders/web-client' -import { useShares } from 'web-app-files/src/composables' import { displayPositionedDropdown, formatDateFromDateTime, @@ -194,6 +192,7 @@ export default defineComponent({ }, setup() { + const store = useStore() const userStore = useUserStore() const clientService = useClientService() const spacesStore = useSpacesStore() @@ -207,6 +206,10 @@ export default defineComponent({ const configStore = useConfigStore() const { options: configOptions } = storeToRefs(configStore) + const sharesStore = useSharesStore() + const { addShare } = sharesStore + const { outgoingCollaborators } = storeToRefs(sharesStore) + const saving = ref(false) const savingDelayed = ref(false) const notifyEnabled = ref(false) @@ -262,6 +265,7 @@ export default defineComponent({ }) return { + store, resource: inject('resource'), hasResharing: capabilityRefs.sharingResharing, resharingDefault: capabilityRefs.sharingResharingDefault, @@ -276,7 +280,8 @@ export default defineComponent({ clientService, saving, savingDelayed, - ...useShares(), + outgoingCollaborators, + addShare, showContextMenuOnBtnClick, contextMenuButtonRef, notifyEnabled, @@ -355,8 +360,6 @@ export default defineComponent({ }, methods: { - ...mapActions('Files', ['addShare']), - async fetchRecipients(query) { try { const recipients = await this.$client.shares.getRecipients( @@ -494,43 +497,56 @@ export default defineComponent({ const saveQueue = new PQueue({ concurrency: this.createSharesConcurrentRequests }) + + const bitmask = this.selectedRole.hasCustomPermissions + ? SharePermissions.permissionsToBitmask(this.customPermissions) + : SharePermissions.permissionsToBitmask( + this.selectedRole.permissions( + (this.hasResharing && this.resharingDefault) || this.resourceIsSpace + ) + ) + + let path = this.resource.path + // sharing a share root from the share jail -> use resource name as path + if (this.hasShareJail && path === '/') { + path = `/${this.resource.name}` + } + const savePromises = [] this.selectedCollaborators.forEach((collaborator) => { savePromises.push( saveQueue.add(async () => { - const bitmask = this.selectedRole.hasCustomPermissions - ? SharePermissions.permissionsToBitmask(this.customPermissions) - : SharePermissions.permissionsToBitmask( - this.selectedRole.permissions( - (this.hasResharing && this.resharingDefault) || this.resourceIsSpace - ) - ) - - let path = this.resource.path - // sharing a share root from the share jail -> use resource name as path - if (this.hasShareJail && path === '/') { - path = `/${this.resource.name}` - } - - const addMethod = this.resourceIsSpace ? this.addSpaceMember : this.addShare - try { - await addMethod({ - client: this.$client, - resource: this.resource, - graphClient: this.clientService.graphAuthenticated, - path, - shareWith: collaborator.value.shareWith, - displayName: collaborator.label, - shareType: collaborator.value.shareType, - shareWithUser: collaborator.value.shareWithUser, - shareWithProvider: collaborator.value.shareWithProvider, - permissions: bitmask, - role: this.selectedRole, - expirationDate: this.expirationDate, - storageId: this.resource.fileId || this.resource.id, - notify: this.notifyEnabled - }) + if (this.resourceIsSpace) { + await this.addSpaceMember({ + client: this.$client, + graphClient: this.clientService.graphAuthenticated, + path, + shareWith: collaborator.value.shareWith, + displayName: collaborator.label, + shareType: collaborator.value.shareType, + permissions: bitmask, + role: this.selectedRole, + expirationDate: this.expirationDate, + storageId: this.resource.fileId || this.resource.id + }) + } else { + await this.addShare({ + clientService: this.$clientService, + vuexStore: this.store, + resource: this.resource, + path, + shareWith: collaborator.value.shareWith, + shareType: collaborator.value.shareType, + shareWithUser: collaborator.value.shareWithUser, + shareWithProvider: collaborator.value.shareWithProvider, + permissions: bitmask, + role: this.selectedRole, + expirationDate: this.expirationDate, + storageId: this.resource.fileId || this.resource.id, + notify: this.notifyEnabled + }) + } } catch (e) { console.error(e) errors.push({ diff --git a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue index e58584a6846..cb7e461e9de 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue @@ -129,7 +129,6 @@