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.
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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<Record<IntegrationTab, IntegrationTabRole>> = {
|
||||
api: 'owner',
|
||||
}
|
||||
|
||||
export type IntegrationPreviewIcon =
|
||||
| { type: 'icon'; name: string }
|
||||
| { type: 'emoji'; value: string }
|
||||
|
||||
@@ -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<IntegrationTab>('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) || '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user