Skip to content

Commit

Permalink
Merge pull request #10690 from owncloud/fix-missing-password-modal
Browse files Browse the repository at this point in the history
fix: missing password modal on link type change
  • Loading branch information
JammingBen authored Apr 2, 2024
2 parents ec06985 + 3f160e9 commit 7a78e3c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export default defineComponent({
modal: { type: Object as PropType<Modal>, required: true },
space: { type: Object as PropType<SpaceResource>, required: true },
resource: { type: Object as PropType<Resource>, required: true },
link: { type: Object as PropType<LinkShare>, required: true }
link: { type: Object as PropType<LinkShare>, required: true },
callbackFn: {
type: Function as PropType<() => void>,
default: undefined
}
},
emits: ['confirm', 'update:confirmDisabled'],
setup(props, { expose }) {
Expand All @@ -62,6 +66,10 @@ export default defineComponent({
linkShare: props.link,
options: { password: unref(password) }
})
if (props.callbackFn) {
props.callbackFn()
return
}
showMessage({ title: $gettext('Link was updated successfully') })
} catch (e) {
// Human-readable error message is provided, for example when password is on banned list
Expand Down
18 changes: 0 additions & 18 deletions packages/web-app-files/src/components/SideBar/Shares/FileLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ import { LinkShare } from '@ownclouders/web-client/src/helpers/share'
import DetailsAndEdit from './Links/DetailsAndEdit.vue'
import NameAndCopy from './Links/NameAndCopy.vue'
import CreateQuickLink from './Links/CreateQuickLink.vue'
import SetLinkPasswordModal from '../../Modals/SetLinkPasswordModal.vue'
import { Resource, SpaceResource } from '@ownclouders/web-client/src/helpers'
import { isLocationSharesActive, useSharesStore } from '@ownclouders/web-pkg'
import { useGettext } from 'vue3-gettext'
Expand Down Expand Up @@ -231,11 +230,6 @@ export default defineComponent({
linkShare: LinkShare
password?: string
}) => {
if (password !== undefined && !canDeletePublicLinkPassword(linkShare)) {
showPasswordModal(linkShare)
return
}
try {
await updateLink({
clientService,
Expand All @@ -259,18 +253,6 @@ export default defineComponent({
}
}
const showPasswordModal = (linkShare: LinkShare) => {
dispatchModal({
title: $gettext('Set password'),
customComponent: SetLinkPasswordModal,
customComponentAttrs: () => ({
space: unref(space),
resource: unref(resource),
link: linkShare
})
})
}
return {
clientService,
space,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ import * as EmailValidator from 'email-validator'
import {
createLocationSpaces,
LinkRoleDropdown,
useAbility,
useConfigStore,
useLinkTypes,
useModals,
Expand Down Expand Up @@ -209,15 +210,21 @@ export default defineComponent({
const { $gettext, current } = useGettext()
const configStore = useConfigStore()
const passwordPolicyService = usePasswordPolicyService()
const { can } = useAbility()
const spacesStore = useSpacesStore()
const { spaces } = storeToRefs(spacesStore)
const { getAvailableLinkTypes, getLinkRoleByType } = useLinkTypes()
const { getAvailableLinkTypes, getLinkRoleByType, isPasswordEnforcedForLinkType } =
useLinkTypes()
const space = inject<Ref<SpaceResource>>('space')
const resource = inject<Ref<Resource>>('resource')
const currentLinkType = ref<SharingLinkType>(props.linkShare.type)
const canDeleteReadOnlyPublicLinkPassword = computed(() =>
can('delete-all', 'ReadOnlyPublicLinkPassword')
)
const dateExpire = computed(() => {
return formatRelativeDateFromDateTime(
DateTime.fromISO(props.linkShare.expirationDateTime).endOf('day'),
Expand All @@ -229,17 +236,28 @@ export default defineComponent({
currentLinkType.value = type
const linkShare = props.linkShare
linkShare.type = type
const needsNoPw =
type === SharingLinkType.Internal ||
(unref(canDeleteReadOnlyPublicLinkPassword) && type === SharingLinkType.View)
if (!linkShare.hasPassword && !needsNoPw && isPasswordEnforcedForLinkType(type)) {
showPasswordModal(() => emit('updateLink', { linkShare: { ...linkShare, type } }))
return
}
emit('updateLink', { linkShare })
}
const showPasswordModal = () => {
const showPasswordModal = (callbackFn: () => void = undefined) => {
dispatchModal({
title: props.linkShare.hasPassword ? $gettext('Edit password') : $gettext('Add password'),
customComponent: SetLinkPasswordModal,
customComponentAttrs: () => ({
space: unref(space),
resource: unref(resource),
link: props.linkShare
link: props.linkShare,
...(callbackFn && { callbackFn })
})
})
}
Expand Down Expand Up @@ -342,7 +360,7 @@ export default defineComponent({
id: 'edit-password',
title: this.$gettext('Edit password'),
icon: 'lock-password',
method: this.showPasswordModal
method: () => this.showPasswordModal()
})
if (this.isPasswordRemovable) {
Expand All @@ -359,7 +377,7 @@ export default defineComponent({
id: 'add-password',
title: this.$gettext('Add password'),
icon: 'lock-password',
method: this.showPasswordModal
method: () => this.showPasswordModal()
})
}
Expand Down

0 comments on commit 7a78e3c

Please sign in to comment.