From 35a4b1bbf7360e7273973f55274bfc4e57b8af4f Mon Sep 17 00:00:00 2001 From: Jannik Stehle <50302941+JammingBen@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:59:12 +0200 Subject: [PATCH] Fix shares when creating a link for the current folder via context menu (#8945) --- packages/web-app-files/src/store/actions.ts | 32 ++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/web-app-files/src/store/actions.ts b/packages/web-app-files/src/store/actions.ts index 9dad1317be9..0ccfadcf8e5 100644 --- a/packages/web-app-files/src/store/actions.ts +++ b/packages/web-app-files/src/store/actions.ts @@ -429,18 +429,36 @@ export default { context.commit('SET_VERSIONS', response) }, - addLink(context, { path, client, params, storageId }) { + addLink({ commit, dispatch, getters, rootGetters, state }, { path, client, params, storageId }) { return new Promise((resolve, reject) => { client.shares .shareFileWithLink(path, { ...params, spaceRef: storageId }) .then(async (data) => { - const link = buildShare(data.shareInfo, null, allowSharePermissions(context.rootGetters)) - if (context.state.sharesLoading) { - await Promise.resolve(context.state.sharesLoading) + const link = buildShare(data.shareInfo, null, allowSharePermissions(rootGetters)) + if (state.sharesLoading) { + await Promise.resolve(state.sharesLoading) } - context.commit('OUTGOING_SHARES_UPSERT', { ...link, outgoing: true }) - context.dispatch('updateCurrentFileShareTypes') - context.commit('LOAD_INDICATORS', path) + const indirect = + !!getters.highlightedFile?.path && + path !== getters.highlightedFile.path && + !isProjectSpaceResource(getters.highlightedFile) + commit('OUTGOING_SHARES_UPSERT', { ...link, outgoing: true, indirect }) + dispatch('updateCurrentFileShareTypes') + if (indirect) { + // we might need to update the share types for the ancestor resource as well + const ancestor = state.ancestorMetaData[path] ?? null + if (ancestor) { + const { shareTypes } = ancestor + if (!shareTypes.includes(ShareTypes.link.value)) { + commit('UPDATE_ANCESTOR_FIELD', { + path: ancestor.path, + field: 'shareTypes', + value: [...shareTypes, ShareTypes.link.value] + }) + } + } + } + commit('LOAD_INDICATORS', path) resolve(link) }) .catch((e) => {