From 8e3a248f2b3d883dbf9d855e3f85c904a6fd04ff Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Mon, 22 Jan 2024 14:49:57 +0100 Subject: [PATCH] Consider admin defaults when creating shares The current share logic always uses the default `BUNDLED_PERMISSIONS.ALL` which includes everything. This commit updates share creation logic to use `defaultPermissions` if set by admin for the creation of new shares. Signed-off-by: fenn-cs --- .../lib/Listener/LoadSidebarListener.php | 1 + apps/files_sharing/src/services/ConfigService.js | 11 +++++++++++ apps/files_sharing/src/views/SharingDetailsTab.vue | 6 ++++++ lib/private/Share20/Manager.php | 10 ++++++++++ lib/public/Share/IManager.php | 8 ++++++++ 5 files changed, 36 insertions(+) diff --git a/apps/files_sharing/lib/Listener/LoadSidebarListener.php b/apps/files_sharing/lib/Listener/LoadSidebarListener.php index b88c3ccf0d8ba..c271d1db71fd9 100644 --- a/apps/files_sharing/lib/Listener/LoadSidebarListener.php +++ b/apps/files_sharing/lib/Listener/LoadSidebarListener.php @@ -51,6 +51,7 @@ public function handle(Event $event): void { $shareConfig = [ 'allowPublicUploads' => $this->shareManager->shareApiLinkAllowPublicUpload(), + 'defaultPermissions' => $this->shareManager->shareApiDefaultPermissions(), ]; $this->initialState->provideInitialState('shareConfig', $shareConfig); diff --git a/apps/files_sharing/src/services/ConfigService.js b/apps/files_sharing/src/services/ConfigService.js index d1d99e7be7a5c..8afa41e80e5c3 100644 --- a/apps/files_sharing/src/services/ConfigService.js +++ b/apps/files_sharing/src/services/ConfigService.js @@ -31,6 +31,17 @@ export default class Config { this._shareConfig = loadState('files_sharing', 'shareConfig', {}) } + /** + * Get default share permissions, if any + * + * @return {boolean} + * @readonly + * @memberof Config + */ + get defaultPermissions() { + return this._shareConfig.defaultPermissions + } + /** * Is public upload allowed on link shares ? * diff --git a/apps/files_sharing/src/views/SharingDetailsTab.vue b/apps/files_sharing/src/views/SharingDetailsTab.vue index 8893ee984a3c6..d838c25ec2f23 100644 --- a/apps/files_sharing/src/views/SharingDetailsTab.vue +++ b/apps/files_sharing/src/views/SharingDetailsTab.vue @@ -754,9 +754,15 @@ export default { } if (this.isNewShare) { if (this.isPublicShare) { + // The default sharing permission for public shares should probably + // come from the backend via the `this.config`. this.sharingPermission = BUNDLED_PERMISSIONS.READ_ONLY.toString() } else { this.sharingPermission = BUNDLED_PERMISSIONS.ALL.toString() + // TEMP COMMENT FOR REVIEW : So apparently, switching to the default permissions + // as below is what is required, however, the default permissions does not neccesarily + // mean "Allow editing"... + // this.sharingPermission = this.config.defaultPermissions } } else { diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 31f3924f05381..72b86b1eaaa6e 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -47,6 +47,7 @@ use OCA\Files_Sharing\AppInfo\Application; use OCA\Files_Sharing\ISharedStorage; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Constants; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -1791,6 +1792,15 @@ public function shareApiEnabled() { return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes'; } + /** + * Return default share permissions if set + * + * @return int + */ + public function shareApidefaultPermissions(): int { + return (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL); + } + /** * Is public link sharing enabled * diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 9ac224ed7ef30..6d90d7904858e 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -310,6 +310,14 @@ public function newShare(); */ public function shareApiEnabled(); + /** + * Get default share permissions set by admin + * + * @return int + * @since 27.0.0 + */ + public function shareApidefaultPermissions(): int; + /** * Is public link sharing enabled *