From 95cdc39cd70aa897502f711155d59c285947ec04 Mon Sep 17 00:00:00 2001 From: nfebe Date: Mon, 6 Jan 2025 20:06:21 +0100 Subject: [PATCH] feat(systemtags): toggle for system tag creation in admin settings Signed-off-by: nfebe --- apps/settings/lib/Settings/Admin/Server.php | 3 + .../src/components/SystemTagForm.vue | 4 +- .../components/SystemTagsCreationControl.vue | 77 +++++++++++++++++++ apps/systemtags/src/services/api.ts | 25 +++++- .../src/views/SystemTagsSection.vue | 4 +- 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 apps/systemtags/src/components/SystemTagsCreationControl.vue diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php index 0f253ddf6b1f3..39ad604384df1 100644 --- a/apps/settings/lib/Settings/Admin/Server.php +++ b/apps/settings/lib/Settings/Admin/Server.php @@ -53,6 +53,9 @@ public function getForm() { $this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled()); $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config)); + // Basic settings + $this->initialStateService->provideInitialState('onlyAdminsCanCreateSystemTags', $this->appConfig->getValueString('systemtags', 'only_admins_can_create', 'true')); + return new TemplateResponse('settings', 'settings/admin/server', [ 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(), ], ''); diff --git a/apps/systemtags/src/components/SystemTagForm.vue b/apps/systemtags/src/components/SystemTagForm.vue index 86e2fc8e1084c..9cd2b454715de 100644 --- a/apps/systemtags/src/components/SystemTagForm.vue +++ b/apps/systemtags/src/components/SystemTagForm.vue @@ -9,9 +9,9 @@ aria-labelledby="system-tag-form-heading" @submit.prevent="handleSubmit" @reset="reset"> -

+

{{ t('systemtags', 'Create or edit tags') }} -

+
diff --git a/apps/systemtags/src/components/SystemTagsCreationControl.vue b/apps/systemtags/src/components/SystemTagsCreationControl.vue new file mode 100644 index 0000000000000..356ccef1f1c11 --- /dev/null +++ b/apps/systemtags/src/components/SystemTagsCreationControl.vue @@ -0,0 +1,77 @@ + + + + + diff --git a/apps/systemtags/src/services/api.ts b/apps/systemtags/src/services/api.ts index ef44fa82daed8..3173d23290e5f 100644 --- a/apps/systemtags/src/services/api.ts +++ b/apps/systemtags/src/services/api.ts @@ -7,13 +7,14 @@ import type { FileStat, ResponseDataDetailed, WebDAVClientError } from 'webdav' import type { ServerTag, Tag, TagWithId } from '../types.js' import axios from '@nextcloud/axios' -import { generateUrl } from '@nextcloud/router' +import { generateUrl, generateOcsUrl } from '@nextcloud/router' import { t } from '@nextcloud/l10n' import { davClient } from './davClient.js' import { formatTag, parseIdFromLocation, parseTags } from '../utils' import logger from '../logger.ts' import { emit } from '@nextcloud/event-bus' +import { confirmPassword } from '@nextcloud/password-confirmation' export const fetchTagsPayload = ` @@ -203,3 +204,25 @@ export const setTagObjects = async function(tag: TagWithId, type: string, object }, }) } + +type OcsResponse = { + ocs: NonNullable, +} + +export const updateOnlyAdminsCanCreateSystemTags = async (isAllowed: boolean): Promise => { + // Convert to string for compatibility + const isAllowedString = isAllowed ? '1' : '0' + + const url = generateOcsUrl('/apps/provisioning_api/api/v1/config/apps/{appId}/{key}', { + appId: 'systemtags', + key: 'only_admins_can_create', + }) + + await confirmPassword() + + const res = await axios.post(url, { + value: isAllowedString, + }) + + return res.data +} diff --git a/apps/systemtags/src/views/SystemTagsSection.vue b/apps/systemtags/src/views/SystemTagsSection.vue index 9745ab188afc2..8e2d6b53e2af9 100644 --- a/apps/systemtags/src/views/SystemTagsSection.vue +++ b/apps/systemtags/src/views/SystemTagsSection.vue @@ -6,10 +6,10 @@