-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(systemtags): add setting to block non admin to create system tags #49514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b4e3eff
f7c46b6
abf840b
00fbbf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <!-- | ||
| - 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', 'If enabled, regular accounts will be restricted from creating new tags but will still be able to assign and remove them from their files.') }} | ||
| </p> | ||
|
|
||
| <NcCheckboxRadioSwitch type="switch" | ||
| :checked.sync="systemTagsCreationRestrictedToAdmin" | ||
| @update:checked="updateSystemTagsDefault"> | ||
| {{ t('settings', 'Restrict tag creation to admins only') }} | ||
| </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 { updateSystemTagsAdminRestriction } from '../services/api.js' | ||
|
|
||
| import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' | ||
|
|
||
| export default { | ||
| name: 'SystemTagsCreationControl', | ||
|
|
||
| components: { | ||
| NcCheckboxRadioSwitch, | ||
| }, | ||
|
|
||
| data() { | ||
| return { | ||
| // By default, system tags creation is not restricted to admins | ||
| systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1', | ||
| } | ||
| }, | ||
| methods: { | ||
| t, | ||
| async updateSystemTagsDefault(isRestricted: boolean) { | ||
| try { | ||
| const responseData = await updateSystemTagsAdminRestriction(isRestricted) | ||
| console.debug('updateSystemTagsDefault', responseData) | ||
| this.handleResponse({ | ||
| isRestricted, | ||
| status: responseData.ocs?.meta?.status, | ||
| }) | ||
| } catch (e) { | ||
| this.handleResponse({ | ||
| errorMessage: t('settings', 'Unable to update setting'), | ||
| error: e, | ||
| }) | ||
| } | ||
| }, | ||
|
|
||
| handleResponse({ isRestricted, status, errorMessage, error }) { | ||
| if (status === 'ok') { | ||
| this.systemTagsCreationRestrictedToAdmin = isRestricted | ||
| showSuccess(t('settings', `System tag creation is now ${isRestricted ? 'restricted to administrators' : 'allowed for everybody'}`)) | ||
| return | ||
| } | ||
|
|
||
| if (errorMessage) { | ||
| showError(errorMessage) | ||
| logger.error(errorMessage, error) | ||
| } | ||
| }, | ||
| }, | ||
| } | ||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ import { FileAction } from '@nextcloud/files' | |
| import { isPublicShare } from '@nextcloud/sharing/public' | ||
| import { spawnDialog } from '@nextcloud/dialogs' | ||
| import { t } from '@nextcloud/l10n' | ||
| import { getCurrentUser } from '@nextcloud/auth' | ||
| import { loadState } from '@nextcloud/initial-state' | ||
|
|
||
| import TagMultipleSvg from '@mdi/svg/svg/tag-multiple.svg?raw' | ||
|
|
||
|
|
@@ -34,6 +36,11 @@ export const action = new FileAction({ | |
|
|
||
| // If the app is disabled, the action is not available anyway | ||
| enabled(nodes) { | ||
| // By default, everyone can create system tags | ||
| if (loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1' && getCurrentUser()?.isAdmin !== true) { | ||
| return false | ||
| } | ||
|
Comment on lines
+40
to
+42
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nfebe why are we preventing the entire bulk tagging action if creation is disabled?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in followup |
||
|
|
||
| if (isPublicShare()) { | ||
| return false | ||
| } | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ SPDX-FileCopyrightText: jden <[email protected]> | |
| SPDX-FileCopyrightText: inherits developers | ||
| SPDX-FileCopyrightText: escape-html developers | ||
| SPDX-FileCopyrightText: defunctzombie | ||
| SPDX-FileCopyrightText: debounce developers | ||
| SPDX-FileCopyrightText: atomiks | ||
| SPDX-FileCopyrightText: Varun A P | ||
| SPDX-FileCopyrightText: Tobias Koppers @sokra | ||
|
|
@@ -114,6 +115,9 @@ This file is generated from multiple sources. Included packages: | |
| - @nextcloud/logger | ||
| - version: 3.0.2 | ||
| - license: GPL-3.0-or-later | ||
| - @nextcloud/password-confirmation | ||
| - version: 5.3.1 | ||
| - license: MIT | ||
| - @nextcloud/paths | ||
| - version: 2.2.1 | ||
| - license: GPL-3.0-or-later | ||
|
|
@@ -183,6 +187,9 @@ This file is generated from multiple sources. Included packages: | |
| - css-loader | ||
| - version: 7.1.2 | ||
| - license: MIT | ||
| - debounce | ||
| - version: 2.2.0 | ||
| - license: MIT | ||
| - define-data-property | ||
| - version: 1.1.4 | ||
| - license: MIT | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value is NOT stored as a boolean in the backend, but as an integer @Altahrim
