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: pass only space as space prop to sidebar #12000

Merged
merged 1 commit into from
Dec 4, 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,6 @@
Bugfix: Use only space resource with `driveType` "project" as space in sidebar

We've fixed the issue where any selected resource got passed to the sidebar as a space in Spaces page. Now only space resource with `driveType` "project" will be passed as a space.

https://github.com/owncloud/web/pull/12000
https://github.com/owncloud/web/issues/11978
5 changes: 4 additions & 1 deletion packages/web-app-files/src/views/spaces/Projects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ export default defineComponent({
return spacesStore.spaces.filter(isProjectSpaceResource) || []
})
const selectedSpace = computed(() => {
if (unref(selectedResources).length === 1) {
if (
unref(selectedResources).length === 1 &&
isProjectSpaceResource(unref(selectedResources)[0])
) {
return unref(selectedResources)[0] as ProjectSpaceResource
}
return null
Expand Down
25 changes: 22 additions & 3 deletions packages/web-app-files/tests/unit/views/spaces/Projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
mount,
defaultComponentMocks,
defaultStubs,
RouteLocation
RouteLocation,
PiniaMockOptions
} from '@ownclouders/web-test-helpers'
import { AbilityRule, SpaceResource } from '@ownclouders/web-client'
import {
Expand Down Expand Up @@ -120,22 +121,40 @@ describe('Projects view', () => {
})
expect(wrapper.find('create-space-stub').exists()).toBeTruthy()
})
it('should not pass selected resource as space to sidebar when driveType is not "project"', () => {
const resource = mock<SpaceResource>({ id: 'selected-resource', driveType: 'personal' })
const { wrapper } = getMountedWrapper({
store: { resourcesStore: { resources: [resource], selectedIds: ['selected-resource'] } }
})

expect(wrapper.vm.selectedSpace).toStrictEqual(null)
})
it('should pass selected resource as space to sidebar when driveType is "project"', () => {
const resource = mock<SpaceResource>({ id: 'selected-resource', driveType: 'project' })
const { wrapper } = getMountedWrapper({
store: { resourcesStore: { resources: [resource], selectedIds: ['selected-resource'] } }
})

expect(wrapper.vm.selectedSpace.id).toStrictEqual('selected-resource')
})
})

function getMountedWrapper({
mocks = {},
spaces = [],
abilities = [],
stubAppBar = true,
includeDisabled = false
includeDisabled = false,
store = {}
}: {
mocks?: Record<string, unknown>
spaces?: SpaceResource[]
abilities?: AbilityRule[]
stubAppBar?: boolean
includeDisabled?: boolean
store?: PiniaMockOptions
} = {}) {
const plugins = defaultPlugins({ abilities, piniaOptions: { spacesState: { spaces } } })
const plugins = defaultPlugins({ abilities, piniaOptions: { spacesState: { spaces }, ...store } })

vi.mocked(queryItemAsString).mockImplementation(() => includeDisabled.toString())

Expand Down