From 06626825b4ac553126bef9461ec15782e8ff6948 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Wed, 31 Jan 2024 20:38:34 +0100 Subject: [PATCH] Use `@nextcloud/capabilities` to obtain share api defaults - Remove redundant initial state added - Call `getCapabilities()` in share config file. Signed-off-by: fenn-cs --- .../lib/Listener/LoadSidebarListener.php | 7 ------- .../src/services/ConfigService.js | 20 ++++++++----------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/apps/files_sharing/lib/Listener/LoadSidebarListener.php b/apps/files_sharing/lib/Listener/LoadSidebarListener.php index 7787a348d3a5b..f82f60a170d54 100644 --- a/apps/files_sharing/lib/Listener/LoadSidebarListener.php +++ b/apps/files_sharing/lib/Listener/LoadSidebarListener.php @@ -48,12 +48,5 @@ public function handle(Event $event): void { } Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files'); - - $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 8afa41e80e5c3..59e84b707c1dc 100644 --- a/apps/files_sharing/src/services/ConfigService.js +++ b/apps/files_sharing/src/services/ConfigService.js @@ -21,14 +21,12 @@ * along with this program. If not, see . * */ - -import { loadState } from '@nextcloud/initial-state' import { getCapabilities } from '@nextcloud/capabilities' export default class Config { constructor() { - this._shareConfig = loadState('files_sharing', 'shareConfig', {}) + this._capabilities = getCapabilities() } /** @@ -39,7 +37,7 @@ export default class Config { * @memberof Config */ get defaultPermissions() { - return this._shareConfig.defaultPermissions + return this._capabilities.files_sharing?.default_permissions } /** @@ -50,7 +48,7 @@ export default class Config { * @memberof Config */ get isPublicUploadEnabled() { - return this._shareConfig.allowPublicUploads + return this._capabilities.files_sharing?.public.upload } /** @@ -225,11 +223,10 @@ export default class Config { * @memberof Config */ get isMailShareAllowed() { - const capabilities = getCapabilities() // eslint-disable-next-line camelcase - return capabilities?.files_sharing?.sharebymail !== undefined + return this._capabilities?.files_sharing?.sharebymail !== undefined // eslint-disable-next-line camelcase - && capabilities?.files_sharing?.public?.enabled === true + && this._capabilities?.files_sharing?.public?.enabled === true } /** @@ -284,7 +281,7 @@ export default class Config { * @memberof Config */ get isPasswordForMailSharesRequired() { - return (getCapabilities().files_sharing.sharebymail === undefined) ? false : getCapabilities().files_sharing.sharebymail.password.enforced + return (this._capabilities.files_sharing.sharebymail === undefined) ? false : this._capabilities.files_sharing.sharebymail.password.enforced } /** @@ -293,7 +290,7 @@ export default class Config { * @memberof Config */ get shouldAlwaysShowUnique() { - return (getCapabilities().files_sharing?.sharee?.always_show_unique === true) + return (this._capabilities.files_sharing?.sharee?.always_show_unique === true) } /** @@ -338,8 +335,7 @@ export default class Config { * @memberof Config */ get passwordPolicy() { - const capabilities = getCapabilities() - return capabilities.password_policy ? capabilities.password_policy : {} + return this._capabilities.password_policy ? this._capabilities.password_policy : {} } }