feat: phase 4 - frontend groups UI, permission-matrix, usePermission hook, field-level permissions tab, authStore permissions

This commit is contained in:
Agent Zero
2026-07-15 23:27:11 +02:00
parent beaca24480
commit bb6466b53d
7 changed files with 1055 additions and 30 deletions
+37
View File
@@ -0,0 +1,37 @@
import { useAuthStore } from '@/store/authStore';
export function usePermission() {
const user = useAuthStore((state) => state.user);
const hasPermission = (permission: string): boolean => {
if (user?.is_system_admin) return true;
const perms = user?.permissions || [];
// Check exact match and wildcards
for (const p of perms) {
if (p === permission) return true;
if (p === '*:*') return true;
const pParts = p.split(':');
const rParts = permission.split(':');
if (pParts.length === rParts.length) {
let match = true;
for (let i = 0; i < pParts.length; i++) {
if (pParts[i] !== '*' && pParts[i] !== rParts[i]) {
match = false;
break;
}
}
if (match) return true;
}
}
return false;
};
const hasFieldAccess = (module: string, field: string): 'hidden' | 'readonly' | 'read' => {
if (user?.is_system_admin) return 'read';
const fieldPerms = user?.field_permissions || {};
const modulePerms = fieldPerms[module] || {};
return modulePerms[field] || 'read';
};
return { hasPermission, hasFieldAccess };
}