From f8accb2610229303e49b1b1a2938315b6fd38f22 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 30 Jun 2026 20:33:48 +0800 Subject: [PATCH] fix(frontend): hide API integration tab for non-owner tenants Gate the integrations API tab and sidebar preview behind owner role, matching Settings and the /api-principal-config backend guard, so users without permission no longer see a 403 error when opening the tab. --- frontend/src/components/menu.vue | 11 +++++- frontend/src/config/integrations.ts | 7 ++++ .../views/integrations/IntegrationsModal.vue | 38 +++++++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue index 1f35a33e..ababf30c 100644 --- a/frontend/src/components/menu.vue +++ b/frontend/src/components/menu.vue @@ -257,10 +257,17 @@ import UserMenu from '@/components/UserMenu.vue'; import TenantSelector from '@/components/TenantSelector.vue'; import { useI18n } from 'vue-i18n'; import { getSystemInfo } from '@/api/system'; -import { INTEGRATION_PREVIEW_ITEMS } from '@/config/integrations'; +import { INTEGRATION_PREVIEW_ITEMS, INTEGRATION_TAB_MIN_ROLE } from '@/config/integrations'; const chatResources = useChatResourcesStore(); -const integrationPreviewItems = INTEGRATION_PREVIEW_ITEMS; +const integrationPreviewItems = computed(() => + INTEGRATION_PREVIEW_ITEMS.filter((item) => { + const min = INTEGRATION_TAB_MIN_ROLE[item.key]; + if (!min) return true; + if (authStore.canAccessAllTenants) return true; + return authStore.hasRole(min); + }), +); // Platform logos reused from IMChannelsOverviewPanel — keeps the session list // visually consistent with the channels admin view. import wecomLogo from '@/assets/img/im/wecom.svg'; diff --git a/frontend/src/config/integrations.ts b/frontend/src/config/integrations.ts index c9bb2b55..70d06e17 100644 --- a/frontend/src/config/integrations.ts +++ b/frontend/src/config/integrations.ts @@ -7,6 +7,13 @@ export type IntegrationTab = 'im' | 'embed' | 'api' | 'chrome' | 'claw' export const INTEGRATION_TABS: IntegrationTab[] = ['im', 'embed', 'api', 'chrome', 'claw'] +/** Aligns with Settings.vue SECTION_MIN_ROLE.api and router.go g.Owner() on /api-principal-config. */ +export type IntegrationTabRole = 'viewer' | 'contributor' | 'admin' | 'owner' + +export const INTEGRATION_TAB_MIN_ROLE: Partial> = { + api: 'owner', +} + export type IntegrationPreviewIcon = | { type: 'icon'; name: string } | { type: 'emoji'; value: string } diff --git a/frontend/src/views/integrations/IntegrationsModal.vue b/frontend/src/views/integrations/IntegrationsModal.vue index 5c2d55df..27502a41 100644 --- a/frontend/src/views/integrations/IntegrationsModal.vue +++ b/frontend/src/views/integrations/IntegrationsModal.vue @@ -84,11 +84,18 @@ import AgentEmbedChannelPanel from '@/components/AgentEmbedChannelPanel.vue'; import ApiIntegrationSettings from '@/views/integrations/ApiIntegrationSettings.vue'; import ChromeExtensionLanding from '@/views/integrations/ChromeExtensionLanding.vue'; import ClawSkillLanding from '@/views/integrations/ClawSkillLanding.vue'; -import { INTEGRATION_PREVIEW_ITEMS, INTEGRATION_TABS, type IntegrationTab } from '@/config/integrations'; +import { + INTEGRATION_PREVIEW_ITEMS, + INTEGRATION_TAB_MIN_ROLE, + INTEGRATION_TABS, + type IntegrationTab, +} from '@/config/integrations'; +import { useAuthStore } from '@/stores/auth'; const { t } = useI18n(); const route = useRoute(); const router = useRouter(); +const authStore = useAuthStore(); const currentSection = ref('im'); const filterAgentId = ref(''); @@ -99,19 +106,34 @@ const isLandingSection = computed( () => currentSection.value === 'chrome' || currentSection.value === 'claw', ); +function canSeeTab(tab: IntegrationTab): boolean { + const min = INTEGRATION_TAB_MIN_ROLE[tab]; + if (!min) return true; + if (authStore.canAccessAllTenants) return true; + return authStore.hasRole(min); +} + const navItems = computed(() => - INTEGRATION_PREVIEW_ITEMS.map((item) => ({ - key: item.key, - icon: item.icon.type === 'icon' ? item.icon.name : '', - emoji: item.icon.type === 'emoji' ? item.icon.value : undefined, - label: t(`integrations.tabs.${item.key}`), - })), + INTEGRATION_PREVIEW_ITEMS + .filter((item) => canSeeTab(item.key)) + .map((item) => ({ + key: item.key, + icon: item.icon.type === 'icon' ? item.icon.name : '', + emoji: item.icon.type === 'emoji' ? item.icon.value : undefined, + label: t(`integrations.tabs.${item.key}`), + })), ); function applyRouteQuery() { const tab = route.query.tab as string; - if (INTEGRATION_TABS.includes(tab as IntegrationTab)) { + if (INTEGRATION_TABS.includes(tab as IntegrationTab) && canSeeTab(tab as IntegrationTab)) { currentSection.value = tab as IntegrationTab; + } else if (INTEGRATION_TABS.includes(tab as IntegrationTab)) { + currentSection.value = navItems.value[0]?.key ?? 'im'; + if (visible.value) syncRouteQuery(); + } else if (navItems.value.length > 0 && !canSeeTab(currentSection.value)) { + currentSection.value = navItems.value[0].key; + if (visible.value) syncRouteQuery(); } filterAgentId.value = (route.query.agentId as string) || ''; }