From 6f1cbecb19f6de9a0a7eb4a854fdf03d876d04f2 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Wed, 9 Mar 2022 09:58:22 +0100 Subject: [PATCH 1/9] Add and adjust unit tests --- .../src/components/SideBar/SideBar.vue | 5 ++ .../SideBar/Shares/FileShares.spec.js | 4 ++ .../unit/components/SideBar/SideBar.spec.js | 60 ++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/packages/web-app-files/src/components/SideBar/SideBar.vue b/packages/web-app-files/src/components/SideBar/SideBar.vue index 8be8ff881b6..53e8e3e4805 100644 --- a/packages/web-app-files/src/components/SideBar/SideBar.vue +++ b/packages/web-app-files/src/components/SideBar/SideBar.vue @@ -246,6 +246,11 @@ export default { visibilityObserver.disconnect() hiddenObserver.disconnect() }, + mounted() { + if (this.$route.params.spaceId && !this.highlightedFileIsSpace) { + this.loadSpaceTask.perform(this, this.$route.params.spaceId) + } + }, methods: { ...mapActions('Files/sidebar', { closeSidebar: 'close', diff --git a/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js b/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js index 699075655c2..9176b111c84 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js +++ b/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js @@ -8,6 +8,10 @@ import Collaborators from '@/__fixtures__/collaborators' import mockAxios from 'jest-mock-axios' import { spaceRoleManager } from '../../../../../src/helpers/share' import VueCompositionAPI from '@vue/composition-api/dist/vue-composition-api' +import mockAxios from 'jest-mock-axios' +import { buildSpace } from '../../../../../src/helpers/resources' +import { spaceRoleManager } from '../../../../../src/helpers/share' +import VueCompositionAPI from '@vue/composition-api/dist/vue-composition-api' const localVue = createLocalVue() localVue.use(DesignSystem) diff --git a/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js b/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js index 360b3b240e7..328aedc2938 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js +++ b/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js @@ -10,6 +10,7 @@ import { buildResource, renameResource } from '@files/src/helpers/resources' import SideBar from '@files/src/components/SideBar/SideBar.vue' import { createLocationSpaces } from '../../../../src/router' +import mockAxios from 'jest-mock-axios' jest.mock('web-pkg/src/observer') jest.mock('@files/src/helpers/resources', () => { @@ -165,13 +166,58 @@ describe('SideBar', () => { }) }) }) + + describe('current space', () => { + beforeEach(() => { + buildResource.mockImplementation((item) => item) + }) + afterEach(() => { + jest.clearAllMocks() + mockAxios.reset() + }) + it('fetches the current space if a space id is given', async () => { + const spaceId = 1 + mockAxios.request.mockImplementationOnce(() => { + return Promise.resolve({ + data: { id: spaceId } + }) + }) + + const mockFileInfo = jest.fn() + mockFileInfo.mockReturnValueOnce(Files['/'][1]) + + const wrapper = createWrapper({ + item: simpleOwnFolder, + selectedItems: [simpleOwnFolder], + mocks: { $client: { files: { fileInfo: mockFileInfo } } }, + spaceId + }) + + await wrapper.vm.loadSpaceTask.last + expect(wrapper.vm.currentSpace.id).toBe(spaceId) + }) + it('does not fetch the current space if no space id is given', async () => { + const mockFileInfo = jest.fn() + mockFileInfo.mockReturnValueOnce(Files['/'][1]) + + const wrapper = createWrapper({ + item: simpleOwnFolder, + selectedItems: [simpleOwnFolder], + mocks: { $client: { files: { fileInfo: mockFileInfo } } } + }) + + await wrapper.vm.loadSpaceTask.last + expect(wrapper.vm.currentSpace).toBeNull() + }) + }) }) function createWrapper({ item, selectedItems, mocks, - currentRouteName = 'files-spaces-personal-home' + currentRouteName = 'files-spaces-personal-home', + spaceId = undefined }) { const localVue = createLocalVue() localVue.use(Vuex) @@ -180,6 +226,7 @@ function createWrapper({ translations: 'does-not-matter.json', silent: true }) + return shallowMount(SideBar, { store: new Vuex.Store({ getters: { @@ -191,7 +238,11 @@ function createWrapper({ api_enabled: true, public: { enabled: true } } - }) + }), + getToken: jest.fn(() => 'GFwHKXdsMgoFwt'), + configuration: jest.fn(() => ({ + server: 'http://example.com/' + })) }, modules: { apps: { @@ -237,6 +288,11 @@ function createWrapper({ resolve: (r) => { return { href: r.name } } + }, + $route: { + params: { + spaceId + } } }, mocks From 50f0c28fadc7661d4a1ef304556b20eec8afb22b Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Thu, 10 Mar 2022 09:54:49 +0100 Subject: [PATCH 2/9] Move laodSpaceTask from Sidebar to FileShares-panel --- .../components/SideBar/Shares/FileShares.vue | 6 +- .../src/components/SideBar/SideBar.vue | 5 -- .../unit/components/SideBar/SideBar.spec.js | 60 +------------------ 3 files changed, 5 insertions(+), 66 deletions(-) diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue index f1b329b7754..f57df284cfd 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue @@ -114,11 +114,11 @@ export default { const promises = [] const spaceShares = [] - for (const role of Object.keys(ref.currentSpace.spaceRoles)) { - for (const userId of ref.currentSpace.spaceRoles[role]) { + for (const role of Object.keys(ref.space.spaceRoles)) { + for (const userId of ref.space.spaceRoles[role]) { promises.push( graphClient.users.getUser(userId).then((resolved) => { - spaceShares.push(buildSpaceShare({ ...resolved.data, role }, ref.currentSpace.id)) + spaceShares.push(buildSpaceShare({ ...resolved.data, role }, ref.space.id)) }) ) } diff --git a/packages/web-app-files/src/components/SideBar/SideBar.vue b/packages/web-app-files/src/components/SideBar/SideBar.vue index 53e8e3e4805..8be8ff881b6 100644 --- a/packages/web-app-files/src/components/SideBar/SideBar.vue +++ b/packages/web-app-files/src/components/SideBar/SideBar.vue @@ -246,11 +246,6 @@ export default { visibilityObserver.disconnect() hiddenObserver.disconnect() }, - mounted() { - if (this.$route.params.spaceId && !this.highlightedFileIsSpace) { - this.loadSpaceTask.perform(this, this.$route.params.spaceId) - } - }, methods: { ...mapActions('Files/sidebar', { closeSidebar: 'close', diff --git a/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js b/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js index 328aedc2938..360b3b240e7 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js +++ b/packages/web-app-files/tests/unit/components/SideBar/SideBar.spec.js @@ -10,7 +10,6 @@ import { buildResource, renameResource } from '@files/src/helpers/resources' import SideBar from '@files/src/components/SideBar/SideBar.vue' import { createLocationSpaces } from '../../../../src/router' -import mockAxios from 'jest-mock-axios' jest.mock('web-pkg/src/observer') jest.mock('@files/src/helpers/resources', () => { @@ -166,58 +165,13 @@ describe('SideBar', () => { }) }) }) - - describe('current space', () => { - beforeEach(() => { - buildResource.mockImplementation((item) => item) - }) - afterEach(() => { - jest.clearAllMocks() - mockAxios.reset() - }) - it('fetches the current space if a space id is given', async () => { - const spaceId = 1 - mockAxios.request.mockImplementationOnce(() => { - return Promise.resolve({ - data: { id: spaceId } - }) - }) - - const mockFileInfo = jest.fn() - mockFileInfo.mockReturnValueOnce(Files['/'][1]) - - const wrapper = createWrapper({ - item: simpleOwnFolder, - selectedItems: [simpleOwnFolder], - mocks: { $client: { files: { fileInfo: mockFileInfo } } }, - spaceId - }) - - await wrapper.vm.loadSpaceTask.last - expect(wrapper.vm.currentSpace.id).toBe(spaceId) - }) - it('does not fetch the current space if no space id is given', async () => { - const mockFileInfo = jest.fn() - mockFileInfo.mockReturnValueOnce(Files['/'][1]) - - const wrapper = createWrapper({ - item: simpleOwnFolder, - selectedItems: [simpleOwnFolder], - mocks: { $client: { files: { fileInfo: mockFileInfo } } } - }) - - await wrapper.vm.loadSpaceTask.last - expect(wrapper.vm.currentSpace).toBeNull() - }) - }) }) function createWrapper({ item, selectedItems, mocks, - currentRouteName = 'files-spaces-personal-home', - spaceId = undefined + currentRouteName = 'files-spaces-personal-home' }) { const localVue = createLocalVue() localVue.use(Vuex) @@ -226,7 +180,6 @@ function createWrapper({ translations: 'does-not-matter.json', silent: true }) - return shallowMount(SideBar, { store: new Vuex.Store({ getters: { @@ -238,11 +191,7 @@ function createWrapper({ api_enabled: true, public: { enabled: true } } - }), - getToken: jest.fn(() => 'GFwHKXdsMgoFwt'), - configuration: jest.fn(() => ({ - server: 'http://example.com/' - })) + }) }, modules: { apps: { @@ -288,11 +237,6 @@ function createWrapper({ resolve: (r) => { return { href: r.name } } - }, - $route: { - params: { - spaceId - } } }, mocks From 9ba49e622f5927753911fcae232659a16f2f8cc7 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 11 Mar 2022 09:59:26 +0100 Subject: [PATCH 3/9] Implement people sharing for resources within a space --- .../enhancement-spaces-sharing-within-space | 6 +++ .../SideBar/Details/FileDetails.vue | 21 +++++++-- .../components/SideBar/Links/FileLinks.vue | 6 ++- .../components/SideBar/Shares/FileShares.vue | 17 ++++--- .../InviteCollaboratorForm.vue | 10 +++- .../components/SideBar/Shares/SpaceShares.vue | 2 +- .../src/services/folder/loaderProject.ts | 3 +- packages/web-app-files/src/store/actions.js | 46 +++++++++++++------ .../tests/unit/store/actions.spec.js | 2 +- 9 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 changelog/unreleased/enhancement-spaces-sharing-within-space diff --git a/changelog/unreleased/enhancement-spaces-sharing-within-space b/changelog/unreleased/enhancement-spaces-sharing-within-space new file mode 100644 index 00000000000..04ab2c30172 --- /dev/null +++ b/changelog/unreleased/enhancement-spaces-sharing-within-space @@ -0,0 +1,6 @@ +Enhancement: Implement people sharing for resources within a space + +Resources within a space can now be shared with other people. + +https://github.com/owncloud/web/pull/6577 +https://github.com/owncloud/web/issues/6283 diff --git a/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue b/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue index 0fb37dbffcb..2045ef1e344 100644 --- a/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue +++ b/packages/web-app-files/src/components/SideBar/Details/FileDetails.vue @@ -92,8 +92,9 @@ import { ImageDimension } from '../../../constants' import { loadPreview } from '../../../helpers/resource' import upperFirst from 'lodash-es/upperFirst' import path from 'path' -import { createLocationSpaces, isAuthenticatedRoute } from '../../../router' +import { createLocationSpaces, isAuthenticatedRoute, isLocationSpacesActive } from '../../../router' import { ShareTypes } from '../../../helpers/share' +import { useRoute, useRouter } from 'web-pkg/src/composables' import { getIndicators } from '../../../helpers/statusIndicators' export default { @@ -103,11 +104,20 @@ export default { inject: ['displayedItem'], setup() { const sharedParentDir = ref('') - const sharedParentRoute = computed(() => - createLocationSpaces('files-spaces-personal-home', { + const router = useRouter() + const route = useRoute() + + const sharedParentRoute = computed(() => { + if (isLocationSpacesActive(router, 'files-spaces-project')) { + return createLocationSpaces('files-spaces-project', { + params: { spaceId: route.value.params.spaceId, item: sharedParentDir.value } + }) + } + + return createLocationSpaces('files-spaces-personal-home', { params: { item: sharedParentDir.value } }) - ) + }) return { sharedParentDir, @@ -307,7 +317,8 @@ export default { await this.loadSharesTree({ client: this.$client, path: this.file.path, - $gettext: this.$gettext + $gettext: this.$gettext, + spaceId: this.$route.params.spaceId }) this.shareIndicators = getIndicators(this.file, this.sharesTree) }, diff --git a/packages/web-app-files/src/components/SideBar/Links/FileLinks.vue b/packages/web-app-files/src/components/SideBar/Links/FileLinks.vue index 17aa0d6e9d5..6fa2d077a5f 100644 --- a/packages/web-app-files/src/components/SideBar/Links/FileLinks.vue +++ b/packages/web-app-files/src/components/SideBar/Links/FileLinks.vue @@ -197,12 +197,14 @@ export default { this.loadCurrentFileOutgoingShares({ client: this.$client, path: this.highlightedFile.path, - $gettext: this.$gettext + $gettext: this.$gettext, + spaceId: this.$route.params.spaceId }) this.loadSharesTree({ client: this.$client, path: dirname(this.highlightedFile.path), - $gettext: this.$gettext + $gettext: this.$gettext, + spaceId: this.$route.params.spaceId }) }, linksComparator(l1, l2) { diff --git a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue index f57df284cfd..f111fb3f881 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/FileShares.vue @@ -31,7 +31,8 @@