fix: OCISDEV-1438 hide Shared via link tab when public sharing is disabled (#13005)
The Shares navigation (desktop tab list and mobile drop-down) always offered a "Shared via link" entry, even when public link sharing was disabled for the account — for example in the Vault, where the backend rejects public link creation and the capability `files_sharing.public.enabled` reports `false`. The entry led to a page that could never contain anything. The Shares navigation now hides the "Shared via link" entry whenever `files_sharing.public.enabled` is `false`. Anyone who still reaches the via-link route directly, including through the legacy `/list/shared-via-link` redirect, is redirected to "Shared with me" at navigation time, keeping the current route scope (e.g. `vault`) intact. When public sharing is enabled, all three entries behave as before. PR: https://github.com/owncloud/ocis/pull/13005
This commit is contained in:
1 parent
9e984d5ef3
commit
6c278bf2ee
5 files changed
+148
-27
No files matched your search
@@ -0,0 +1,17 @@
|
||||
Bugfix: Hide "Shared via link" when public sharing is disabled
|
||||
|
||||
The Shares navigation (the desktop tab list and the mobile drop-down) always
|
||||
offered a "Shared via link" entry, even when public link sharing was disabled
|
||||
for the account — for example in the Vault, where the backend rejects public
|
||||
link creation and the capability `files_sharing.public.enabled` reported
|
||||
`false`. The entry led to a page that could never contain anything.
|
||||
|
||||
The Shares navigation was changed to hide the "Shared via link" entry
|
||||
whenever `files_sharing.public.enabled` is `false`. Anyone who still reached
|
||||
the via-link route directly, including through the legacy
|
||||
`/list/shared-via-link` redirect, was redirected to "Shared with me" at
|
||||
navigation time, keeping the current route scope (e.g. `vault`) intact. When
|
||||
public sharing was enabled, all three Shares navigation entries continued to
|
||||
behave exactly as before.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/13005
|
||||
@@ -42,21 +42,24 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { isLocationSharesActive, RouteShareTypes } from '@ownclouders/web-pkg'
|
||||
import {
|
||||
isLocationSharesActive,
|
||||
locationSharesViaLink,
|
||||
locationSharesWithMe,
|
||||
locationSharesWithOthers
|
||||
locationSharesWithOthers,
|
||||
RouteShareTypes,
|
||||
useActiveLocation,
|
||||
useCapabilityStore,
|
||||
useRouter
|
||||
} from '@ownclouders/web-pkg'
|
||||
|
||||
import { computed, unref } from 'vue'
|
||||
import { useRouter } from '@ownclouders/web-pkg'
|
||||
import { useActiveLocation } from '@ownclouders/web-pkg'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { RouteLocationRaw } from 'vue-router'
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const router = useRouter()
|
||||
const capabilityStore = useCapabilityStore()
|
||||
|
||||
const resolveScopeTemplatePath = (path: string, scopePrefix: string) =>
|
||||
path.replace(/^\/:scope\(vault\)\?/, scopePrefix)
|
||||
@@ -119,13 +122,17 @@ const navItems = computed(() => [
|
||||
text: $gettext('Shared with others'),
|
||||
active: unref(sharesWithOthersActive)
|
||||
},
|
||||
{
|
||||
id: locationSharesViaLink.name as string,
|
||||
icon: 'link',
|
||||
to: locationToPath(locationSharesViaLink),
|
||||
text: $gettext('Shared via link'),
|
||||
active: unref(sharesViaLinkActive)
|
||||
}
|
||||
...(capabilityStore.sharingPublicEnabled
|
||||
? [
|
||||
{
|
||||
id: locationSharesViaLink.name as string,
|
||||
icon: 'link',
|
||||
to: locationToPath(locationSharesViaLink),
|
||||
text: $gettext('Shared via link'),
|
||||
active: unref(sharesViaLinkActive)
|
||||
}
|
||||
]
|
||||
: [])
|
||||
])
|
||||
const currentNavItem = computed(() => unref(navItems).find((navItem) => navItem.active))
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="oc-flex">
|
||||
<div v-if="!isRedirecting" class="oc-flex">
|
||||
<files-view-wrapper>
|
||||
<app-bar :is-side-bar-open="isSideBarOpen">
|
||||
<template #navigation>
|
||||
@@ -56,9 +56,13 @@
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
FileSideBar,
|
||||
locationSharesWithMe,
|
||||
useCapabilityStore,
|
||||
useFileActions,
|
||||
useLoadPreview,
|
||||
useResourcesStore
|
||||
useResourcesStore,
|
||||
useRoute,
|
||||
useRouter
|
||||
} from '@ownclouders/web-pkg'
|
||||
import { AppLoadingSpinner } from '@ownclouders/web-pkg'
|
||||
import { NoContentMessage } from '@ownclouders/web-pkg'
|
||||
@@ -79,6 +83,9 @@ const { getMatchingSpace } = useGetMatchingSpace()
|
||||
|
||||
const resourcesStore = useResourcesStore()
|
||||
const { triggerDefaultAction } = useFileActions()
|
||||
const capabilityStore = useCapabilityStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const {
|
||||
loadResourcesTask,
|
||||
@@ -125,7 +132,18 @@ resourcesStore.$onAction((action) => {
|
||||
const isEmpty = computed(() => {
|
||||
return unref(paginatedResources).length < 1
|
||||
})
|
||||
// capabilities are loaded before routes render and don't change without a reload
|
||||
const isRedirecting = !capabilityStore.sharingPublicEnabled
|
||||
async function created() {
|
||||
if (isRedirecting) {
|
||||
const scope = unref(route).params?.scope
|
||||
await router.replace({
|
||||
name: locationSharesWithMe.name,
|
||||
params: { ...(scope && { scope }) }
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await unref(loadResourcesTask).perform()
|
||||
scrollToResourceFromRoute(unref(paginatedResources), 'files-app-bar')
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import SharesNavigation from '../../../../src/components/AppBar/SharesNavigation.vue'
|
||||
import { locationSharesWithMe } from '@ownclouders/web-pkg'
|
||||
import { CapabilityStore, locationSharesWithMe } from '@ownclouders/web-pkg'
|
||||
import { mock } from 'vitest-mock-extended'
|
||||
import { RouteRecordNormalized } from 'vue-router'
|
||||
import {
|
||||
@@ -30,13 +30,38 @@ describe('SharesNavigation component', () => {
|
||||
const { wrapper } = getWrapper()
|
||||
expect(wrapper.html()).toMatchSnapshot()
|
||||
})
|
||||
|
||||
describe('when public sharing is disabled', () => {
|
||||
it('does not render the "Shared via link" entry on desktop or mobile', () => {
|
||||
const { wrapper } = getWrapper({ sharingPublicEnabled: false })
|
||||
expect(wrapper.findAll('[to="/files/shares/with-me/"]').length).toBe(2)
|
||||
expect(wrapper.findAll('[to="/files/shares/with-others/"]').length).toBe(2)
|
||||
expect(wrapper.find('[to="/files/shares/via-link/"]').exists()).toBeFalsy()
|
||||
expect(wrapper.html()).not.toContain('Shared via link')
|
||||
})
|
||||
})
|
||||
|
||||
describe('when public sharing is enabled', () => {
|
||||
it('renders all three entries on desktop and mobile', () => {
|
||||
const { wrapper } = getWrapper({ sharingPublicEnabled: true })
|
||||
expect(wrapper.findAll('[to="/files/shares/with-me/"]').length).toBe(2)
|
||||
expect(wrapper.findAll('[to="/files/shares/with-others/"]').length).toBe(2)
|
||||
expect(wrapper.findAll('[to="/files/shares/via-link/"]').length).toBe(2)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function getWrapper({ currentRouteName = locationSharesWithMe.name } = {}) {
|
||||
function getWrapper({
|
||||
currentRouteName = locationSharesWithMe.name,
|
||||
sharingPublicEnabled = true
|
||||
} = {}) {
|
||||
const mocks = defaultComponentMocks({
|
||||
currentRoute: mock<RouteLocation>({ name: currentRouteName })
|
||||
})
|
||||
mocks.$router.getRoutes.mockImplementation(() => routes)
|
||||
const capabilities = {
|
||||
files_sharing: { public: { enabled: sharingPublicEnabled } }
|
||||
} satisfies Partial<CapabilityStore['capabilities']>
|
||||
return {
|
||||
mocks,
|
||||
wrapper: shallowMount(SharesNavigation, {
|
||||
@@ -45,7 +70,11 @@ function getWrapper({ currentRouteName = locationSharesWithMe.name } = {}) {
|
||||
renderStubDefaultSlot: true,
|
||||
mocks,
|
||||
provide: mocks,
|
||||
plugins: [...defaultPlugins()]
|
||||
plugins: [
|
||||
...defaultPlugins({
|
||||
piniaOptions: { capabilityState: { capabilities } }
|
||||
})
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import SharedViaLink from '../../../../src/views/shares/SharedViaLink.vue'
|
||||
import { useResourcesViewDefaults } from '../../../../src/composables'
|
||||
import { useResourcesViewDefaultsMock } from '../../../../tests/mocks/useResourcesViewDefaultsMock'
|
||||
import { ref } from 'vue'
|
||||
import { AppBar, ResourceTable } from '@ownclouders/web-pkg'
|
||||
import { AppBar, CapabilityStore, ResourceTable } from '@ownclouders/web-pkg'
|
||||
import { mock, mockDeep } from 'vitest-mock-extended'
|
||||
import { OutgoingShareResource } from '@ownclouders/web-client'
|
||||
import {
|
||||
@@ -64,35 +64,85 @@ describe('SharedViaLink view', () => {
|
||||
).toEqual(mockedFiles.length)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when public sharing is disabled', () => {
|
||||
it('redirects to the "Shared with me" route, preserving the current scope, and does not load resources', () => {
|
||||
const { mocks, resourcesViewDefaults } = getMountedWrapper({
|
||||
sharingPublicEnabled: false,
|
||||
routeParams: { scope: 'vault' }
|
||||
})
|
||||
expect(mocks.$router.replace).toHaveBeenCalledWith({
|
||||
name: 'files-shares-with-me',
|
||||
params: { scope: 'vault' }
|
||||
})
|
||||
expect(resourcesViewDefaults.loadResourcesTask.perform).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not render its body while redirecting', () => {
|
||||
const { wrapper } = getMountedWrapper({
|
||||
sharingPublicEnabled: false,
|
||||
routeParams: { scope: 'vault' }
|
||||
})
|
||||
expect(wrapper.find('app-bar-stub').exists()).toBeFalsy()
|
||||
expect(wrapper.find('file-side-bar-stub').exists()).toBeFalsy()
|
||||
})
|
||||
})
|
||||
|
||||
describe('when public sharing is enabled', () => {
|
||||
it('does not redirect and proceeds to load resources', () => {
|
||||
const { mocks, resourcesViewDefaults } = getMountedWrapper({ sharingPublicEnabled: true })
|
||||
expect(mocks.$router.replace).not.toHaveBeenCalled()
|
||||
expect(resourcesViewDefaults.loadResourcesTask.perform).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function getMountedWrapper({
|
||||
mocks = {},
|
||||
files = [],
|
||||
loading = false
|
||||
}: { mocks?: Record<string, unknown>; files?: OutgoingShareResource[]; loading?: boolean } = {}) {
|
||||
vi.mocked(useResourcesViewDefaults).mockImplementation(() =>
|
||||
useResourcesViewDefaultsMock({
|
||||
paginatedResources: ref(files),
|
||||
areResourcesLoading: ref(loading)
|
||||
})
|
||||
)
|
||||
loading = false,
|
||||
sharingPublicEnabled = true,
|
||||
routeParams = {}
|
||||
}: {
|
||||
mocks?: Record<string, unknown>
|
||||
files?: OutgoingShareResource[]
|
||||
loading?: boolean
|
||||
sharingPublicEnabled?: boolean
|
||||
routeParams?: Record<string, unknown>
|
||||
} = {}) {
|
||||
const resourcesViewDefaults = useResourcesViewDefaultsMock({
|
||||
paginatedResources: ref(files),
|
||||
areResourcesLoading: ref(loading)
|
||||
})
|
||||
vi.mocked(useResourcesViewDefaults).mockImplementation(() => resourcesViewDefaults)
|
||||
const defaultMocks = {
|
||||
...defaultComponentMocks({
|
||||
currentRoute: mock<RouteLocation>({ name: 'files-shares-via-link' })
|
||||
currentRoute: mock<RouteLocation>({
|
||||
name: 'files-shares-via-link',
|
||||
params: routeParams as Record<string, string | string[]>
|
||||
})
|
||||
}),
|
||||
...(mocks && mocks)
|
||||
}
|
||||
|
||||
const capabilities = {
|
||||
files_sharing: { public: { enabled: sharingPublicEnabled } }
|
||||
} satisfies Partial<CapabilityStore['capabilities']>
|
||||
|
||||
return {
|
||||
mocks: defaultMocks,
|
||||
resourcesViewDefaults,
|
||||
wrapper: mount(SharedViaLink, {
|
||||
global: {
|
||||
components: {
|
||||
AppBar,
|
||||
ResourceTable
|
||||
},
|
||||
plugins: [...defaultPlugins()],
|
||||
plugins: [
|
||||
...defaultPlugins({
|
||||
piniaOptions: { capabilityState: { capabilities } }
|
||||
})
|
||||
],
|
||||
mocks: defaultMocks,
|
||||
provide: defaultMocks,
|
||||
stubs: defaultStubs
|
||||
|
||||
Reference in new issue
Block a user