Skip to content

Commit 0a3088e

Browse files
committed
feat(policy): initialize real workbench view mode from actor role
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent e2692c9 commit 0a3088e

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/views/Settings/PolicyWorkbench/useRealPolicyWorkbench.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
import axios from '@nextcloud/axios'
7+
import { getCurrentUser } from '@nextcloud/auth'
8+
import { loadState } from '@nextcloud/initial-state'
79
import { generateOcsUrl } from '@nextcloud/router'
810
import { computed, reactive, ref } from 'vue'
911
import { t } from '@nextcloud/l10n'
@@ -215,7 +217,14 @@ function toDraftSnapshot(draft: PolicyEditorDraft | null): string {
215217

216218
export function createRealPolicyWorkbenchState() {
217219
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)
219228
const activeSettingKey = ref<string | null>(null)
220229
const editorDraft = ref<PolicyEditorDraft | null>(null)
221230
const editorMode = ref<'create' | 'edit' | null>(null)
@@ -392,6 +401,10 @@ export function createRealPolicyWorkbenchState() {
392401
})
393402

394403
const createUserOverrideDisabledReason = computed(() => {
404+
if (viewMode.value === 'system-admin') {
405+
return null
406+
}
407+
395408
if (inheritedSystemRule.value?.allowChildOverride === false) {
396409
return t('libresign', 'Blocked by a higher-level rule that does not allow user exceptions.')
397410
}
@@ -590,6 +603,10 @@ export function createRealPolicyWorkbenchState() {
590603
void loadTargets(scope, query)
591604
}
592605

606+
function setViewMode(mode: 'system-admin' | 'group-admin') {
607+
viewMode.value = mode
608+
}
609+
593610
function closeSetting() {
594611
activeSettingKey.value = null
595612
editorDraft.value = null
@@ -855,6 +872,7 @@ export function createRealPolicyWorkbenchState() {
855872
updateDraftTargets,
856873
updateDraftAllowOverride,
857874
searchAvailableTargets,
875+
setViewMode,
858876
saveDraft,
859877
removeRule,
860878
resolveTargetLabel,

0 commit comments

Comments
 (0)