gdias 1 week ago
parent
commit
767de6e7e8
2 changed files with 26 additions and 6 deletions
  1. 9 6
      src/routes/(app)/+layout.svelte
  2. 17 0
      src/routes/(app)/dashboard/executive/+page.svelte

+ 9 - 6
src/routes/(app)/+layout.svelte

@@ -20,8 +20,7 @@
 		CreditCard,
 		HelpCircle,
 		PieChart,
-		Users,
-		ShieldCheck
+		Users
 	} from 'lucide-svelte';
 	import { goto } from '$app/navigation';
 	import logoWhite from '$lib/assets/images/nettown_white_logo.svg';
@@ -60,17 +59,21 @@
 	});
 
 	const navItems = [
+		{ name: 'Dashboard Executivo', href: '/dashboard/executive', icon: PieChart, adminOnly: true },
 		{ name: 'Visão Geral', href: '/dashboard', icon: LayoutDashboard },
 		{ name: 'Interações', href: '/dashboard/interactions', icon: MessageSquare },
 		{ name: 'Análise de Sentimento', href: '/dashboard/analytics', icon: BarChart2 },
 		{ name: 'Personas', href: '/dashboard/personas', icon: UserRound },
 		{ name: 'Evolução', href: '/dashboard/evolucao', icon: TrendingUp },
-		{ name: 'Configurações', href: '/dashboard/settings', icon: Settings },
-		{ name: 'Dashboard Executivo', href: '/dashboard/executive', icon: PieChart },
 		{ name: 'Agentes', href: '/dashboard/operators', icon: Users },
-		{ name: 'Config. SLA', href: '/dashboard/sla', icon: ShieldCheck }
+		{ name: 'Configurações', href: '/dashboard/settings', icon: Settings }
 	];
 
+	// Itens com `adminOnly` só aparecem para usuários com papel admin.
+	const visibleNavItems = $derived(
+		navItems.filter((item) => !item.adminOnly || $auth.user?.user_role === 'admin')
+	);
+
 	function handleLogout() {
 		auth.logout();
 		goto('/login');
@@ -188,7 +191,7 @@
 			>
 				{isSidebarCollapsed ? 'Menu' : 'Menu Principal'}
 			</div>
-			{#each navItems as item}
+			{#each visibleNavItems as item}
 				{@const Icon = item.icon}
 				{@const isActive = isNavItemActive(item.href)}
 				<a

+ 17 - 0
src/routes/(app)/dashboard/executive/+page.svelte

@@ -13,13 +13,30 @@
 		BookOpen
 	} from 'lucide-svelte';
 	import { onMount } from 'svelte';
+	import { goto } from '$app/navigation';
 	import { api } from '$lib/core/api/client.js';
+	import { auth } from '$lib/core/stores/auth';
 
 	let isLoading = $state(true);
 	let loadError = $state('');
 	let data = $state(null);
 
+	// Guard por papel: apenas admin acessa o Dashboard Executivo. Assim que a
+	// sessão estiver reidratada, redireciona quem não for admin (o backend
+	// também bloqueia com 403, esta é a defesa do lado do cliente).
+	$effect(() => {
+		if ($auth.initialized && $auth.user?.user_role !== 'admin') {
+			goto('/dashboard');
+		}
+	});
+
 	async function loadExecutive() {
+		// Evita a chamada (e o 403) quando o usuário não é admin.
+		if ($auth.user?.user_role !== 'admin') {
+			isLoading = false;
+			return;
+		}
+
 		isLoading = true;
 		loadError = '';
 		try {