From 5820d00d35813055fe84ca9daf04cabadaa8dcd3 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 --- .../src/components/SystemTagForm.vue | 4 +- .../components/SystemTagsCreationControl.vue | 82 +++++++++++++++++++ apps/systemtags/src/services/api.ts | 25 +++++- .../src/views/SystemTagsSection.vue | 4 +- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 apps/systemtags/src/components/SystemTagsCreationControl.vue 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..89b2129457d74 --- /dev/null +++ b/apps/systemtags/src/components/SystemTagsCreationControl.vue @@ -0,0 +1,82 @@ + + + + + diff --git a/apps/systemtags/src/services/api.ts b/apps/systemtags/src/services/api.ts index ef44fa82daed8..4a840a8c01fc1 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 updateSystemTagCreationAllowed4All = 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 @@