From 6558dc9383e407cfe76391bdd1b1f80accc6ec56 Mon Sep 17 00:00:00 2001
From: nfebe <fenn25.fn@gmail.com>
Date: Tue, 29 Apr 2025 00:29:01 +0100
Subject: fix(files_sharing): Create `download` attribute when toggling
 checkbox if missing

Previously, toggling the checkbox did not create the 'download' attribute if it was missing,
causing it to become unresponsive after a page reload. Now, setShareAttribute ensures the
attribute is updated or created correctly.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
---
 apps/files_sharing/src/views/SharingDetailsTab.vue | 30 ++++++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

(limited to 'apps/files_sharing/src/views/SharingDetailsTab.vue')

diff --git a/apps/files_sharing/src/views/SharingDetailsTab.vue b/apps/files_sharing/src/views/SharingDetailsTab.vue
index a1dc5c78459..76478d447b7 100644
--- a/apps/files_sharing/src/views/SharingDetailsTab.vue
+++ b/apps/files_sharing/src/views/SharingDetailsTab.vue
@@ -430,11 +430,7 @@ export default {
 				return this.share.attributes.find(attr => attr.key === 'download')?.value || false
 			},
 			set(checked) {
-				// Find the 'download' attribute and update its value
-				const downloadAttr = this.share.attributes.find(attr => attr.key === 'download')
-				if (downloadAttr) {
-					downloadAttr.value = checked
-				}
+				this.setShareAttribute('permissions', 'download', checked)
 			},
 		},
 		/**
@@ -744,6 +740,30 @@ export default {
 	},
 
 	methods: {
+		/**
+		 * Set a share attribute on the current share
+		 * @param {string} scope The attribute scope
+		 * @param {string} key The attribute key
+		 * @param {boolean} value The value
+		 */
+		 setShareAttribute(scope, key, value) {
+			if (!this.share.attributes) {
+				this.$set(this.share, 'attributes', [])
+			}
+
+			const attribute = this.share.attributes
+				.find((attr) => attr.scope === scope || attr.key === key)
+
+			if (attribute) {
+				attribute.value = value
+			} else {
+				this.share.attributes.push({
+					scope,
+					key,
+					value,
+				})
+			}
+		},
 		updateAtomicPermissions({
 			isReadChecked = this.hasRead,
 			isEditChecked = this.canEdit,
-- 
cgit v1.2.3

