Skip to content

Commit

Permalink
feat: Update UI to respect tag creation permissions
Browse files Browse the repository at this point in the history
Added support for the `only_admin_can_create` flag in system tags.
The UI now hides the option to create tags when this flag is enabled, ensuring compliance with admin settings.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Jan 22, 2025
1 parent f7c46b6 commit abf840b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/systemtags/src/components/SystemTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import {
setTagForFile,
} from '../services/files.js'

import { loadState } from '@nextcloud/initial-state'

import type { Tag, TagWithId } from '../types.js'

export default Vue.extend({
Expand Down Expand Up @@ -188,6 +190,10 @@ export default Vue.extend({
this.sortedTags.unshift(createdTag)
this.selectedTags.push(createdTag)
} catch (error) {
if(loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1') {
showError(t('systemtags', 'System admin disabled tag creation. You can only use existing ones.'))
return
}
showError(t('systemtags', 'Failed to create tag'))
}
this.loading = false
Expand Down
3 changes: 2 additions & 1 deletion apps/systemtags/src/components/SystemTagsCreationControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default {

data() {
return {
systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '1') === '1',
// By default, system tags creation is not restricted to admins
systemTagsCreationRestrictedToAdmin: loadState('settings', 'restrictSystemTagsCreationToAdmin', '0') === '1',
}
},
methods: {
Expand Down
7 changes: 7 additions & 0 deletions apps/systemtags/src/files_actions/bulkSystemTagsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
}

if (isPublicShare()) {
return false
}
Expand Down

0 comments on commit abf840b

Please sign in to comment.