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: hidden shares in preview app #12040

Merged
merged 1 commit into from
Dec 16, 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
8 changes: 8 additions & 0 deletions changelog/unreleased/bugfix-preview-app-files-visibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Preview app files visibility

We've fixed the issue with displaying hidden files when user open a file in preview app in "Shared with me" list.
The `q_share-visibility` query param is now passed to the app so that if a user opens a file while listing "visible shares", the preview app will allow moving only to another visible files.
When the `q_share-visibility` query param is set to `hidden` (i.e. user is listing "hidden shares"), the preview app will allow moving only to another hidden files.

https://github.com/owncloud/web/pull/12040
https://github.com/owncloud/web/issues/11883
16 changes: 15 additions & 1 deletion packages/web-app-preview/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import {
watch,
Ref
} from 'vue'
import { Resource } from '@ownclouders/web-client'
import { IncomingShareResource, Resource } from '@ownclouders/web-client'
import {
AppFileHandlingResult,
AppFolderHandlingResult,
Expand Down Expand Up @@ -180,6 +180,20 @@ export default defineComponent({
}

const files = props.activeFiles.filter((file) => {
if (
unref(props.currentFileContext.routeQuery)['q_share-visibility'] === 'hidden' &&
!(file as IncomingShareResource).hidden
) {
return false
}

if (
unref(props.currentFileContext.routeQuery)['q_share-visibility'] !== 'hidden' &&
(file as IncomingShareResource).hidden
) {
return false
}

return mimeTypes.includes(file.mimeType?.toLowerCase()) && file.canDownload()
})

Expand Down
34 changes: 31 additions & 3 deletions packages/web-app-preview/tests/unit/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import App from '../../src/App.vue'
import { nextTick } from 'vue'
import { nextTick, ref } from 'vue'
import { defaultComponentMocks, defaultPlugins, shallowMount } from '@ownclouders/web-test-helpers'
import { FileContext, queryItemAsString } from '@ownclouders/web-pkg'
import { mock } from 'vitest-mock-extended'
Expand All @@ -17,6 +17,7 @@ const activeFiles = [
name: 'bear.png',
mimeType: 'image/png',
path: 'personal/admin/bear.png',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -25,6 +26,7 @@ const activeFiles = [
name: 'elephant.png',
mimeType: 'image/png',
path: 'personal/admin/elephant.png',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -33,6 +35,7 @@ const activeFiles = [
name: 'wale_sounds.flac',
mimeType: 'audio/flac',
path: 'personal/admin/wale_sounds.flac',
hidden: true,
canDownload: () => true
},
{
Expand All @@ -41,6 +44,7 @@ const activeFiles = [
name: 'lonely_sloth_very_sad.gif',
mimeType: 'image/gif',
path: 'personal/admin/lonely_sloth_very_sad.gif',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -49,6 +53,7 @@ const activeFiles = [
name: 'tiger_eats_plants.mp4',
mimeType: 'video/mp4',
path: 'personal/admin/tiger_eats_plants.mp4',
hidden: true,
canDownload: () => true
},
{
Expand All @@ -57,6 +62,7 @@ const activeFiles = [
name: 'happy_hippo.gif',
mimeType: 'image/gif',
path: 'personal/admin/happy_hippo.gif',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -65,6 +71,7 @@ const activeFiles = [
name: 'sleeping_dog.gif',
mimeType: 'image/gif',
path: 'personal/admin/sleeping_dog.gif',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -73,6 +80,7 @@ const activeFiles = [
name: 'cat_murr_murr.gif',
mimeType: 'image/gif',
path: 'personal/admin/cat_murr_murr.gif',
hidden: false,
canDownload: () => true
},
{
Expand All @@ -81,6 +89,7 @@ const activeFiles = [
name: 'labrador.gif',
mimeType: 'image/gif',
path: 'personal/admin/labrador.gif',
hidden: false,
canDownload: () => true
}
]
Expand All @@ -104,9 +113,27 @@ describe('Preview app', () => {
).toEqual(['1', '2', '4', '6', '7', '8', '9'])
})
})

describe('Computed "filteredFiles"', () => {
it('should hide hidden shares if the share visibility query is not set to "hidden"', () => {
const { wrapper } = createShallowMountWrapper()
expect(wrapper.vm.filteredFiles.length).toStrictEqual(7)
})

it('should hide visible shares if the share visibility query is set to "hidden"', () => {
const { wrapper } = createShallowMountWrapper({
currentFileContext: { routeQuery: ref({ ['q_share-visibility']: 'hidden' }) }
})
expect(wrapper.vm.filteredFiles.length).toStrictEqual(2)
})
})
})

function createShallowMountWrapper() {
function createShallowMountWrapper({
currentFileContext
}: {
currentFileContext?: Partial<FileContext>
} = {}) {
const mocks = defaultComponentMocks()
mocks.$previewService.loadPreview.mockResolvedValue('')
vi.mocked(queryItemAsString).mockImplementationOnce(() => '1')
Expand All @@ -115,7 +142,8 @@ function createShallowMountWrapper() {
wrapper: shallowMount(App, {
props: {
currentFileContext: mock<FileContext>({
path: 'personal/admin/bear.png'
path: 'personal/admin/bear.png',
...currentFileContext
}),
activeFiles,
isFolderLoading: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const routeToContextQuery = (location: RouteLocation): LocationQuery => {
const { params, query } = location

const contextQuery: Record<string, QueryValue> = {}
const contextQueryItems = ['fileId', 'shareId'].concat(
const contextQueryItems = ['fileId', 'shareId', 'q_share-visibility'].concat(
(location as any).meta?.contextQueryItems || []
) as string[]
for (const queryItem of contextQueryItems) {
Expand Down