From f684724e0c8bbc3357f7ee74a50aed1688698615 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 1 Dec 2023 15:34:37 +0100 Subject: [PATCH] feat: show link modal when password is enforced Show the full expanded link modal for creating quick links when a password is enforced. --- .../components/SideBar/Shares/FileLinks.vue | 129 ++++----- .../SideBar/Shares/Links/CreateQuickLink.vue | 15 +- .../src/components/CreateLinkModal.vue | 78 +++--- .../files/useFileActionsCreateQuicklink.ts | 93 +++++-- .../src/composables/clipboard/index.ts | 1 + .../src/composables/clipboard/useClipboard.ts | 27 ++ packages/web-pkg/src/composables/index.ts | 1 + .../web-pkg/src/composables/links/index.ts | 2 + .../src/composables/links/useCreateLink.ts | 77 ++++++ .../links/useDefaultLinkPermissions.ts | 26 ++ .../composables/links/useExpirationRules.ts | 37 ++- packages/web-pkg/src/helpers/share/index.ts | 1 - packages/web-pkg/src/helpers/share/link.ts | 247 ------------------ 13 files changed, 340 insertions(+), 394 deletions(-) create mode 100644 packages/web-pkg/src/composables/clipboard/index.ts create mode 100644 packages/web-pkg/src/composables/clipboard/useClipboard.ts create mode 100644 packages/web-pkg/src/composables/links/useCreateLink.ts create mode 100644 packages/web-pkg/src/composables/links/useDefaultLinkPermissions.ts delete mode 100644 packages/web-pkg/src/helpers/share/link.ts diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue index 2644cdc391c..fd396be7b1f 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue @@ -15,7 +15,7 @@ >('space') const resource = inject>('resource') @@ -221,6 +226,36 @@ export default defineComponent({ ) } + const showQuickLinkPasswordModal = (params = {}) => { + const modal = { + variation: 'passive', + title: $gettext('Set password'), + cancelText: $gettext('Cancel'), + confirmText: $gettext('Set'), + hasInput: true, + inputDescription: $gettext('Passwords for links are required.'), + inputPasswordPolicy: passwordPolicyService.getPolicy(), + inputGeneratePasswordMethod: () => passwordPolicyService.generatePassword(), + inputLabel: $gettext('Password'), + inputType: 'password', + onInput: () => store.dispatch('setModalInputErrorMessage', ''), + onPasswordChallengeCompleted: () => store.dispatch('setModalConfirmButtonDisabled', false), + onPasswordChallengeFailed: () => store.dispatch('setModalConfirmButtonDisabled', true), + onCancel: () => store.dispatch('hideModal'), + onConfirm: async (newPassword: string) => { + await createLink({ + resource: unref(resource), + space: unref(space), + ...params, + password: newPassword + }) + return store.dispatch('hideModal') + } + } + + return store.dispatch('createModal', modal) + } + return { $store: store, ability, @@ -228,7 +263,7 @@ export default defineComponent({ resource, incomingParentShare: inject('incomingParentShare'), hasSpaces: useCapabilitySpacesEnabled(), - hasShareJail: useCapabilityShareJailEnabled(), + hasShareJail, hasPublicLinkEditing: useCapabilityFilesSharingPublicCanEdit(), hasPublicLinkContribute: useCapabilityFilesSharingPublicCanContribute(), hasPublicLinkAliasSupport: useCapabilityFilesSharingPublicAlias(), @@ -241,10 +276,12 @@ export default defineComponent({ canCreatePublicLinks, canDeleteReadOnlyPublicLinkPassword, configurationManager, - passwordPolicyService, canCreateLinks, canEditLink, - expirationRules + expirationRules, + createLink, + showQuickLinkPasswordModal, + defaultLinkPermissions } }, computed: { @@ -380,37 +417,12 @@ export default defineComponent({ ) }, - addNewLink() { - this.checkLinkToCreate({ - link: { - name: this.$gettext('Link'), - permissions: getDefaultLinkPermissions({ - ability: this.ability, - store: this.$store - }).toString(), - expiration: this.expirationRules.default, - password: false - } - }) - }, - - checkLinkToCreate({ link }) { - const paramsToCreate = this.getParamsForLink(link) - - if (this.isPasswordEnforcedFor(link)) { - showQuickLinkPasswordModal( - { - ...this.$language, - store: this.$store, - passwordPolicyService: this.passwordPolicyService - }, - (newPassword) => { - this.createLink({ params: { ...paramsToCreate, password: newPassword } }) - } - ) - } else { - this.createLink({ params: paramsToCreate }) + addNewLink({ link }) { + if (this.isPasswordEnforcedFor({ permissions: this.defaultLinkPermissions })) { + return this.showQuickLinkPasswordModal(link) } + + return this.createLink({ resource: this.resource, space: this.space, ...link }) }, checkLinkToUpdate({ link }) { @@ -424,16 +436,7 @@ export default defineComponent({ } if (!link.password && !this.canDeletePublicLinkPassword(link)) { - showQuickLinkPasswordModal( - { - ...this.$language, - store: this.$store, - passwordPolicyService: this.passwordPolicyService - }, - (newPassword) => { - this.updatePublicLink({ params: { ...params, password: newPassword } }) - } - ) + this.showQuickLinkPasswordModal(params) } else { this.updatePublicLink({ params }) } @@ -490,38 +493,6 @@ export default defineComponent({ } }, - async createLink({ params }) { - 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}` - } - try { - await this.addLink({ - path, - client: this.$client, - storageId: this.resource.fileId || this.resource.id, - params - }) - this.hideModal() - this.showMessage({ - title: this.$gettext('Link was created successfully') - }) - } catch (e) { - console.error(e) - - // Human-readable error message is provided, for example when password is on banned list - if (e.statusCode === 400) { - return this.setModalInputErrorMessage(this.$gettext(e.message)) - } - - this.showErrorMessage({ - title: this.$gettext('Failed to create link'), - error: e - }) - } - }, - async updatePublicLink({ params }) { try { await this.updateLink({ diff --git a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue index b045510bbed..7a15f5cef47 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Links/CreateQuickLink.vue @@ -26,14 +26,10 @@