rights system

This commit is contained in:
Matthias Hochmeister
2026-03-23 12:12:21 +01:00
parent a575b61d26
commit fa10467f21
8 changed files with 32 additions and 90 deletions

View File

@@ -31,7 +31,7 @@ import {
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { Navigate } from 'react-router-dom';
import DashboardLayout from '../components/dashboard/DashboardLayout';
import { useAuth } from '../contexts/AuthContext';
import { usePermissionContext } from '../contexts/PermissionContext';
import { useNotification } from '../contexts/NotificationContext';
import { settingsApi } from '../services/settings';
@@ -61,11 +61,11 @@ const ADMIN_INTERVAL_OPTIONS = [
];
function AdminSettings() {
const { user } = useAuth();
const { hasPermission } = usePermissionContext();
const { showSuccess, showError } = useNotification();
const queryClient = useQueryClient();
const isAdmin = user?.groups?.includes('dashboard_admin') ?? false;
const canAccess = hasPermission('admin:write');
// State for link collections
const [linkCollections, setLinkCollections] = useState<LinkCollection[]>([]);
@@ -86,7 +86,7 @@ function AdminSettings() {
const { data: settings, isLoading } = useQuery({
queryKey: ['admin-settings'],
queryFn: () => settingsApi.getAll(),
enabled: isAdmin,
enabled: canAccess,
});
// Initialize state from fetched settings
@@ -197,7 +197,7 @@ function AdminSettings() {
reader.readAsDataURL(file);
};
if (!isAdmin) {
if (!canAccess) {
return <Navigate to="/dashboard" replace />;
}