fix(web): [backport][OCISDEV-1187] disable confirm in link password dialog when empty (#13234)
fix(web): [OCISDEV-1187] disable confirm in link password dialog when empty (#13218) The link "Add password" / "Edit password" dialog could be confirmed, by button or Enter, while the field was still empty, which removed the password from the link. Confirm now starts disabled, and Enter only confirms when the password policy is fulfilled, same as the button. Signed-off-by: Gaurav Soni <sonigaurav119@gmail.com>
This commit is contained in:
1 parent
ace994ccae
commit
5de8529700
3 files changed
+88
-5
No files matched your search
@@ -0,0 +1,7 @@
|
||||
Bugfix: Disable confirm in the link password dialog until a password is entered
|
||||
|
||||
The "Add password" / "Edit password" dialog for links could be confirmed with
|
||||
an empty field, which removed the password from the link. The confirm button
|
||||
is now disabled until a valid password is entered.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/13218
|
||||
@@ -10,13 +10,13 @@
|
||||
class="oc-modal-body-input"
|
||||
@password-challenge-completed="$emit('update:confirmDisabled', false)"
|
||||
@password-challenge-failed="$emit('update:confirmDisabled', true)"
|
||||
@keydown.enter.prevent="$emit('confirm')"
|
||||
@keydown.enter.prevent="onEnter"
|
||||
@update:model-value="onInput"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, unref } from 'vue'
|
||||
import { onMounted, ref, unref } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { upperFirst } from 'lodash-es'
|
||||
import {
|
||||
@@ -40,7 +40,7 @@ interface Emits {
|
||||
}
|
||||
const { space, resource, link, callbackFn = undefined } = defineProps<Props>()
|
||||
|
||||
defineEmits<Emits>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const { showMessage, showErrorMessage } = useMessages()
|
||||
const clientService = useClientService()
|
||||
@@ -56,6 +56,18 @@ const onInput = (value: string) => {
|
||||
errorMessage.value = undefined
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// an empty password removes the link's password, so confirm starts disabled
|
||||
emit('update:confirmDisabled', true)
|
||||
})
|
||||
|
||||
const onEnter = () => {
|
||||
if (!inputPasswordPolicy.check(unref(password))) {
|
||||
return
|
||||
}
|
||||
emit('confirm')
|
||||
}
|
||||
|
||||
const onConfirm = async () => {
|
||||
try {
|
||||
await updateLink({
|
||||
|
||||
+66
-2
@@ -1,8 +1,20 @@
|
||||
import { mock } from 'vitest-mock-extended'
|
||||
import SetLinkPasswordModal from '../../../../src/components/Modals/SetLinkPasswordModal.vue'
|
||||
import { defaultComponentMocks, defaultPlugins, shallowMount } from '@ownclouders/web-test-helpers'
|
||||
import { Modal, useMessages, useSharesStore } from '@ownclouders/web-pkg'
|
||||
import {
|
||||
Modal,
|
||||
PasswordPolicyService,
|
||||
useMessages,
|
||||
usePasswordPolicyService,
|
||||
useSharesStore
|
||||
} from '@ownclouders/web-pkg'
|
||||
import { Resource, LinkShare, SpaceResource } from '@ownclouders/web-client'
|
||||
import { PasswordPolicy } from '@ownclouders/design-system/helpers'
|
||||
|
||||
vi.mock('@ownclouders/web-pkg', async (importOriginal) => ({
|
||||
...(await importOriginal<any>()),
|
||||
usePasswordPolicyService: vi.fn()
|
||||
}))
|
||||
|
||||
describe('SetLinkPasswordModal', () => {
|
||||
it('should render a text input field for the password', () => {
|
||||
@@ -10,6 +22,51 @@ describe('SetLinkPasswordModal', () => {
|
||||
|
||||
expect(wrapper.find('oc-text-input-stub').exists()).toBeTruthy()
|
||||
})
|
||||
describe('confirm disabled state', () => {
|
||||
it('emits update:confirmDisabled with true after mount', () => {
|
||||
const { wrapper } = getWrapper()
|
||||
|
||||
expect(wrapper.emitted('update:confirmDisabled')).toContainEqual([true])
|
||||
})
|
||||
it('leaves the confirm state to the password policy check while typing', async () => {
|
||||
const { wrapper } = getWrapper()
|
||||
const input = wrapper.findComponent({ name: 'OcTextInput' })
|
||||
const emissionCountAfterMount = wrapper.emitted('update:confirmDisabled').length
|
||||
|
||||
await input.vm.$emit('update:modelValue', 'abc')
|
||||
await input.vm.$emit('update:modelValue', '')
|
||||
|
||||
expect(wrapper.emitted('update:confirmDisabled').length).toBe(emissionCountAfterMount)
|
||||
})
|
||||
})
|
||||
describe('pressing Enter in the password field', () => {
|
||||
it('does not emit confirm when the field is untouched/empty', async () => {
|
||||
const { wrapper } = getWrapper({ passwordPolicyFulfilled: false })
|
||||
const input = wrapper.findComponent({ name: 'OcTextInput' })
|
||||
|
||||
await input.trigger('keydown.enter')
|
||||
|
||||
expect(wrapper.emitted('confirm')).toBeFalsy()
|
||||
})
|
||||
it('does not emit confirm when the value does not fulfill the password policy', async () => {
|
||||
const { wrapper } = getWrapper({ passwordPolicyFulfilled: false })
|
||||
const input = wrapper.findComponent({ name: 'OcTextInput' })
|
||||
|
||||
await input.vm.$emit('update:modelValue', ' ')
|
||||
await input.trigger('keydown.enter')
|
||||
|
||||
expect(wrapper.emitted('confirm')).toBeFalsy()
|
||||
})
|
||||
it('emits confirm when the value fulfills the password policy', async () => {
|
||||
const { wrapper } = getWrapper()
|
||||
const input = wrapper.findComponent({ name: 'OcTextInput' })
|
||||
|
||||
await input.vm.$emit('update:modelValue', 'abc')
|
||||
await input.trigger('keydown.enter')
|
||||
|
||||
expect(wrapper.emitted('confirm')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
describe('method "onConfirm"', () => {
|
||||
it('updates the link', async () => {
|
||||
const { wrapper } = getWrapper()
|
||||
@@ -32,7 +89,14 @@ describe('SetLinkPasswordModal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
function getWrapper() {
|
||||
function getWrapper({
|
||||
passwordPolicyFulfilled = true
|
||||
}: { passwordPolicyFulfilled?: boolean } = {}) {
|
||||
vi.mocked(usePasswordPolicyService).mockReturnValue(
|
||||
mock<PasswordPolicyService>({
|
||||
getPolicy: () => mock<PasswordPolicy>({ check: () => passwordPolicyFulfilled })
|
||||
})
|
||||
)
|
||||
const mocks = { ...defaultComponentMocks() }
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user