Skip to content

Commit

Permalink
Fix shares when creating a link for the current folder via context me…
Browse files Browse the repository at this point in the history
…nu (#8945)
  • Loading branch information
JammingBen committed Apr 27, 2023
1 parent 10385dd commit 35a4b1b
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions packages/web-app-files/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 35a4b1b

Please sign in to comment.