Add frontend audit admin auth semantics

This commit is contained in:
RWDai
2026-05-13 18:12:46 +08:00
parent 337d0af136
commit e818443841
2 changed files with 23 additions and 0 deletions

View File

@@ -105,4 +105,21 @@ describe('auth store logout', () => {
expect(store.user).toBeNull()
expect(store.token).toBeNull()
})
it('separates admin access from admin operations for audit administrators', () => {
const store = useAuthStore()
store.user = {
id: 'audit-1',
username: 'auditor',
role: 'audit_admin',
is_active: true,
created_at: '2026-03-16T00:00:00Z',
}
expect(store.isAdmin).toBe(false)
expect(store.isAuditAdmin).toBe(true)
expect(store.canAccessAdmin).toBe(true)
expect(store.canOperateAdmin).toBe(false)
})
})

View File

@@ -32,6 +32,9 @@ export const useAuthStore = defineStore('auth', () => {
}
}
const isAdmin = computed(() => user.value?.role === 'admin')
const isAuditAdmin = computed(() => user.value?.role === 'audit_admin')
const canAccessAdmin = computed(() => isAdmin.value || isAuditAdmin.value)
const canOperateAdmin = computed(() => isAdmin.value)
async function login(email: string, password: string, authType: 'local' | 'ldap' = 'local') {
loading.value = true
@@ -114,6 +117,9 @@ export const useAuthStore = defineStore('auth', () => {
error,
isAuthenticated,
isAdmin,
isAuditAdmin,
canAccessAdmin,
canOperateAdmin,
login,
logout,
applyExternalLogout,