From e7c9870e594d33c06b1bad32914ad546ed038763 Mon Sep 17 00:00:00 2001 From: ypratama Date: Wed, 2 Sep 2026 16:48:55 +0700 Subject: [PATCH] Fix: Properly handle global site_uuid and dynamic env for BACKONE_SITE_UUIDS --- src/app/(dashboard)/agents/UptimeStatsCards.tsx | 2 +- src/lib/actions/agentsMongo.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/(dashboard)/agents/UptimeStatsCards.tsx b/src/app/(dashboard)/agents/UptimeStatsCards.tsx index d282188..1048fe6 100644 --- a/src/app/(dashboard)/agents/UptimeStatsCards.tsx +++ b/src/app/(dashboard)/agents/UptimeStatsCards.tsx @@ -21,7 +21,7 @@ export default function UptimeStatsCards({
- TOTAL AGENTS (V6) + TOTAL AGENTS {totalAgents}
diff --git a/src/lib/actions/agentsMongo.ts b/src/lib/actions/agentsMongo.ts index 0efcf3b..51a96e0 100644 --- a/src/lib/actions/agentsMongo.ts +++ b/src/lib/actions/agentsMongo.ts @@ -13,13 +13,20 @@ export async function fetchAgentsFromMongo( const filter: any = {}; - if (!isCompanyRole) { - // BRUTE FORCE OVERRIDE for SUPER_ADMIN: - // ALWAYS force the filter to this exact site + global to prove if this code runs. - filter.site_uuid = { $in: ['6681452d_9cae_4ff4_8ae8_0d504774265e', 'global'] }; + if (!isCompanyRole && SITE_UUID) { + if (SITE_UUID === 'all' || SITE_UUID === 'test-site' || SITE_UUID === 'default' || SITE_UUID === 'global') { + const dynamicEnv = process['env']; + const envSites = (dynamicEnv.BACKONE_SITE_UUIDS || dynamicEnv.BACKONE_SITE_UUID || '').split(',').map(s => s.trim()).filter(Boolean); + + if (envSites.length > 0) { + filter.site_uuid = { $in: [...envSites, 'global'] }; + } + } else { + filter.site_uuid = { $in: [SITE_UUID, 'global'] }; + } } - console.log("V5 EXECUTING! BRUTE FORCED FILTER:", JSON.stringify(filter)); + if (user.role === 'AGENT_VIEWER' && user.agent_uuid) { filter.uuid = user.agent_uuid;