From 996f6850654e855657e19472003dfd4cf33f9aca Mon Sep 17 00:00:00 2001 From: ypratama Date: Wed, 2 Sep 2026 13:55:23 +0700 Subject: [PATCH] Fix: Server action getAgents now correctly falls back to environment KNOWN_SITES when SITE_UUID is all --- src/lib/actions/agentsMongo.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/actions/agentsMongo.ts b/src/lib/actions/agentsMongo.ts index 22e331e..cb5af8b 100644 --- a/src/lib/actions/agentsMongo.ts +++ b/src/lib/actions/agentsMongo.ts @@ -12,8 +12,17 @@ export async function fetchAgentsFromMongo( const isCompanyRole = companyRoles.includes(user.role); const filter: any = {}; - // Hanya apply site_uuid filter untuk NON-company roles - if (SITE_UUID && !isCompanyRole) filter.site_uuid = { $in: [SITE_UUID, 'global'] }; + + if (!isCompanyRole && SITE_UUID) { + if (SITE_UUID === 'all') { + const envSites = (process.env.BACKONE_SITE_UUIDS || process.env.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'] }; + } + } if (user.role === 'AGENT_VIEWER' && user.agent_uuid) { filter.uuid = user.agent_uuid;