diff --git a/changelog/unreleased/bugfix-require-quick-link-password-if-enforced-in-oC10 b/changelog/unreleased/bugfix-require-quick-link-password-if-enforced-in-oC10 new file mode 100644 index 00000000000..83d4e06757d --- /dev/null +++ b/changelog/unreleased/bugfix-require-quick-link-password-if-enforced-in-oC10 @@ -0,0 +1,8 @@ +Bugfix: Require quick link password if enforced in ownCloud 10 + +We've fixed a bug, where no password was requested while creating a quick link, +this led to a silent error where no quick link was created. +We now prompt for a quick link password if enforced + +https://github.com/owncloud/web/pull/6967 +https://github.com/owncloud/web/issues/6963 diff --git a/packages/web-app-files/src/helpers/share/link.ts b/packages/web-app-files/src/helpers/share/link.ts index 01619cbbaf6..6555b06be3e 100644 --- a/packages/web-app-files/src/helpers/share/link.ts +++ b/packages/web-app-files/src/helpers/share/link.ts @@ -12,6 +12,7 @@ interface CreateQuicklink { store: Store storageId?: any resource: any + password?: string } export const createQuicklink = async (args: CreateQuicklink): Promise => { @@ -20,6 +21,11 @@ export const createQuicklink = async (args: CreateQuicklink): Promise => permissions: 1, quicklink: true } + + if (args.password) { + params.password = args.password + } + const { storageId, resource, store } = args const expirationDate = store.state.user.capabilities.files_sharing.public.expire_date diff --git a/packages/web-app-files/src/quickActions.js b/packages/web-app-files/src/quickActions.js index 2717bf96936..1018226f1b2 100644 --- a/packages/web-app-files/src/quickActions.js +++ b/packages/web-app-files/src/quickActions.js @@ -1,3 +1,4 @@ +import { $gettext } from './gettext' import { createQuicklink } from './helpers/share' export async function openNewCollaboratorsPanel(ctx) { @@ -19,6 +20,28 @@ export function canShare(item, store) { return item.canShare() } +export function showQuickLinkPasswordModal(ctx, onConfirm) { + const modal = { + variation: 'passive', + title: $gettext('Set password'), + cancelText: $gettext('Cancel'), + confirmText: $gettext('Set'), + hasInput: true, + inputLabel: $gettext('Password'), + onCancel: () => ctx.store.dispatch('hideModal'), + inputDescription: $gettext('Passwords for links are required.'), + onConfirm: (password) => onConfirm(password), + onInput: (password) => { + if (password.trim() === '') { + return ctx.store.dispatch('setModalInputErrorMessage', $gettext('Password cannot be empty')) + } + return ctx.store.dispatch('setModalInputErrorMessage', null) + } + } + + return ctx.store.dispatch('createModal', modal) +} + export default { collaborators: { id: 'collaborators', @@ -32,6 +55,24 @@ export default { label: ($gettext) => $gettext('Copy quicklink'), icon: 'link', handler: async (ctx) => { + const passwordEnforced = + ctx.store.getters.capabilities?.files_sharing?.public?.password?.enforced_for?.read_only === + true + + if (passwordEnforced) { + return showQuickLinkPasswordModal(ctx, async (password) => { + if (!password || password.trim() === '') { + return ctx.store.dispatch('showMessage', { + title: $gettext('Password cannot be empty'), + status: 'danger' + }) + } + ctx.store.dispatch('hideModal') + await createQuicklink({ ...ctx, resource: ctx.item, password }) + await ctx.store.dispatch('Files/sidebar/openWithPanel', 'sharing-item') + }) + } + await createQuicklink({ ...ctx, resource: ctx.item }) await ctx.store.dispatch('Files/sidebar/openWithPanel', 'sharing-item') },