From d1317e75409bdb2f37129ce07aee621bbe2b1a6c Mon Sep 17 00:00:00 2001
From: Vincent Petry <vincent@nextcloud.com>
Date: Fri, 26 Aug 2022 11:09:18 +0200
Subject: Remove copy in file actions when not allowed

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
---
 apps/files/js/fileactions.js   |  9 ++++++++-
 apps/files/js/fileinfomodel.js | 13 ++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

(limited to 'apps/files')

diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 9b86c6521ae..f342f21a4fb 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -673,6 +673,9 @@
 				displayName: function(context) {
 					var permissions = context.fileInfoModel.attributes.permissions;
 					if (permissions & OC.PERMISSION_UPDATE) {
+						if (!context.fileInfoModel.canDownload()) {
+							return t('files', 'Move');
+						}
 						return t('files', 'Move or copy');
 					}
 					return t('files', 'Copy');
@@ -685,7 +688,11 @@
 					var permissions = context.fileInfoModel.attributes.permissions;
 					var actions = OC.dialogs.FILEPICKER_TYPE_COPY;
 					if (permissions & OC.PERMISSION_UPDATE) {
-						actions = OC.dialogs.FILEPICKER_TYPE_COPY_MOVE;
+						if (!context.fileInfoModel.canDownload()) {
+							actions = OC.dialogs.FILEPICKER_TYPE_MOVE;
+						} else {
+							actions = OC.dialogs.FILEPICKER_TYPE_COPY_MOVE;
+						}
 					}
 					var dialogDir = context.dir;
 					if (typeof context.fileList.dirInfo.dirLastCopiedTo !== 'undefined') {
diff --git a/apps/files/js/fileinfomodel.js b/apps/files/js/fileinfomodel.js
index 83a8c62592b..79575109656 100644
--- a/apps/files/js/fileinfomodel.js
+++ b/apps/files/js/fileinfomodel.js
@@ -126,7 +126,18 @@
 				});
 
 			return deferred.promise();
-		}
+		},
+
+		canDownload: function() {
+			for (const i in this.attributes.shareAttributes) {
+				const attr = this.attributes.shareAttributes[i]
+				if (attr.scope === 'permissions' && attr.key === 'download') {
+					return attr.enabled
+				}
+			}
+
+			return true
+		},
 	});
 
 	if (!OCA.Files) {
-- 
cgit v1.2.3