-
-
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
5 changed files
with
109 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
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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
<!-- | ||
- 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', 'Allow only admins to create tags (enable or disable).') }} | ||
</p> | ||
|
||
<NcCheckboxRadioSwitch type="switch" | ||
:checked.sync="onlyAdminsCanCreateEnabled" | ||
@update:checked="updateSystemTagsDefault"> | ||
{{ 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 { updateOnlyAdminsCanCreateSystemTags } from '../services/api.js' | ||
|
||
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' | ||
|
||
export default { | ||
name: 'SystemTagsCreationControl', | ||
|
||
components: { | ||
NcCheckboxRadioSwitch, | ||
}, | ||
|
||
data() { | ||
return { | ||
onlyAdminsCanCreateEnabled: loadState('settings', 'onlyAdminsCanCreateSystemTags', '1') === '1', | ||
} | ||
}, | ||
methods: { | ||
t, | ||
async updateSystemTagsDefault(isEnabled: boolean) { | ||
try { | ||
const responseData = await updateOnlyAdminsCanCreateSystemTags(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.onlyAdminsCanCreateEnabled = 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