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) => {