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

Show error message when accessing space via publik link that is disabled #11725

Merged
merged 4 commits into from
Oct 7, 2024
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,7 @@
Bugfix: Accessing disabled password-protected space does not show error

We've fixed a bug where accessing a disabled password-protected space did not show an error message.
Now, users will see an error message when trying to access a disabled password-protected space.

https://github.com/owncloud/web/pull/11725
https://github.com/owncloud/web/issues/11721
21 changes: 13 additions & 8 deletions packages/web-runtime/src/pages/resolvePublicLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default defineComponent({
} catch (e) {
authStore.clearPublicLinkContext()
console.error(e, e.resource)
return
throw e
}
}

Expand Down Expand Up @@ -275,14 +275,19 @@ export default defineComponent({
})

onMounted(async () => {
if (unref(isOcmLink)) {
await resolvePublicLinkTask.perform(false)
return
}
try {
if (unref(isOcmLink)) {
await resolvePublicLinkTask.perform(false)
return
}

await loadPublicSpaceTask.perform()

await loadPublicSpaceTask.perform()
if (!unref(isPasswordRequired)) {
await resolvePublicLinkTask.perform(false)
if (!unref(isPasswordRequired)) {
await resolvePublicLinkTask.perform(false)
}
} catch (e) {
console.error(e)
}
})

Expand Down
44 changes: 41 additions & 3 deletions packages/web-runtime/tests/unit/pages/resolvePublicLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CapabilityStore, ClientService, useRouteParam, useRouteQuery } from '@o
import { DavHttpError, SpaceResource } from '@ownclouders/web-client'
import { authService } from '../../../src/services/auth'
import { ref } from 'vue'
import { DavErrorCode } from '@ownclouders/web-client/webdav'

vi.mock('../../../src/services/auth')

Expand Down Expand Up @@ -67,6 +68,31 @@ describe('resolvePublicLink', () => {
})
})
})
describe('error message', () => {
it('should display an error message if the space cannot be resolved', async () => {
const { wrapper, mocks } = getWrapper({ getFileInfoErrorStatusCode: 404 })

try {
await wrapper.vm.loadPublicSpaceTask.last
} catch {}

expect(wrapper.find('.oc-link-resolve-error-message').text()).toContain(
'The resource could not be located, it may not exist anymore.'
)
})
it('should display an error message if the space cannot be resolved after entering password', async () => {
const { wrapper, mocks } = getWrapper({
passwordRequired: true,
getFileInfoErrorStatusCode: 404
})
await wrapper.vm.loadPublicSpaceTask.last
await expect(wrapper.vm.resolvePublicLinkTask.perform(true)).rejects.toThrow()

expect(wrapper.find('.oc-link-resolve-error-message').text()).toContain(
'The resource could not be located, it may not exist anymore.'
)
})
})
describe('internal link', () => {
it('redirects the user to the login page', async () => {
const { wrapper, mocks } = getWrapper({ isInternalLink: true })
Expand All @@ -82,8 +108,13 @@ describe('resolvePublicLink', () => {

function getWrapper({
passwordRequired = false,
isInternalLink = false
}: { passwordRequired?: boolean; isInternalLink?: boolean } = {}) {
isInternalLink = false,
getFileInfoErrorStatusCode = null
}: {
passwordRequired?: boolean
isInternalLink?: boolean
getFileInfoErrorStatusCode?: number
} = {}) {
const $clientService = mockDeep<ClientService>()
const spaceResource = mockDeep<SpaceResource>({ driveType: 'public' })

Expand All @@ -98,7 +129,14 @@ function getWrapper({
)
}

$clientService.webdav.getFileInfo.mockResolvedValueOnce(spaceResource)
if (getFileInfoErrorStatusCode) {
$clientService.webdav.getFileInfo.mockRejectedValueOnce(
new DavHttpError('', 'ERR_UNKNOWN' as DavErrorCode, undefined, getFileInfoErrorStatusCode)
)
} else {
$clientService.webdav.getFileInfo.mockResolvedValueOnce(spaceResource)
}

const mocks = { ...defaultComponentMocks(), $clientService }

const capabilities = {
Expand Down