Skip to content

Commit

Permalink
fix(FilesView): Update files view upon share creation/delete
Browse files Browse the repository at this point in the history
Resolves : #44961

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Jun 25, 2024
1 parent ffa8b00 commit 0281e6e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
8 changes: 6 additions & 2 deletions apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
{{ t('files_sharing', 'Customize link') }}
</NcActionButton>
</template>

<NcActionButton :close-after-click="true"
@click.prevent="showQRCode = true">
<template #icon>
Expand Down Expand Up @@ -210,11 +210,12 @@
</template>

<script>
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { Type as ShareTypes } from '@nextcloud/sharing'
import Vue from 'vue'
import VueQrcode from '@chenfengyuan/vue-qrcode';
import VueQrcode from '@chenfengyuan/vue-qrcode'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActionInput from '@nextcloud/vue/dist/Components/NcActionInput.js'
Expand Down Expand Up @@ -686,6 +687,9 @@ export default {
})
}
await this.getNode()
emit('files:node:updated', this.node)
// Execute the copy link method
// freshly created share component
// ! somehow does not works on firefox !
Expand Down
24 changes: 23 additions & 1 deletion apps/files_sharing/src/mixins/SharesMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { emit } from '@nextcloud/event-bus'
import { fetchNode } from '../services/WebdavClient.ts'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { getCurrentUser } from '@nextcloud/auth'
// eslint-disable-next-line import/no-unresolved, n/no-missing-import
Expand All @@ -13,6 +15,7 @@ import Share from '../models/Share.js'
import SharesRequests from './ShareRequests.js'
import ShareTypes from './ShareTypes.js'
import Config from '../services/ConfigService.js'
import logger from '../services/logger.ts'

import {
BUNDLED_PERMISSIONS,
Expand Down Expand Up @@ -40,6 +43,7 @@ export default {
data() {
return {
config: new Config(),
node: null,

// errors helpers
errors: {},
Expand All @@ -62,7 +66,9 @@ export default {
},

computed: {

path() {
return (this.fileInfo.path + '/' + this.fileInfo.name).replace('//', '/')
},
/**
* Does the current share have a note
*
Expand Down Expand Up @@ -149,6 +155,20 @@ export default {
},

methods: {
/**
* Fetch webdav node
*
* @return {Node}
*/
async getNode() {
const node = { path: this.path }
try {
this.node = await fetchNode(node)
logger.info('Fetched node:', { node: this.node })
} catch (error) {
logger.error('Error:', error)
}
},
/**
* Check if a share is valid before
* firing the request
Expand Down Expand Up @@ -247,6 +267,8 @@ export default {
: t('files_sharing', 'Folder "{path}" has been unshared', { path: this.share.path })
showSuccess(message)
this.$emit('remove:share', this.share)
await this.getNode()
emit('files:node:updated', this.node)
} catch (error) {
// re-open menu if error
this.open = true
Expand Down
18 changes: 18 additions & 0 deletions apps/files_sharing/src/services/WebdavClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { davGetClient, davGetDefaultPropfind, davResultToNode, davRootPath } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'
import type { Node } from '@nextcloud/files'

export const client = davGetClient()

export const fetchNode = async (node: Node): Promise<Node> => {
const propfindPayload = davGetDefaultPropfind()
const result = await client.stat(`${davRootPath}${node.path}`, {
details: true,
data: propfindPayload,
}) as ResponseDataDetailed<FileStat>
return davResultToNode(result.data)
}
14 changes: 10 additions & 4 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
</template>
<script>
import { emit } from '@nextcloud/event-bus'
import { getLanguage } from '@nextcloud/l10n'
import { Type as ShareType } from '@nextcloud/sharing'
Expand Down Expand Up @@ -276,6 +277,7 @@ import Share from '../models/Share.js'
import ShareRequests from '../mixins/ShareRequests.js'
import ShareTypes from '../mixins/ShareTypes.js'
import SharesMixin from '../mixins/SharesMixin.js'
import logger from '../services/logger.ts'
import {
ATOMIC_PERMISSIONS,
Expand Down Expand Up @@ -887,7 +889,7 @@ export default {
}
this.creating = true
const share = await this.addShare(incomingShare, this.fileInfo)
const share = await this.addShare(incomingShare)
this.creating = false
this.share = share
this.$emit('add:share', this.share)
Expand All @@ -896,6 +898,9 @@ export default {
this.queueUpdate(...permissionsAndAttributes)
}
await this.getNode()
emit('files:node:updated', this.node)
if (this.$refs.externalLinkActions?.length > 0) {
await Promise.allSettled(this.$refs.externalLinkActions.map((action) => {
if (typeof action.$children.at(0)?.onSave !== 'function') {
Expand All @@ -911,12 +916,11 @@ export default {
* Process the new share request
*
* @param {Share} share incoming share object
* @param {object} fileInfo file data
*/
async addShare(share, fileInfo) {
async addShare(share) {
console.debug('Adding a new share from the input for', share)
const path = this.path
try {
const path = (fileInfo.path + '/' + fileInfo.name).replace('//', '/')
const resultingShare = await this.createShare({
path,
shareType: share.shareType,
Expand All @@ -936,6 +940,8 @@ export default {
},
async removeShare() {
await this.onDelete()
await this.getNode()
emit('files:node:updated', this.node)
this.$emit('close-sharing-details')
},
/**
Expand Down

0 comments on commit 0281e6e

Please sign in to comment.