-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(systemtags): toggle for system tag creation in admin settings
Signed-off-by: nfebe <[email protected]>
- Loading branch information
Showing
4 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
apps/systemtags/src/components/SystemTagsCreationControl.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<div id="system-tags-creation-control"> | ||
<h4 class="inlineblock"> | ||
{{ t('settings', 'System tag creation') }} | ||
</h4> | ||
|
||
<p class="settings-hint"> | ||
{{ t('settings', 'Enable or disable system tag creation for non-admin users.') }} | ||
</p> | ||
|
||
<NcCheckboxRadioSwitch type="switch" | ||
:checked.sync="systemTagsCreationEnabled" | ||
@update:checked="onSystemTagsDefaultChange"> | ||
{{ t('settings', 'Enable') }} | ||
</NcCheckboxRadioSwitch> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { showError, showSuccess } from '@nextcloud/dialogs' | ||
import { t } from '@nextcloud/l10n' | ||
import logger from '../logger.ts' | ||
import { updateSystemTagCreationAllowed4All } from '../services/api.js' | ||
|
||
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' | ||
|
||
export default { | ||
name: 'SystemTagsCreationControl', | ||
|
||
components: { | ||
NcCheckboxRadioSwitch, | ||
}, | ||
|
||
data() { | ||
return { | ||
systemTagsCreationEnabled: loadState('settings', 'systemTagsEnabledByDefault', true), | ||
} | ||
}, | ||
|
||
methods: { | ||
t, | ||
async onSystemTagsDefaultChange(isEnabled: boolean) { | ||
await this.updateSystemTagsDefault(isEnabled) | ||
}, | ||
|
||
async updateSystemTagsDefault(isEnabled) { | ||
try { | ||
const responseData = await updateSystemTagCreationAllowed4All(isEnabled) | ||
console.debug('updateSystemTagsDefault', responseData) | ||
this.handleResponse({ | ||
isEnabled, | ||
status: responseData.ocs?.meta?.status, | ||
}) | ||
} catch (e) { | ||
this.handleResponse({ | ||
errorMessage: t('settings', 'Unable to update setting'), | ||
error: e, | ||
}) | ||
} | ||
}, | ||
|
||
handleResponse({ isEnabled, status, errorMessage, error }) { | ||
if (status === 'ok') { | ||
this.systemTagsCreationEnabled = isEnabled | ||
showSuccess(t('settings', `System tag creation is now ${isEnabled ? 'enabled' : 'disabled'} for non-admin users`)) | ||
return | ||
} | ||
|
||
if (errorMessage) { | ||
showError(errorMessage) | ||
logger.error(errorMessage, error) | ||
} | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters