Skip to content

Commit

Permalink
Add set password modal (#6967)
Browse files Browse the repository at this point in the history
Add set password modal
  • Loading branch information
Jan authored May 13, 2022
1 parent 22cf41c commit f40a899
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions packages/web-app-files/src/helpers/share/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface CreateQuicklink {
store: Store<any>
storageId?: any
resource: any
password?: string
}

export const createQuicklink = async (args: CreateQuicklink): Promise<Share> => {
Expand All @@ -20,6 +21,11 @@ export const createQuicklink = async (args: CreateQuicklink): Promise<Share> =>
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

Expand Down
41 changes: 41 additions & 0 deletions packages/web-app-files/src/quickActions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { $gettext } from './gettext'
import { createQuicklink } from './helpers/share'

export async function openNewCollaboratorsPanel(ctx) {
Expand All @@ -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',
Expand All @@ -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')
},
Expand Down

0 comments on commit f40a899

Please sign in to comment.