|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | import axios from '@nextcloud/axios' |
| 7 | +import { getCurrentUser } from '@nextcloud/auth' |
| 8 | +import { loadState } from '@nextcloud/initial-state' |
7 | 9 | import { generateOcsUrl } from '@nextcloud/router' |
8 | 10 | import { computed, reactive, ref } from 'vue' |
9 | 11 | import { t } from '@nextcloud/l10n' |
@@ -215,7 +217,14 @@ function toDraftSnapshot(draft: PolicyEditorDraft | null): string { |
215 | 217 |
|
216 | 218 | export function createRealPolicyWorkbenchState() { |
217 | 219 | const policiesStore = usePoliciesStore() |
218 | | - const viewMode = ref<'system-admin' | 'group-admin'>('system-admin') |
| 220 | + const currentUser = getCurrentUser() |
| 221 | + const config = loadState<{ can_manage_group_policies?: boolean }>('libresign', 'config', {}) |
| 222 | + const initialViewMode: 'system-admin' | 'group-admin' = currentUser?.isAdmin |
| 223 | + ? 'system-admin' |
| 224 | + : config.can_manage_group_policies |
| 225 | + ? 'group-admin' |
| 226 | + : 'system-admin' |
| 227 | + const viewMode = ref<'system-admin' | 'group-admin'>(initialViewMode) |
219 | 228 | const activeSettingKey = ref<string | null>(null) |
220 | 229 | const editorDraft = ref<PolicyEditorDraft | null>(null) |
221 | 230 | const editorMode = ref<'create' | 'edit' | null>(null) |
@@ -392,6 +401,10 @@ export function createRealPolicyWorkbenchState() { |
392 | 401 | }) |
393 | 402 |
|
394 | 403 | const createUserOverrideDisabledReason = computed(() => { |
| 404 | + if (viewMode.value === 'system-admin') { |
| 405 | + return null |
| 406 | + } |
| 407 | + |
395 | 408 | if (inheritedSystemRule.value?.allowChildOverride === false) { |
396 | 409 | return t('libresign', 'Blocked by a higher-level rule that does not allow user exceptions.') |
397 | 410 | } |
@@ -590,6 +603,10 @@ export function createRealPolicyWorkbenchState() { |
590 | 603 | void loadTargets(scope, query) |
591 | 604 | } |
592 | 605 |
|
| 606 | + function setViewMode(mode: 'system-admin' | 'group-admin') { |
| 607 | + viewMode.value = mode |
| 608 | + } |
| 609 | + |
593 | 610 | function closeSetting() { |
594 | 611 | activeSettingKey.value = null |
595 | 612 | editorDraft.value = null |
@@ -855,6 +872,7 @@ export function createRealPolicyWorkbenchState() { |
855 | 872 | updateDraftTargets, |
856 | 873 | updateDraftAllowOverride, |
857 | 874 | searchAvailableTargets, |
| 875 | + setViewMode, |
858 | 876 | saveDraft, |
859 | 877 | removeRule, |
860 | 878 | resolveTargetLabel, |
|
0 commit comments