|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<template> |
| 7 | + <div id="system-tags-creation-control"> |
| 8 | + <h4 class="inlineblock"> |
| 9 | + {{ t('settings', 'System tag creation') }} |
| 10 | + </h4> |
| 11 | + |
| 12 | + <p class="settings-hint"> |
| 13 | + {{ t('settings', 'If enabled, regular accounts will be restricted from creating new tags but will still be able to assign and remove them from their files.') }} |
| 14 | + </p> |
| 15 | + |
| 16 | + <NcCheckboxRadioSwitch type="switch" |
| 17 | + :checked.sync="systemTagsCreationRestrictedToAdmin" |
| 18 | + @update:checked="updateSystemTagsDefault"> |
| 19 | + {{ t('settings', 'Restrict tag creation to admins only') }} |
| 20 | + </NcCheckboxRadioSwitch> |
| 21 | + </div> |
| 22 | +</template> |
| 23 | + |
| 24 | +<script lang="ts"> |
| 25 | +import { loadState } from '@nextcloud/initial-state' |
| 26 | +import { showError, showSuccess } from '@nextcloud/dialogs' |
| 27 | +import { t } from '@nextcloud/l10n' |
| 28 | +import logger from '../logger.ts' |
| 29 | +import { updateSystemTagsAdminRestriction } from '../services/api.js' |
| 30 | +
|
| 31 | +import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' |
| 32 | +
|
| 33 | +export default { |
| 34 | + name: 'SystemTagsCreationControl', |
| 35 | +
|
| 36 | + components: { |
| 37 | + NcCheckboxRadioSwitch, |
| 38 | + }, |
| 39 | +
|
| 40 | + data() { |
| 41 | + return { |
| 42 | + // By default, system tags creation is not restricted to admins |
| 43 | + systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1', |
| 44 | + } |
| 45 | + }, |
| 46 | + methods: { |
| 47 | + t, |
| 48 | + async updateSystemTagsDefault(isRestricted: boolean) { |
| 49 | + try { |
| 50 | + const responseData = await updateSystemTagsAdminRestriction(isRestricted) |
| 51 | + console.debug('updateSystemTagsDefault', responseData) |
| 52 | + this.handleResponse({ |
| 53 | + isRestricted, |
| 54 | + status: responseData.ocs?.meta?.status, |
| 55 | + }) |
| 56 | + } catch (e) { |
| 57 | + this.handleResponse({ |
| 58 | + errorMessage: t('settings', 'Unable to update setting'), |
| 59 | + error: e, |
| 60 | + }) |
| 61 | + } |
| 62 | + }, |
| 63 | +
|
| 64 | + handleResponse({ isRestricted, status, errorMessage, error }) { |
| 65 | + if (status === 'ok') { |
| 66 | + this.systemTagsCreationRestrictedToAdmin = isRestricted |
| 67 | + showSuccess(t('settings', `System tag creation is now ${isRestricted ? 'restricted to administrators' : 'allowed for everybody'}`)) |
| 68 | + return |
| 69 | + } |
| 70 | +
|
| 71 | + if (errorMessage) { |
| 72 | + showError(errorMessage) |
| 73 | + logger.error(errorMessage, error) |
| 74 | + } |
| 75 | + }, |
| 76 | + }, |
| 77 | +} |
| 78 | +</script> |
0 commit comments