Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Hide some actions based on node permissions and share attributes
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Feb 21, 2024
commit 18b32e892c58c37872d683199575ad4e41b8edaf
39 changes: 35 additions & 4 deletions apps/files_versions/src/components/Version.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</div>
</template>
<template #actions>
<NcActionButton v-if="enableLabeling"
<NcActionButton v-if="enableLabeling && hasUpdatePermissions"
:close-after-click="true"
@click="labelUpdate">
<template #icon>
Expand All @@ -62,23 +62,24 @@
</template>
{{ t('files_versions', 'Compare to current version') }}
</NcActionButton>
<NcActionButton v-if="!isCurrent"
<NcActionButton v-if="!isCurrent && hasUpdatePermissions"
:close-after-click="true"
@click="restoreVersion">
<template #icon>
<BackupRestore :size="22" />
</template>
{{ t('files_versions', 'Restore version') }}
</NcActionButton>
<NcActionLink :href="downloadURL"
<NcActionLink v-if="isDownloadable"
:href="downloadURL"
:close-after-click="true"
:download="downloadURL">
<template #icon>
<Download :size="22" />
</template>
{{ t('files_versions', 'Download version') }}
</NcActionLink>
<NcActionButton v-if="!isCurrent && enableDeletion"
<NcActionButton v-if="!isCurrent && enableDeletion && hasDeletePermissions"
:close-after-click="true"
@click="deleteVersion">
<template #icon>
Expand Down Expand Up @@ -106,6 +107,9 @@ import { translate as t } from '@nextcloud/l10n'
import { joinPaths } from '@nextcloud/paths'
import { getRootUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import { Permission } from '@nextcloud/files'

import { hasPermissions } from '../../../files_sharing/src/lib/SharePermissionsToolBox.js'

export default {
name: 'Version',
Expand Down Expand Up @@ -224,6 +228,33 @@ export default {
enableDeletion() {
return this.capabilities.files.version_deletion === true
},

/** @return {boolean} */
hasDeletePermissions() {
return hasPermissions(this.fileInfo.permissions, Permission.DELETE)
},

/** @return {boolean} */
hasUpdatePermissions() {
return hasPermissions(this.fileInfo.permissions, Permission.UPDATE)
},

/** @return {boolean} */
isDownloadable() {
if ((this.fileInfo.permissions & Permission.READ) === 0) {
return false
}

// If the mount type is a share, ensure it got download permissions.
if (this.fileInfo.mountType === 'shared') {
const downloadAttribute = this.fileInfo.shareAttributes.find((attribute) => attribute.scope === 'permissions' && attribute.key === 'download')
if (downloadAttribute !== undefined && downloadAttribute.enabled === false) {
return false
}
}

return true
},
},
methods: {
labelUpdate() {
Expand Down
4 changes: 2 additions & 2 deletions dist/files_versions-files_versions.js

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dist/files_versions-files_versions.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @copyright 2022 Louis Chmn <[email protected]>
*
* @author Louis Chmn <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @copyright Copyright (c) 2021 John Molakvoæ <[email protected]>
*
Expand Down
2 changes: 1 addition & 1 deletion dist/files_versions-files_versions.js.map

Large diffs are not rendered by default.