Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set password modal #6967

Merged
merged 4 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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