mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
fix(systemtags): unify restrict_creation_to_admin handling
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
parent
4c92c91980
commit
29405f0964
7 changed files with 41 additions and 15 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue