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

Fix banned password error not shown in different modals #9866

Merged
merged 5 commits into from
Oct 27, 2023
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
@@ -1,8 +1,9 @@
Enhancement: Add permission to delete link passwords when password is enforced

We've enabled to ability to allow delete passwords on public links, even if the password is enforced.
We've added the ability to allow deleting passwords on public links, even if the password is enforced.
Therefore, the user needs respective permission, granted by the server.
This feature is only possible on public links that have the viewer role.

https://github.com/owncloud/web/pull/9857
https://github.com/owncloud/web/pull/9866
AlexAndBear marked this conversation as resolved.
Show resolved Hide resolved
https://github.com/owncloud/ocis/issues/7538
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export default defineComponent({
console.error(e)

// Human-readable error message is provided, for example when password is on banned list
if (e.status === 400) {
if (e.statusCode === 400) {
return this.setModalInputErrorMessage(this.$gettext(e.message))
}

Expand Down
91 changes: 55 additions & 36 deletions packages/web-pkg/src/helpers/share/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,16 @@ export interface CopyQuickLink extends CreateQuicklink {
// it has a fallback to the vue-use implementation.
//
// https://webkit.org/blog/10855/
const doCopy = async ({
store,
language,
quickLinkUrl
}: {
store: Store<unknown>
language: Language
quickLinkUrl: string
}) => {
const { $gettext } = language
try {
if (typeof ClipboardItem && navigator?.clipboard?.write) {
await navigator.clipboard.write([
new ClipboardItem({
'text/plain': new Blob([quickLinkUrl], { type: 'text/plain' })
})
])
} else {
const { copy } = useClipboard({ legacy: true })
await copy(quickLinkUrl)
}
await store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})
} catch (e) {
console.error(e)
await store.dispatch('showErrorMessage', {
title: $gettext('Copy link failed'),
error: e
})
const copyToClipboard = async (quickLinkUrl: string) => {
if (typeof ClipboardItem && navigator?.clipboard?.write) {
return navigator.clipboard.write([
new ClipboardItem({
'text/plain': new Blob([quickLinkUrl], { type: 'text/plain' })
})
])
} else {
const { copy } = useClipboard({ legacy: true })
return copy(quickLinkUrl)
}
}
export const copyQuicklink = async (args: CopyQuickLink) => {
Expand All @@ -85,7 +65,18 @@ export const copyQuicklink = async (args: CopyQuickLink) => {
.find((share: Share) => share.quicklink === true)

if (existingQuickLink) {
return doCopy({ store, language, quickLinkUrl: existingQuickLink.url })
try {
await copyToClipboard(existingQuickLink.url)
return store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})
} catch (e) {
console.error(e)
return store.dispatch('showErrorMessage', {
title: $gettext('Copy link failed'),
error: e
})
}
}

const isPasswordEnforced =
Expand All @@ -95,15 +86,43 @@ export const copyQuicklink = async (args: CopyQuickLink) => {
return showQuickLinkPasswordModal(
{ $gettext, store, passwordPolicyService },
async (password: string) => {
await store.dispatch('hideModal')
const quickLink = await createQuicklink({ ...args, password })
return doCopy({ store, language, quickLinkUrl: quickLink.url })
try {
const quickLink = await createQuicklink({ ...args, password })
await store.dispatch('hideModal')
await copyToClipboard(quickLink.url)
return store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})
} catch (e) {
console.log(e)

// Human-readable error message is provided, for example when password is on banned list
if (e.statusCode === 400) {
return store.dispatch('setModalInputErrorMessage', $gettext(e.message))
}

return store.dispatch('showErrorMessage', {
title: $gettext('Copy link failed'),
error: e
})
}
}
)
}

const quickLink = await createQuicklink(args)
return doCopy({ store, language, quickLinkUrl: quickLink.url })
try {
const quickLink = await createQuicklink(args)
await copyToClipboard(quickLink.url)
return store.dispatch('showMessage', {
title: $gettext('The link has been copied to your clipboard.')
})
} catch (e) {
console.error(e)
return store.dispatch('showErrorMessage', {
title: $gettext('Copy link failed'),
error: e
})
}
}

export const createQuicklink = async (args: CreateQuicklink): Promise<Share> => {
Expand Down