-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix(systemtags): unify restrict_creation_to_admin handling #51288
base: master
Are you sure you want to change the base?
Changes from all commits
ef62e17
e41d716
58ca8d4
0e45f58
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 |
---|---|---|
|
@@ -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="canEditOrCreateTag ? t('systemtags', 'Search or create tag') : t('systemtags', 'Search tag')" | ||
data-cy-systemtags-picker-input> | ||
<TagIcon :size="20" /> | ||
</NcTextField> | ||
|
@@ -49,7 +49,8 @@ | |
</NcCheckboxRadioSwitch> | ||
|
||
<!-- Color picker --> | ||
<NcColorPicker :data-cy-systemtags-picker-tag-color="tag.id" | ||
<NcColorPicker v-if="canEditOrCreateTag" | ||
:data-cy-systemtags-picker-tag-color="tag.id" | ||
:value="`#${tag.color}`" | ||
:shown="openedPicker === tag.id" | ||
class="systemtags-picker__tag-color" | ||
|
@@ -67,8 +68,8 @@ | |
</li> | ||
|
||
<!-- Create new tag --> | ||
<li> | ||
<NcButton v-if="canCreateTag" | ||
<li v-if="canEditOrCreateTag && input.trim() !== ''"> | ||
<NcButton v-if="canEditOrCreateTag" | ||
:disabled="status === Status.CREATING_TAG" | ||
alignment="start" | ||
class="systemtags-picker__tag-create" | ||
|
@@ -88,7 +89,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') }} | ||
{{ canEditOrCreateTag ? 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" /> | ||
|
@@ -127,7 +128,9 @@ | |
|
||
import { defineComponent } from 'vue' | ||
import { emit } from '@nextcloud/event-bus' | ||
import { getCurrentUser } from '@nextcloud/auth' | ||
import { getLanguage, n, t } from '@nextcloud/l10n' | ||
import { loadState } from '@nextcloud/initial-state' | ||
import { showError, showInfo } from '@nextcloud/dialogs' | ||
import debounce from 'debounce' | ||
import domPurify from 'dompurify' | ||
|
@@ -150,8 +153,8 @@ | |
import TagIcon from 'vue-material-design-icons/Tag.vue' | ||
|
||
import { createTag, fetchTag, fetchTags, getTagObjects, setTagObjects, updateTag } from '../services/api' | ||
import { getNodeSystemTags, setNodeSystemTags } from '../utils' | ||
import { elementColor, invertTextColor, isDarkModeEnabled } from '../utils/colorUtils' | ||
import { getNodeSystemTags, setNodeSystemTags } from '../utils' | ||
import logger from '../logger.ts' | ||
|
||
const debounceUpdateTag = debounce(updateTag, 500) | ||
|
@@ -170,6 +173,8 @@ | |
DONE = 'done', | ||
} | ||
|
||
const restrictSystemTagsCreationToAdmin = loadState<false|true>('systemtags', 'restrictSystemTagsCreationToAdmin', false) === true | ||
|
||
export default defineComponent({ | ||
name: 'SystemTagPicker', | ||
|
||
|
@@ -204,6 +209,8 @@ | |
emit, | ||
Status, | ||
t, | ||
// Either tag creation is not restricted to admins or the current user is an admin | ||
canEditOrCreateTag: !restrictSystemTagsCreationToAdmin || getCurrentUser()?.isAdmin, | ||
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. name clash with line 251 |
||
} | ||
}, | ||
|
||
|
@@ -241,7 +248,7 @@ | |
return this.toAdd.length > 0 || this.toRemove.length > 0 | ||
}, | ||
|
||
canCreateTag(): boolean { | ||
canEditOrCreateTag(): boolean { | ||
return this.input.trim() !== '' | ||
&& !this.tags.some(tag => tag.displayName.trim().toLocaleLowerCase() === this.input.trim().toLocaleLowerCase()) | ||
}, | ||
|
@@ -364,6 +371,10 @@ | |
}) | ||
return acc | ||
}, {} as TagListCount) as TagListCount | ||
|
||
if (!this.canEditOrCreateTag) { | ||
logger.debug('System tag creation is restricted to admins and the current user is not an admin') | ||
} | ||
}, | ||
|
||
methods: { | ||
|
@@ -422,6 +433,12 @@ | |
}, | ||
|
||
async onNewTag() { | ||
if (!this.canEditOrCreateTag) { | ||
// Should not happen ™ | ||
showError(t('systemtags', 'Only admins can create new tags')) | ||
return | ||
} | ||
|
||
this.status = Status.CREATING_TAG | ||
try { | ||
const payload: Tag = { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
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. Simple types here (should be
Suggested change
|
||||||
if (systemTagsCreationRestrictedToAdmin) { | ||||||
showError(t('systemtags', 'System admin disabled tag creation. You can only use existing ones.')) | ||||||
return | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,13 +10,13 @@ | |||||||||
</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.') }} | ||||||||||
{{ t('settings', 'If enabled, regular accounts will be restricted from editing or 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') }} | ||||||||||
{{ t('settings', 'Restrict tag edition and creation to admins only') }} | ||||||||||
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. I think it is
Suggested change
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. I checked and you're right! What a weird phrazing 😁
Suggested change
|
||||||||||
</NcCheckboxRadioSwitch> | ||||||||||
</div> | ||||||||||
</template> | ||||||||||
|
@@ -25,8 +25,9 @@ | |||||||||
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 logger from '../logger.ts' | ||||||||||
|
||||||||||
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch' | ||||||||||
|
||||||||||
|
@@ -37,14 +38,19 @@ export default { | |||||||||
NcCheckboxRadioSwitch, | ||||||||||
}, | ||||||||||
|
||||||||||
setup() { | ||||||||||
return { | ||||||||||
t, | ||||||||||
} | ||||||||||
}, | ||||||||||
|
||||||||||
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, | ||||||||||
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.
Suggested change
|
||||||||||
} | ||||||||||
}, | ||||||||||
methods: { | ||||||||||
t, | ||||||||||
async updateSystemTagsDefault(isRestricted: boolean) { | ||||||||||
try { | ||||||||||
const responseData = await updateSystemTagsAdminRestriction(isRestricted) | ||||||||||
|
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.