diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2025-03-05 09:49:19 +0100 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2025-03-06 11:29:57 +0100 |
commit | 29405f0964ce5b7bade2f8fe14f33bcd3563e9bf (patch) | |
tree | a737776f59e860b912c51da9d1afd9aeddf9cc24 | |
parent | 4c92c91980c18f0e2d0394825e322a466c2654bc (diff) | |
download | nextcloud-server-29405f0964ce5b7bade2f8fe14f33bcd3563e9bf.tar.gz nextcloud-server-29405f0964ce5b7bade2f8fe14f33bcd3563e9bf.zip |
fix(systemtags): unify restrict_creation_to_admin handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
7 files changed, 41 insertions, 15 deletions
diff --git a/apps/settings/lib/Settings/Admin/Server.php b/apps/settings/lib/Settings/Admin/Server.php index 8071d812076..c0f29ce8f34 100644 --- a/apps/settings/lib/Settings/Admin/Server.php +++ b/apps/settings/lib/Settings/Admin/Server.php @@ -55,7 +55,7 @@ class Server implements IDelegatedSettings { $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config)); // Basic settings - $this->initialStateService->provideInitialState('restrictSystemTagsCreationToAdmin', $this->appConfig->getValueString('systemtags', 'restrict_creation_to_admin', 'true')); + $this->initialStateService->provideInitialState('restrictSystemTagsCreationToAdmin', $this->appConfig->getValueBool('systemtags', 'restrict_creation_to_admin', false)); return new TemplateResponse('settings', 'settings/admin/server', [ 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(), diff --git a/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php b/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php index 74fa6bd03fe..15d06394889 100644 --- a/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/apps/systemtags/lib/Listeners/BeforeTemplateRenderedListener.php @@ -9,18 +9,29 @@ namespace OCA\SystemTags\Listeners; use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent; use OCA\SystemTags\AppInfo\Application; +use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IAppConfig; use OCP\Util; /** * @template-implements IEventListener<BeforeTemplateRenderedEvent> */ class BeforeTemplateRenderedListener implements IEventListener { + public function __construct( + private IAppConfig $appConfig, + private IInitialState $initialState, + ) { + } + public function handle(Event $event): void { if (!$event instanceof BeforeTemplateRenderedEvent) { return; } Util::addInitScript(Application::APP_ID, 'init'); + + $restrictSystemTagsCreationToAdmin = $this->appConfig->getValueBool(Application::APP_ID, 'restrict_creation_to_admin', false); + $this->initialState->provideInitialState('restrictSystemTagsCreationToAdmin', $restrictSystemTagsCreationToAdmin); } } diff --git a/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php b/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php index 7d00bf44fc4..87e50a48075 100644 --- a/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php +++ b/apps/systemtags/lib/Listeners/LoadAdditionalScriptsListener.php @@ -9,18 +9,29 @@ namespace OCA\SystemTags\Listeners; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\SystemTags\AppInfo\Application; +use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IAppConfig; use OCP\Util; /** * @template-implements IEventListener<LoadAdditionalScriptsEvent> */ class LoadAdditionalScriptsListener implements IEventListener { + public function __construct( + private IAppConfig $appConfig, + private IInitialState $initialState, + ) { + } + public function handle(Event $event): void { if (!$event instanceof LoadAdditionalScriptsEvent) { return; } Util::addInitScript(Application::APP_ID, 'init'); + + $restrictSystemTagsCreationToAdmin = $this->appConfig->getValueBool(Application::APP_ID, 'restrict_creation_to_admin', false); + $this->initialState->provideInitialState('restrictSystemTagsCreationToAdmin', $restrictSystemTagsCreationToAdmin); } } diff --git a/apps/systemtags/src/components/SystemTagPicker.vue b/apps/systemtags/src/components/SystemTagPicker.vue index e47395d34c5..26a50c82e1f 100644 --- a/apps/systemtags/src/components/SystemTagPicker.vue +++ b/apps/systemtags/src/components/SystemTagPicker.vue @@ -25,7 +25,7 @@ <!-- Search or create input --> <div class="systemtags-picker__input"> <NcTextField :value.sync="input" - :label="t('systemtags', 'Search or create tag')" + :label="canCreateTag ? t('systemtags', 'Search or create tag') : t('systemtags', 'Search tag')" data-cy-systemtags-picker-input> <TagIcon :size="20" /> </NcTextField> @@ -67,7 +67,7 @@ </li> <!-- Create new tag --> - <li> + <li v-if="canCreateTag"> <NcButton v-if="canCreateTag" :disabled="status === Status.CREATING_TAG" alignment="start" @@ -88,7 +88,7 @@ <!-- Note --> <div class="systemtags-picker__note"> <NcNoteCard v-if="!hasChanges" type="info"> - {{ t('systemtags', 'Select or create tags to apply to all selected files') }} + {{ canCreateTag ? t('systemtags', 'Select or create tags to apply to all selected files'): t('systemtags', 'Select tags to apply to all selected files') }} </NcNoteCard> <NcNoteCard v-else type="info"> <span v-html="statusMessage" /> @@ -153,6 +153,8 @@ import { createTag, fetchTag, fetchTags, getTagObjects, setTagObjects, updateTag import { getNodeSystemTags, setNodeSystemTags } from '../utils' import { elementColor, invertTextColor, isDarkModeEnabled } from '../utils/colorUtils' import logger from '../logger.ts' +import { loadState } from '@nextcloud/initial-state' +import { getCurrentUser } from '@nextcloud/auth' const debounceUpdateTag = debounce(updateTag, 500) const mainBackgroundColor = getComputedStyle(document.body) @@ -170,6 +172,8 @@ enum Status { DONE = 'done', } +const restrictSystemTagsCreationToAdmin = loadState<false|true>('settings', 'restrictSystemTagsCreationToAdmin', false) === true + export default defineComponent({ name: 'SystemTagPicker', @@ -204,6 +208,8 @@ export default defineComponent({ emit, Status, t, + // Either tag creation is not restricted to admins or the current user is an admin + canCreateTag: !restrictSystemTagsCreationToAdmin || getCurrentUser()?.isAdmin, } }, @@ -422,6 +428,12 @@ export default defineComponent({ }, async onNewTag() { + if (!this.canCreateTag) { + // Should not happen ™ + showError(t('systemtags', 'Only admins can create new tags')) + return + } + this.status = Status.CREATING_TAG try { const payload: Tag = { diff --git a/apps/systemtags/src/components/SystemTags.vue b/apps/systemtags/src/components/SystemTags.vue index 105321ee1e4..08dbb59d1c9 100644 --- a/apps/systemtags/src/components/SystemTags.vue +++ b/apps/systemtags/src/components/SystemTags.vue @@ -189,7 +189,8 @@ export default Vue.extend({ this.sortedTags.unshift(createdTag) this.selectedTags.push(createdTag) } catch (error) { - if(loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1') { + const systemTagsCreationRestrictedToAdmin = loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true + if (systemTagsCreationRestrictedToAdmin) { showError(t('systemtags', 'System admin disabled tag creation. You can only use existing ones.')) return } diff --git a/apps/systemtags/src/components/SystemTagsCreationControl.vue b/apps/systemtags/src/components/SystemTagsCreationControl.vue index f6d6f0b9457..e8305991983 100644 --- a/apps/systemtags/src/components/SystemTagsCreationControl.vue +++ b/apps/systemtags/src/components/SystemTagsCreationControl.vue @@ -40,7 +40,7 @@ export default { data() { return { // By default, system tags creation is not restricted to admins - systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1', + systemTagsCreationRestrictedToAdmin: loadState<true|false>('settings', 'restrictSystemTagsCreationToAdmin', false) === true, } }, methods: { diff --git a/apps/systemtags/src/files_actions/bulkSystemTagsAction.ts b/apps/systemtags/src/files_actions/bulkSystemTagsAction.ts index cdb1025f094..0f33650d588 100644 --- a/apps/systemtags/src/files_actions/bulkSystemTagsAction.ts +++ b/apps/systemtags/src/files_actions/bulkSystemTagsAction.ts @@ -9,13 +9,9 @@ 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' -const restrictSystemTagsCreationToAdmin = loadState<'0'|'1'>('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1' - /** * Spawn a dialog to add or remove tags from multiple nodes. * @param nodes Nodes to modify tags for @@ -38,11 +34,6 @@ 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 (restrictSystemTagsCreationToAdmin && getCurrentUser()?.isAdmin !== true) { - return false - } - if (isPublicShare()) { return false } |