Skip to content

Commit 009c700

Browse files
committed
test(policy): cover role-specific user override behavior in real workbench state
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent d6fed17 commit 009c700

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

src/tests/views/Settings/PolicyWorkbench/useRealPolicyWorkbench.spec.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ import { createL10nMock } from '../../../testHelpers/l10n.js'
88

99
vi.mock('@nextcloud/l10n', () => createL10nMock())
1010

11+
const { currentUserState } = vi.hoisted(() => ({
12+
currentUserState: {
13+
isAdmin: true,
14+
},
15+
}))
16+
17+
vi.mock('@nextcloud/auth', () => ({
18+
getCurrentUser: vi.fn(() => currentUserState),
19+
}))
20+
21+
vi.mock('@nextcloud/initial-state', () => ({
22+
loadState: vi.fn((_app, key: string, defaultValue: unknown) => {
23+
if (key === 'config') {
24+
return { can_manage_group_policies: true }
25+
}
26+
27+
return defaultValue
28+
}),
29+
}))
30+
1131
const { axiosGet } = vi.hoisted(() => ({
1232
axiosGet: vi.fn(),
1333
}))
@@ -48,6 +68,7 @@ import { createRealPolicyWorkbenchState } from '../../../../views/Settings/Polic
4868

4969
describe('useRealPolicyWorkbench', () => {
5070
beforeEach(() => {
71+
currentUserState.isAdmin = true
5172
axiosGet.mockReset()
5273
saveSystemPolicy.mockReset()
5374
saveGroupPolicy.mockReset()
@@ -348,7 +369,7 @@ describe('useRealPolicyWorkbench', () => {
348369
expect(state.summary?.baseSource).toBe('Global default')
349370
})
350371

351-
it('exposes disabled reason for user exceptions when parent override blocks lower layers', async () => {
372+
it('allows system-admin to create user exceptions even when a group blocks inheritance', async () => {
352373
getPolicy.mockReturnValue({ effectiveValue: 'parallel', sourceScope: 'global' })
353374

354375
const state = createRealPolicyWorkbenchState()
@@ -358,7 +379,28 @@ describe('useRealPolicyWorkbench', () => {
358379
state.updateDraftAllowOverride(false)
359380
await state.saveDraft()
360381

382+
expect(state.viewMode).toBe('system-admin')
383+
expect(state.createUserOverrideDisabledReason).toBeNull()
384+
385+
state.startEditor({ scope: 'user' })
386+
expect(state.editorDraft?.scope).toBe('user')
387+
})
388+
389+
it('blocks user exceptions for group-admin when a group rule disables inheritance', async () => {
390+
getPolicy.mockReturnValue({ effectiveValue: 'parallel', sourceScope: 'global' })
391+
392+
const state = createRealPolicyWorkbenchState()
393+
state.setViewMode('group-admin')
394+
state.openSetting('signature_flow')
395+
state.startEditor({ scope: 'group' })
396+
state.updateDraftTargets(['finance'])
397+
state.updateDraftAllowOverride(false)
398+
await state.saveDraft()
399+
361400
expect(state.createUserOverrideDisabledReason).toContain('Blocked by the Finance group rule')
401+
402+
state.startEditor({ scope: 'user' })
403+
expect(state.editorDraft).toBeNull()
362404
})
363405

364406
it('allows creating group rule when no system rule is set', () => {

0 commit comments

Comments
 (0)