feat(frontend): tenant switcher in user menu + role-aware UI gates
PR 4 of #1303 wired the backend X-Tenant-ID gate to accept active tenant_members rows (not just superusers), but the frontend never exposed a switcher to ordinary multi-tenant members. The only existing component, the sidebar TenantSelector, is gated to canAccessAllTenants and queries /tenants/search — both wrong for a Contributor that an Owner just invited to a second tenant. This PR closes both gaps: 1. Switcher entry inside the user-avatar dropdown - New "Switch Tenant" submenu in UserMenu.vue, hover-triggered, with a teleported floating panel (same pattern as the existing IM overview submenu so the layout/animation read consistently). - Data source is authStore.memberships, populated by /auth/login. No new API call: the JWT-issued claim already enumerates every tenant the user is an active member of plus their role. - Visibility: only shown when memberships.length > 1. Cluster superusers keep using the sidebar TenantSelector for "any tenant in the system" — the avatar entry is the curated "tenants I'm a member of" list. - Click writes via authStore.setSelectedTenant(...), then window.location.reload() so every cached store / open SSE stream / in-flight request is re-keyed under the new tenant. Same approach as the existing TenantSelector. 2. Role-aware UI gates on high-friction surfaces - authStore exposes a new hasRole(min: 'viewer'|'contributor'| 'admin'|'owner') helper (numeric ordering matches middleware/rbac.go) so v-if gates line up with the server-side matrix instead of duplicating ['admin','owner'].includes(...). - Gates applied per the PR 4 audit: * KB list "Create" button — Contributor+ * Agent list "Create" button — Contributor+ * Model / VectorStore / WebSearch / MCP — Add+Edit+Delete+Test are Admin+ (and the per-card action menus return [] for non-Admins so the dropdowns disappear, not just disable). * Parser / Storage engine drawers — Save button Admin+ * Retrieval settings — slider/selector inputs disabled for non-Admins (the form auto-saves on change, no dedicated Save). * API key reset — Owner+ (Reset is the highest-impact tenant op). * IM channel toggle/edit/delete + Add — Admin+. Same in the avatar-menu IM submenu (toggle disabled for non-Admins). - KB / agent per-card edit/delete already key off kb.isMine / agent.isMine + (for builtins) is_builtin; that path is left as-is. 3. i18n - Three new keys under tenant.switcher.* in en-US/zh-CN/ko-KR/ru-RU. - Role labels reuse the existing tenantMember.role.* bundle from PR 3, with a "show raw role" fallback if a locale lacks the key. The server is the source of truth for every gated action — these changes only hide buttons that would 403, never grant new authority. authStore.hasRole and currentTenantRole both carry a SECURITY note saying they read from localStorage and are UI-rendering-only. vue-tsc --build error count unchanged from baseline (90, all pre-existing issues unrelated to this PR).
This commit is contained in:
@@ -32,9 +32,11 @@
|
|||||||
<t-switch
|
<t-switch
|
||||||
:value="channel.enabled"
|
:value="channel.enabled"
|
||||||
size="small"
|
size="small"
|
||||||
|
:disabled="!authStore.hasRole('admin')"
|
||||||
@change="handleToggle(channel)"
|
@change="handleToggle(channel)"
|
||||||
/>
|
/>
|
||||||
<t-dropdown
|
<t-dropdown
|
||||||
|
v-if="authStore.hasRole('admin')"
|
||||||
trigger="click"
|
trigger="click"
|
||||||
placement="bottom-right"
|
placement="bottom-right"
|
||||||
:options="[
|
:options="[
|
||||||
@@ -77,7 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add button -->
|
<!-- Add button -->
|
||||||
<t-button theme="default" variant="dashed" block @click="showCreateDialog = true" class="add-btn">
|
<t-button v-if="authStore.hasRole('admin')" theme="default" variant="dashed" block @click="showCreateDialog = true" class="add-btn">
|
||||||
<t-icon name="add" />
|
<t-icon name="add" />
|
||||||
{{ $t('agentEditor.im.addChannel') }}
|
{{ $t('agentEditor.im.addChannel') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -429,8 +431,10 @@ import {
|
|||||||
} from '@/api/agent';
|
} from '@/api/agent';
|
||||||
import { listKnowledgeBases } from '@/api/knowledge-base';
|
import { listKnowledgeBases } from '@/api/knowledge-base';
|
||||||
import type { IMChannel } from '@/api/agent';
|
import type { IMChannel } from '@/api/agent';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
agentId: string;
|
agentId: string;
|
||||||
|
|||||||
@@ -84,6 +84,7 @@
|
|||||||
:value="ch.enabled"
|
:value="ch.enabled"
|
||||||
size="small"
|
size="small"
|
||||||
:loading="togglingId === ch.id"
|
:loading="togglingId === ch.id"
|
||||||
|
:disabled="!authStore.hasRole('admin')"
|
||||||
@change="handleToggle(ch)"
|
@change="handleToggle(ch)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -98,6 +99,7 @@ import { ref, watch } from 'vue';
|
|||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { MessagePlugin } from 'tdesign-vue-next';
|
import { MessagePlugin } from 'tdesign-vue-next';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import {
|
import {
|
||||||
listAllIMChannels,
|
listAllIMChannels,
|
||||||
listAgents,
|
listAgents,
|
||||||
@@ -138,6 +140,7 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
const channels = ref<IMChannelOverview[]>([]);
|
const channels = ref<IMChannelOverview[]>([]);
|
||||||
const agentMap = ref<Map<string, CustomAgent>>(new Map());
|
const agentMap = ref<Map<string, CustomAgent>>(new Map());
|
||||||
|
|||||||
@@ -71,6 +71,23 @@
|
|||||||
<t-icon name="setting" class="menu-icon" />
|
<t-icon name="setting" class="menu-icon" />
|
||||||
<span>{{ $t('general.allSettings') }}</span>
|
<span>{{ $t('general.allSettings') }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- Tenant switcher submenu — only meaningful when the user belongs
|
||||||
|
to more than one tenant. Superusers (canAccessAllTenants) keep
|
||||||
|
using the sidebar TenantSelector for "any tenant in the system";
|
||||||
|
the entry here is the curated "tenants I'm a member of" list,
|
||||||
|
matching what the backend memberships claim covers. -->
|
||||||
|
<div
|
||||||
|
v-if="showTenantSwitcher"
|
||||||
|
ref="tenantMenuItemRef"
|
||||||
|
class="menu-item menu-item--submenu"
|
||||||
|
:class="{ 'is-open': tenantSubmenuOpen }"
|
||||||
|
@mouseenter="showTenantSubmenu"
|
||||||
|
@mouseleave="scheduleHideTenantSubmenu"
|
||||||
|
>
|
||||||
|
<t-icon name="swap" class="menu-icon" />
|
||||||
|
<span class="menu-item-label">{{ $t('tenant.switcher.menuLabel') }}</span>
|
||||||
|
<t-icon name="chevron-right" class="menu-chevron" />
|
||||||
|
</div>
|
||||||
<div class="menu-divider"></div>
|
<div class="menu-divider"></div>
|
||||||
<div class="menu-item" @click="openClawhubSkill">
|
<div class="menu-item" @click="openClawhubSkill">
|
||||||
<span class="menu-icon menu-icon--emoji" role="img" :aria-label="$t('common.clawhubSkill')">🦞</span>
|
<span class="menu-icon menu-icon--emoji" role="img" :aria-label="$t('common.clawhubSkill')">🦞</span>
|
||||||
@@ -143,6 +160,47 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
|
||||||
|
<!-- Tenant switcher floating panel — shares the same teleport rationale
|
||||||
|
as the IM submenu. Lists every tenant the user is an active member
|
||||||
|
of (from the JWT-issued memberships claim cached in authStore). -->
|
||||||
|
<Teleport to="body">
|
||||||
|
<div
|
||||||
|
v-if="tenantSubmenuOpen"
|
||||||
|
class="tenant-submenu-floating"
|
||||||
|
:style="tenantSubmenuStyle"
|
||||||
|
@mouseenter="showTenantSubmenu"
|
||||||
|
@mouseleave="scheduleHideTenantSubmenu"
|
||||||
|
>
|
||||||
|
<div class="tenant-submenu-header">
|
||||||
|
{{ $t('tenant.switcher.menuLabel') }}
|
||||||
|
</div>
|
||||||
|
<div class="tenant-submenu-list">
|
||||||
|
<div
|
||||||
|
v-for="m in switchableMemberships"
|
||||||
|
:key="m.tenant_id"
|
||||||
|
class="tenant-submenu-item"
|
||||||
|
:class="{ 'is-current': isCurrentTenant(m.tenant_id) }"
|
||||||
|
@click="switchToTenant(m)"
|
||||||
|
>
|
||||||
|
<div class="tenant-submenu-item-avatar" :class="{ 'is-current': isCurrentTenant(m.tenant_id) }">
|
||||||
|
{{ tenantInitial(m) }}
|
||||||
|
</div>
|
||||||
|
<div class="tenant-submenu-item-info">
|
||||||
|
<span class="tenant-submenu-item-name">{{ tenantDisplayName(m) }}</span>
|
||||||
|
<span class="tenant-submenu-item-role">{{ formatRole(m.role) }}</span>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
v-if="isCurrentTenant(m.tenant_id)"
|
||||||
|
class="tenant-submenu-item-badge"
|
||||||
|
>{{ $t('tenant.switcher.currentBadge') }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="switchableMemberships.length === 0" class="tenant-submenu-empty">
|
||||||
|
{{ $t('tenant.switcher.empty') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Teleport>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -165,11 +223,15 @@ const authStore = useAuthStore()
|
|||||||
|
|
||||||
const menuRef = ref<HTMLElement>()
|
const menuRef = ref<HTMLElement>()
|
||||||
const imMenuItemRef = ref<HTMLElement>()
|
const imMenuItemRef = ref<HTMLElement>()
|
||||||
|
const tenantMenuItemRef = ref<HTMLElement>()
|
||||||
const menuVisible = ref(false)
|
const menuVisible = ref(false)
|
||||||
const imSubmenuOpen = ref(false)
|
const imSubmenuOpen = ref(false)
|
||||||
const imSubmenuStyle = ref<Record<string, string>>({})
|
const imSubmenuStyle = ref<Record<string, string>>({})
|
||||||
|
const tenantSubmenuOpen = ref(false)
|
||||||
|
const tenantSubmenuStyle = ref<Record<string, string>>({})
|
||||||
const hasActiveIMChannels = ref(false)
|
const hasActiveIMChannels = ref(false)
|
||||||
let imSubmenuHideTimer: ReturnType<typeof setTimeout> | null = null
|
let imSubmenuHideTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let tenantSubmenuHideTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
// 用户信息
|
// 用户信息
|
||||||
const userInfo = ref({
|
const userInfo = ref({
|
||||||
@@ -236,9 +298,129 @@ const scheduleHideIMSubmenu = () => {
|
|||||||
|
|
||||||
const closeAll = () => {
|
const closeAll = () => {
|
||||||
imSubmenuOpen.value = false
|
imSubmenuOpen.value = false
|
||||||
|
tenantSubmenuOpen.value = false
|
||||||
menuVisible.value = false
|
menuVisible.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Tenant switcher submenu ----------
|
||||||
|
//
|
||||||
|
// Same hover-driven submenu pattern as the IM panel above; data comes from
|
||||||
|
// authStore.memberships (populated by /auth/login). PR 4 of #1303 relaxed
|
||||||
|
// the X-Tenant-ID gate in middleware/auth.go to accept active membership
|
||||||
|
// rows, so flipping authStore.selectedTenantId here is enough — the next
|
||||||
|
// page reload re-issues every request with the new header and the server
|
||||||
|
// resolves the role server-side.
|
||||||
|
type Membership = {
|
||||||
|
tenant_id: number
|
||||||
|
tenant_name?: string
|
||||||
|
role: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// switchableMemberships is the curated list shown in the dropdown. We keep
|
||||||
|
// the active tenant in there (with a "Current" badge) so the user has a
|
||||||
|
// single place to glance at "where am I right now"; clicking the current
|
||||||
|
// row is a no-op (handled in switchToTenant).
|
||||||
|
const switchableMemberships = computed<Membership[]>(() => {
|
||||||
|
return authStore.memberships ?? []
|
||||||
|
})
|
||||||
|
|
||||||
|
// Rendered only when there's something to switch *to*. Multi-tenant members
|
||||||
|
// (memberships.length > 1) need it for tenant switching; superusers keep
|
||||||
|
// using the sidebar TenantSelector for the "any tenant in the system" case,
|
||||||
|
// so we don't double-show the entry there.
|
||||||
|
const showTenantSwitcher = computed(() => {
|
||||||
|
return switchableMemberships.value.length > 1
|
||||||
|
})
|
||||||
|
|
||||||
|
const isCurrentTenant = (id: number) => {
|
||||||
|
const active = authStore.effectiveTenantId
|
||||||
|
return active != null && Number(active) === Number(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
const tenantDisplayName = (m: Membership) =>
|
||||||
|
m.tenant_name && m.tenant_name.trim() !== '' ? m.tenant_name : `#${m.tenant_id}`
|
||||||
|
|
||||||
|
const tenantInitial = (m: Membership) => {
|
||||||
|
const name = tenantDisplayName(m).trim()
|
||||||
|
return (name.charAt(0) || '?').toUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatRole = (role: string) => {
|
||||||
|
// Roles match the backend enum: viewer/contributor/admin/owner. The
|
||||||
|
// i18n bundle already carries human labels under tenantMember.role.*
|
||||||
|
// (see PR 3); reuse those rather than inventing a new key namespace.
|
||||||
|
const key = `tenantMember.role.${role}`
|
||||||
|
const label = t(key)
|
||||||
|
// Fallback when the locale doesn't have the key: show the raw role.
|
||||||
|
return label === key ? role : label
|
||||||
|
}
|
||||||
|
|
||||||
|
const switchToTenant = (m: Membership) => {
|
||||||
|
if (isCurrentTenant(m.tenant_id)) {
|
||||||
|
closeAll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Treat switching back to the user's home tenant as "clear the
|
||||||
|
// override" so request.ts stops attaching X-Tenant-ID. This mirrors
|
||||||
|
// what TenantSelector.vue does in selectTenant().
|
||||||
|
const homeTenantId = authStore.tenant?.id ? Number(authStore.tenant.id) : null
|
||||||
|
if (homeTenantId !== null && homeTenantId === m.tenant_id) {
|
||||||
|
authStore.setSelectedTenant(null, null)
|
||||||
|
} else {
|
||||||
|
authStore.setSelectedTenant(m.tenant_id, tenantDisplayName(m))
|
||||||
|
}
|
||||||
|
closeAll()
|
||||||
|
MessagePlugin.success(t('tenant.switchSuccess'))
|
||||||
|
// Hard reload so every cached store / open SSE stream / in-flight
|
||||||
|
// request gets re-keyed under the new tenant. Same approach as
|
||||||
|
// TenantSelector.vue.
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload()
|
||||||
|
}, 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
const showTenantSubmenu = () => {
|
||||||
|
if (tenantSubmenuHideTimer) {
|
||||||
|
clearTimeout(tenantSubmenuHideTimer)
|
||||||
|
tenantSubmenuHideTimer = null
|
||||||
|
}
|
||||||
|
positionTenantSubmenu()
|
||||||
|
tenantSubmenuOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
const scheduleHideTenantSubmenu = () => {
|
||||||
|
if (tenantSubmenuHideTimer) clearTimeout(tenantSubmenuHideTimer)
|
||||||
|
tenantSubmenuHideTimer = setTimeout(() => {
|
||||||
|
tenantSubmenuOpen.value = false
|
||||||
|
tenantSubmenuHideTimer = null
|
||||||
|
}, 180)
|
||||||
|
}
|
||||||
|
|
||||||
|
const positionTenantSubmenu = () => {
|
||||||
|
const el = tenantMenuItemRef.value
|
||||||
|
if (!el) return
|
||||||
|
const rect = el.getBoundingClientRect()
|
||||||
|
const PANEL_WIDTH = 280
|
||||||
|
const PANEL_MAX_HEIGHT = 360
|
||||||
|
const GAP = 8
|
||||||
|
const MARGIN = 8
|
||||||
|
|
||||||
|
let left = rect.right + GAP
|
||||||
|
if (left + PANEL_WIDTH + MARGIN > window.innerWidth) {
|
||||||
|
left = Math.max(MARGIN, rect.left - PANEL_WIDTH - GAP)
|
||||||
|
}
|
||||||
|
|
||||||
|
let top = rect.top - 4
|
||||||
|
const maxTop = window.innerHeight - Math.min(PANEL_MAX_HEIGHT, window.innerHeight - MARGIN * 2) - MARGIN
|
||||||
|
if (top > maxTop) top = maxTop
|
||||||
|
if (top < MARGIN) top = MARGIN
|
||||||
|
|
||||||
|
tenantSubmenuStyle.value = {
|
||||||
|
left: `${left}px`,
|
||||||
|
top: `${top}px`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Silent prefetch so the "live" indicator on the IM menu item reflects reality
|
// Silent prefetch so the "live" indicator on the IM menu item reflects reality
|
||||||
// as soon as the user sees the avatar area. Errors are swallowed — the
|
// as soon as the user sees the avatar area. Errors are swallowed — the
|
||||||
// indicator just stays off if the request fails, which is the conservative
|
// indicator just stays off if the request fails, which is the conservative
|
||||||
@@ -374,12 +556,16 @@ const loadUserInfo = async () => {
|
|||||||
const handleClickOutside = (e: MouseEvent) => {
|
const handleClickOutside = (e: MouseEvent) => {
|
||||||
const target = e.target as Node
|
const target = e.target as Node
|
||||||
if (menuRef.value && menuRef.value.contains(target)) return
|
if (menuRef.value && menuRef.value.contains(target)) return
|
||||||
// The submenu is teleported to body, so it's not inside menuRef — check it
|
// The IM and tenant submenus are teleported to body, so they're not inside
|
||||||
// separately to avoid closing the dropdown when the user clicks the submenu.
|
// menuRef — check them separately to avoid closing the dropdown when the
|
||||||
const floating = document.querySelector('.im-submenu-floating')
|
// user clicks one of the floating panels.
|
||||||
if (floating && floating.contains(target)) return
|
const imFloating = document.querySelector('.im-submenu-floating')
|
||||||
|
if (imFloating && imFloating.contains(target)) return
|
||||||
|
const tenantFloating = document.querySelector('.tenant-submenu-floating')
|
||||||
|
if (tenantFloating && tenantFloating.contains(target)) return
|
||||||
menuVisible.value = false
|
menuVisible.value = false
|
||||||
imSubmenuOpen.value = false
|
imSubmenuOpen.value = false
|
||||||
|
tenantSubmenuOpen.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -725,5 +911,120 @@ onUnmounted(() => {
|
|||||||
// panel so hovering across the gap doesn't fire mouseleave-hide.
|
// panel so hovering across the gap doesn't fire mouseleave-hide.
|
||||||
padding-left: 2px;
|
padding-left: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tenant switcher submenu — same teleport rationale as .im-submenu-floating.
|
||||||
|
// All styling for the panel itself lives here (not in a child component) so
|
||||||
|
// the markup in UserMenu.vue stays self-contained.
|
||||||
|
.tenant-submenu-floating {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1100;
|
||||||
|
width: 280px;
|
||||||
|
max-height: 360px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: var(--td-bg-color-container);
|
||||||
|
border: 0.5px solid var(--td-component-stroke);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
|
||||||
|
// Pointer bridge so the user can slide off the menu item onto the panel
|
||||||
|
// without hitting the gap and triggering mouseleave-hide.
|
||||||
|
padding-left: 2px;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
.tenant-submenu-header {
|
||||||
|
padding: 10px 14px 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
border-bottom: 0.5px solid var(--td-component-stroke);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-list {
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.15s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--td-bg-color-secondarycontainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.is-current {
|
||||||
|
background: rgba(7, 192, 95, 0.08);
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
|
.tenant-submenu-item-name {
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item-avatar {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--td-bg-color-secondarycontainer);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--td-text-color-secondary);
|
||||||
|
flex-shrink: 0;
|
||||||
|
|
||||||
|
&.is-current {
|
||||||
|
background: linear-gradient(135deg, var(--td-brand-color) 0%, var(--td-brand-color-active) 100%);
|
||||||
|
color: var(--td-text-color-anti);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item-name {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--td-text-color-primary);
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item-role {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-item-badge {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.2;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--td-brand-color-light);
|
||||||
|
color: var(--td-brand-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.tenant-submenu-empty {
|
||||||
|
padding: 16px 12px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--td-text-color-placeholder);
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -2268,6 +2268,11 @@ export default {
|
|||||||
title: 'Tenant Information',
|
title: 'Tenant Information',
|
||||||
currentTenant: 'Current Tenant',
|
currentTenant: 'Current Tenant',
|
||||||
switchTenant: 'Switch Tenant',
|
switchTenant: 'Switch Tenant',
|
||||||
|
switcher: {
|
||||||
|
menuLabel: 'Switch Tenant',
|
||||||
|
currentBadge: 'Current',
|
||||||
|
empty: 'You only belong to one tenant',
|
||||||
|
},
|
||||||
sectionDescription: 'View detailed configuration for the tenant',
|
sectionDescription: 'View detailed configuration for the tenant',
|
||||||
apiDocument: 'API Document',
|
apiDocument: 'API Document',
|
||||||
name: 'Tenant Name',
|
name: 'Tenant Name',
|
||||||
|
|||||||
@@ -1526,6 +1526,11 @@ export default {
|
|||||||
title: "테넌트 정보",
|
title: "테넌트 정보",
|
||||||
currentTenant: "현재 테넌트",
|
currentTenant: "현재 테넌트",
|
||||||
switchTenant: "테넌트 전환",
|
switchTenant: "테넌트 전환",
|
||||||
|
switcher: {
|
||||||
|
menuLabel: "테넌트 전환",
|
||||||
|
currentBadge: "현재",
|
||||||
|
empty: "현재 하나의 테넌트에만 속해 있습니다",
|
||||||
|
},
|
||||||
sectionDescription: "테넌트의 상세 설정 정보 보기",
|
sectionDescription: "테넌트의 상세 설정 정보 보기",
|
||||||
apiDocument: "API 문서",
|
apiDocument: "API 문서",
|
||||||
name: "테넌트 이름",
|
name: "테넌트 이름",
|
||||||
|
|||||||
@@ -1344,6 +1344,11 @@ export default {
|
|||||||
title: 'Информация об арендаторе',
|
title: 'Информация об арендаторе',
|
||||||
currentTenant: 'Текущий арендатор',
|
currentTenant: 'Текущий арендатор',
|
||||||
switchTenant: 'Сменить арендатора',
|
switchTenant: 'Сменить арендатора',
|
||||||
|
switcher: {
|
||||||
|
menuLabel: 'Сменить арендатора',
|
||||||
|
currentBadge: 'Текущий',
|
||||||
|
empty: 'Вы состоите только в одном арендаторе',
|
||||||
|
},
|
||||||
sectionDescription: 'Просмотр детальной конфигурации арендатора',
|
sectionDescription: 'Просмотр детальной конфигурации арендатора',
|
||||||
apiDocument: 'Документация API',
|
apiDocument: 'Документация API',
|
||||||
name: 'Имя арендатора',
|
name: 'Имя арендатора',
|
||||||
|
|||||||
@@ -1507,6 +1507,11 @@ export default {
|
|||||||
title: "租户信息",
|
title: "租户信息",
|
||||||
currentTenant: "当前租户",
|
currentTenant: "当前租户",
|
||||||
switchTenant: "切换租户",
|
switchTenant: "切换租户",
|
||||||
|
switcher: {
|
||||||
|
menuLabel: "切换租户",
|
||||||
|
currentBadge: "当前",
|
||||||
|
empty: "你目前只属于这一个租户",
|
||||||
|
},
|
||||||
sectionDescription: "查看租户的详细配置信息",
|
sectionDescription: "查看租户的详细配置信息",
|
||||||
apiDocument: "API文档",
|
apiDocument: "API文档",
|
||||||
name: "租户名称",
|
name: "租户名称",
|
||||||
|
|||||||
@@ -73,6 +73,25 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
return match?.role || ''
|
return match?.role || ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// hasRole answers "is the current tenant role at least <min>?", used by
|
||||||
|
// role-aware UI gating across KB / Agent / settings views. The numeric
|
||||||
|
// ordering (viewer < contributor < admin < owner) mirrors the server-side
|
||||||
|
// matrix in middleware/rbac.go so a v-if here lines up with the 403 the
|
||||||
|
// backend would return.
|
||||||
|
//
|
||||||
|
// SECURITY: shares the same caveat as currentTenantRole — derived from
|
||||||
|
// localStorage, MUST be treated as UI-rendering-only. Never rely on
|
||||||
|
// hasRole() for security decisions; the server is the source of truth.
|
||||||
|
const ROLE_LEVEL: Record<string, number> = {
|
||||||
|
viewer: 10,
|
||||||
|
contributor: 20,
|
||||||
|
admin: 30,
|
||||||
|
owner: 40,
|
||||||
|
}
|
||||||
|
const hasRole = (min: 'viewer' | 'contributor' | 'admin' | 'owner'): boolean => {
|
||||||
|
return (ROLE_LEVEL[currentTenantRole.value] ?? 0) >= ROLE_LEVEL[min]
|
||||||
|
}
|
||||||
|
|
||||||
const effectiveTenantId = computed(() => {
|
const effectiveTenantId = computed(() => {
|
||||||
// 如果选择了其他租户,使用选择的租户ID,否则使用用户默认租户ID
|
// 如果选择了其他租户,使用选择的租户ID,否则使用用户默认租户ID
|
||||||
return selectedTenantId.value || (tenant.value?.id ? Number(tenant.value.id) : null)
|
return selectedTenantId.value || (tenant.value?.id ? Number(tenant.value.id) : null)
|
||||||
@@ -294,6 +313,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
currentUserId,
|
currentUserId,
|
||||||
canAccessAllTenants,
|
canAccessAllTenants,
|
||||||
currentTenantRole,
|
currentTenantRole,
|
||||||
|
hasRole,
|
||||||
effectiveTenantId,
|
effectiveTenantId,
|
||||||
isLiteMode,
|
isLiteMode,
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<div class="header-title" style="--wails-draggable: drag">
|
<div class="header-title" style="--wails-draggable: drag">
|
||||||
<div class="title-row" style="--wails-draggable: drag">
|
<div class="title-row" style="--wails-draggable: drag">
|
||||||
<h2 style="--wails-draggable: drag">{{ $t('agent.title') }}</h2>
|
<h2 style="--wails-draggable: drag">{{ $t('agent.title') }}</h2>
|
||||||
<t-tooltip :content="$t('agent.createAgent')" placement="bottom">
|
<t-tooltip v-if="authStore.hasRole('contributor')" :content="$t('agent.createAgent')" placement="bottom">
|
||||||
<t-button
|
<t-button
|
||||||
variant="text"
|
variant="text"
|
||||||
theme="default"
|
theme="default"
|
||||||
@@ -412,7 +412,7 @@
|
|||||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||||
<span class="empty-txt">{{ $t('agent.empty.title') }}</span>
|
<span class="empty-txt">{{ $t('agent.empty.title') }}</span>
|
||||||
<span class="empty-desc">{{ $t('agent.empty.description') }}</span>
|
<span class="empty-desc">{{ $t('agent.empty.description') }}</span>
|
||||||
<t-button class="agent-create-btn empty-state-btn" @click="handleCreateAgent">
|
<t-button v-if="authStore.hasRole('contributor')" class="agent-create-btn empty-state-btn" @click="handleCreateAgent">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<span class="btn-icon-wrapper">
|
<span class="btn-icon-wrapper">
|
||||||
<svg class="sparkles-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg class="sparkles-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
@@ -430,7 +430,7 @@
|
|||||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||||
<span class="empty-txt">{{ $t('agent.empty.title') }}</span>
|
<span class="empty-txt">{{ $t('agent.empty.title') }}</span>
|
||||||
<span class="empty-desc">{{ $t('agent.empty.description') }}</span>
|
<span class="empty-desc">{{ $t('agent.empty.description') }}</span>
|
||||||
<t-button class="agent-create-btn empty-state-btn" @click="handleCreateAgent">
|
<t-button v-if="authStore.hasRole('contributor')" class="agent-create-btn empty-state-btn" @click="handleCreateAgent">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<span class="btn-icon-wrapper">
|
<span class="btn-icon-wrapper">
|
||||||
<svg class="sparkles-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
<svg class="sparkles-icon" width="18" height="18" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<div class="header-title" style="--wails-draggable: drag">
|
<div class="header-title" style="--wails-draggable: drag">
|
||||||
<div class="title-row" style="--wails-draggable: drag">
|
<div class="title-row" style="--wails-draggable: drag">
|
||||||
<h2 style="--wails-draggable: drag">{{ $t('knowledgeBase.title') }}</h2>
|
<h2 style="--wails-draggable: drag">{{ $t('knowledgeBase.title') }}</h2>
|
||||||
<t-tooltip :content="$t('knowledgeList.create')" placement="bottom">
|
<t-tooltip v-if="authStore.hasRole('contributor')" :content="$t('knowledgeList.create')" placement="bottom">
|
||||||
<t-button
|
<t-button
|
||||||
variant="text"
|
variant="text"
|
||||||
theme="default"
|
theme="default"
|
||||||
@@ -517,7 +517,7 @@
|
|||||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||||
<span class="empty-txt">{{ $t('knowledgeList.empty.title') }}</span>
|
<span class="empty-txt">{{ $t('knowledgeList.empty.title') }}</span>
|
||||||
<span class="empty-desc">{{ $t('knowledgeList.empty.description') }}</span>
|
<span class="empty-desc">{{ $t('knowledgeList.empty.description') }}</span>
|
||||||
<t-button class="kb-create-btn empty-state-btn" @click="handleCreateKnowledgeBase">
|
<t-button v-if="authStore.hasRole('contributor')" class="kb-create-btn empty-state-btn" @click="handleCreateKnowledgeBase">
|
||||||
<template #icon><t-icon name="folder-add" /></template>
|
<template #icon><t-icon name="folder-add" /></template>
|
||||||
{{ $t('knowledgeList.create') }}
|
{{ $t('knowledgeList.create') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -528,7 +528,7 @@
|
|||||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||||
<span class="empty-txt">{{ $t('knowledgeList.empty.title') }}</span>
|
<span class="empty-txt">{{ $t('knowledgeList.empty.title') }}</span>
|
||||||
<span class="empty-desc">{{ $t('knowledgeList.empty.description') }}</span>
|
<span class="empty-desc">{{ $t('knowledgeList.empty.description') }}</span>
|
||||||
<t-button class="kb-create-btn empty-state-btn" @click="handleCreateKnowledgeBase">
|
<t-button v-if="authStore.hasRole('contributor')" class="kb-create-btn empty-state-btn" @click="handleCreateKnowledgeBase">
|
||||||
<template #icon><t-icon name="folder-add" /></template>
|
<template #icon><t-icon name="folder-add" /></template>
|
||||||
{{ $t('knowledgeList.create') }}
|
{{ $t('knowledgeList.create') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
<t-icon name="file-copy" />
|
<t-icon name="file-copy" />
|
||||||
</t-button>
|
</t-button>
|
||||||
<t-button
|
<t-button
|
||||||
|
v-if="authStore.hasRole('owner')"
|
||||||
size="small"
|
size="small"
|
||||||
variant="text"
|
variant="text"
|
||||||
theme="danger"
|
theme="danger"
|
||||||
@@ -230,8 +231,10 @@ import { resetTenantApiKey } from '@/api/tenant'
|
|||||||
import { getApiBaseUrl } from '@/utils/api-base'
|
import { getApiBaseUrl } from '@/utils/api-base'
|
||||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
// Reactive state
|
// Reactive state
|
||||||
const tenantInfo = ref<TenantInfo | null>(null)
|
const tenantInfo = ref<TenantInfo | null>(null)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<h3>{{ $t('mcpSettings.configuredServices') }}</h3>
|
<h3>{{ $t('mcpSettings.configuredServices') }}</h3>
|
||||||
<p>{{ $t('mcpSettings.manageAndTest') }}</p>
|
<p>{{ $t('mcpSettings.manageAndTest') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<t-button size="small" theme="primary" variant="outline" @click="handleAdd">
|
<t-button v-if="authStore.hasRole('admin')" size="small" theme="primary" variant="outline" @click="handleAdd">
|
||||||
<template #icon><t-icon name="add" /></template>
|
<template #icon><t-icon name="add" /></template>
|
||||||
{{ $t('mcpSettings.addService') }}
|
{{ $t('mcpSettings.addService') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<div v-if="services.length === 0" class="empty-state">
|
<div v-if="services.length === 0" class="empty-state">
|
||||||
<t-empty :description="$t('mcpSettings.empty')">
|
<t-empty :description="$t('mcpSettings.empty')">
|
||||||
<t-button theme="primary" variant="outline" size="small" @click="handleAdd">
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" variant="outline" size="small" @click="handleAdd">
|
||||||
<template #icon><t-icon name="add" /></template>
|
<template #icon><t-icon name="add" /></template>
|
||||||
{{ $t('mcpSettings.addFirst') }}
|
{{ $t('mcpSettings.addFirst') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
<t-switch
|
<t-switch
|
||||||
v-model="service.enabled"
|
v-model="service.enabled"
|
||||||
size="medium"
|
size="medium"
|
||||||
:disabled="service.is_builtin"
|
:disabled="service.is_builtin || !authStore.hasRole('admin')"
|
||||||
@change="() => handleToggleEnabled(service)"
|
@change="() => handleToggleEnabled(service)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@@ -118,8 +118,10 @@ import McpServiceDialog from './components/McpServiceDialog.vue'
|
|||||||
import McpTestResult from './components/McpTestResult.vue'
|
import McpTestResult from './components/McpTestResult.vue'
|
||||||
import SettingCard from '@/components/settings/SettingCard.vue'
|
import SettingCard from '@/components/settings/SettingCard.vue'
|
||||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
const confirmDelete = useConfirmDelete()
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
const services = ref<MCPService[]>([])
|
const services = ref<MCPService[]>([])
|
||||||
@@ -246,8 +248,13 @@ const handleDelete = (service: MCPService) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get service options for dropdown menu
|
// Get service options for dropdown menu. MCP service mutations and the
|
||||||
|
// /test endpoint (which probes external infra with stored creds) are all
|
||||||
|
// Admin+ in the backend matrix, so non-Admins see an empty action menu.
|
||||||
const getServiceOptions = () => {
|
const getServiceOptions = () => {
|
||||||
|
if (!authStore.hasRole('admin')) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
{ content: t('mcpSettings.actions.test'), value: 'test' },
|
{ content: t('mcpSettings.actions.test'), value: 'test' },
|
||||||
{ content: t('common.edit'), value: 'edit' },
|
{ content: t('common.edit'), value: 'edit' },
|
||||||
@@ -255,8 +262,12 @@ const getServiceOptions = () => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builtin: 仅测试
|
// Builtin: 仅测试 (Admin+ only as well — testing a builtin still hits
|
||||||
|
// the same /test endpoint that requires Admin+ role).
|
||||||
const getBuiltinServiceOptions = () => {
|
const getBuiltinServiceOptions = () => {
|
||||||
|
if (!authStore.hasRole('admin')) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
{ content: t('mcpSettings.actions.test'), value: 'test' }
|
{ content: t('mcpSettings.actions.test'), value: 'test' }
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,8 +6,12 @@
|
|||||||
<h2>{{ $t('modelSettings.title') }}</h2>
|
<h2>{{ $t('modelSettings.title') }}</h2>
|
||||||
<p class="section-description">{{ $t('modelSettings.description') }}</p>
|
<p class="section-description">{{ $t('modelSettings.description') }}</p>
|
||||||
</div>
|
</div>
|
||||||
<t-dropdown :options="addModelOptions" placement="bottom-right"
|
<t-dropdown
|
||||||
@click="(data: any) => openAddDialog(data.value)">
|
v-if="authStore.hasRole('admin')"
|
||||||
|
:options="addModelOptions"
|
||||||
|
placement="bottom-right"
|
||||||
|
@click="(data: any) => openAddDialog(data.value)"
|
||||||
|
>
|
||||||
<t-button theme="primary" variant="outline" size="small">
|
<t-button theme="primary" variant="outline" size="small">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
{{ $t('modelSettings.actions.addModel') }}
|
||||||
@@ -68,7 +72,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-else class="empty-state">
|
<div v-else class="empty-state">
|
||||||
<t-empty :description="emptyHint">
|
<t-empty :description="emptyHint">
|
||||||
<t-dropdown :options="addModelOptions" placement="bottom" @click="(data: any) => openAddDialog(data.value)">
|
<t-dropdown
|
||||||
|
v-if="authStore.hasRole('admin')"
|
||||||
|
:options="addModelOptions"
|
||||||
|
placement="bottom"
|
||||||
|
@click="(data: any) => openAddDialog(data.value)"
|
||||||
|
>
|
||||||
<t-button theme="primary" variant="outline" size="small">
|
<t-button theme="primary" variant="outline" size="small">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ $t('modelSettings.actions.addModel') }}
|
{{ $t('modelSettings.actions.addModel') }}
|
||||||
@@ -93,8 +102,10 @@ import ModelEditorDialog from '@/components/ModelEditorDialog.vue'
|
|||||||
import SettingCard from '@/components/settings/SettingCard.vue'
|
import SettingCard from '@/components/settings/SettingCard.vue'
|
||||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
import { listModels, createModel, updateModel as updateModelAPI, deleteModel as deleteModelAPI, type ModelConfig } from '@/api/model'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
const confirmDelete = useConfirmDelete()
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
type ModelType = 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'
|
type ModelType = 'chat' | 'embedding' | 'rerank' | 'vllm' | 'asr'
|
||||||
@@ -344,6 +355,14 @@ const getModelOptions = (type: ModelType, model: any) => {
|
|||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Models are tenant-wide infrastructure (LLM credentials); the
|
||||||
|
// backend gates every mutation behind Admin+ (see RegisterModelRoutes).
|
||||||
|
// Non-Admins get an empty action menu — viewing is fine, but editing,
|
||||||
|
// copying (also goes through createModel), and deleting are not.
|
||||||
|
if (!authStore.hasRole('admin')) {
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
options.push({
|
options.push({
|
||||||
content: t('common.edit'),
|
content: t('common.edit'),
|
||||||
value: `edit-${type}-${model.id}`
|
value: `edit-${type}-${model.id}`
|
||||||
|
|||||||
@@ -219,7 +219,7 @@
|
|||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="drawer-footer-actions">
|
<div class="drawer-footer-actions">
|
||||||
<t-button theme="default" variant="outline" @click="drawerVisible = false">{{ $t('common.cancel') }}</t-button>
|
<t-button theme="default" variant="outline" @click="drawerVisible = false">{{ $t('common.cancel') }}</t-button>
|
||||||
<t-button theme="primary" :loading="saving" @click="onSave">{{ $t('common.save') }}</t-button>
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" :loading="saving" @click="onSave">{{ $t('common.save') }}</t-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</t-drawer>
|
</t-drawer>
|
||||||
@@ -230,6 +230,7 @@
|
|||||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useUIStore } from '@/stores/ui'
|
import { useUIStore } from '@/stores/ui'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
import {
|
import {
|
||||||
getParserEngines,
|
getParserEngines,
|
||||||
getParserEngineConfig,
|
getParserEngineConfig,
|
||||||
@@ -242,6 +243,7 @@ import { getWeKnoraCloudStatus } from '@/api/model'
|
|||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const uiStore = useUIStore()
|
const uiStore = useUIStore()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const CONFIGURABLE_ENGINES = new Set(['mineru', 'mineru_cloud'])
|
const CONFIGURABLE_ENGINES = new Set(['mineru', 'mineru_cloud'])
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
<ModelSelector
|
<ModelSelector
|
||||||
model-type="Rerank"
|
model-type="Rerank"
|
||||||
:selected-model-id="localConfig.rerank_model_id"
|
:selected-model-id="localConfig.rerank_model_id"
|
||||||
|
:disabled="!canEdit"
|
||||||
@update:selected-model-id="handleModelChange"
|
@update:selected-model-id="handleModelChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -35,6 +36,7 @@
|
|||||||
:min="1"
|
:min="1"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
|
:disabled="!canEdit"
|
||||||
@change="handleParamChange"
|
@change="handleParamChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -50,6 +52,7 @@
|
|||||||
:min="0"
|
:min="0"
|
||||||
:max="1"
|
:max="1"
|
||||||
:step="0.05"
|
:step="0.05"
|
||||||
|
:disabled="!canEdit"
|
||||||
@change="handleParamChange"
|
@change="handleParamChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -65,6 +68,7 @@
|
|||||||
:min="0"
|
:min="0"
|
||||||
:max="1"
|
:max="1"
|
||||||
:step="0.05"
|
:step="0.05"
|
||||||
|
:disabled="!canEdit"
|
||||||
@change="handleParamChange"
|
@change="handleParamChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -80,6 +84,7 @@
|
|||||||
:min="1"
|
:min="1"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
|
:disabled="!canEdit"
|
||||||
@change="handleParamChange"
|
@change="handleParamChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -95,6 +100,7 @@
|
|||||||
:min="-10"
|
:min="-10"
|
||||||
:max="10"
|
:max="10"
|
||||||
:step="0.1"
|
:step="0.1"
|
||||||
|
:disabled="!canEdit"
|
||||||
@change="handleParamChange"
|
@change="handleParamChange"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -103,7 +109,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, onMounted, nextTick } from 'vue'
|
import { reactive, computed, onMounted, nextTick } from 'vue'
|
||||||
import { MessagePlugin } from 'tdesign-vue-next'
|
import { MessagePlugin } from 'tdesign-vue-next'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import ModelSelector from '@/components/ModelSelector.vue'
|
import ModelSelector from '@/components/ModelSelector.vue'
|
||||||
@@ -112,8 +118,14 @@ import {
|
|||||||
updateTenantRetrievalConfig,
|
updateTenantRetrievalConfig,
|
||||||
type RetrievalConfig,
|
type RetrievalConfig,
|
||||||
} from '@/api/retrieval'
|
} from '@/api/retrieval'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
// PUT /tenants/kv/retrieval-config requires Admin+ on the server. Hide the
|
||||||
|
// banner + lock all controls for non-Admins so they can read the
|
||||||
|
// configuration without tripping a 403 mid-edit.
|
||||||
|
const canEdit = computed(() => authStore.hasRole('admin'))
|
||||||
|
|
||||||
const defaultConfig: RetrievalConfig = {
|
const defaultConfig: RetrievalConfig = {
|
||||||
embedding_top_k: 50,
|
embedding_top_k: 50,
|
||||||
|
|||||||
@@ -465,7 +465,7 @@
|
|||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="drawer-footer-actions">
|
<div class="drawer-footer-actions">
|
||||||
<t-button theme="default" variant="outline" @click="drawerVisible = false">{{ $t('common.cancel') }}</t-button>
|
<t-button theme="default" variant="outline" @click="drawerVisible = false">{{ $t('common.cancel') }}</t-button>
|
||||||
<t-button theme="primary" :loading="saving" @click="onSave">{{ $t('common.save') }}</t-button>
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" :loading="saving" @click="onSave">{{ $t('common.save') }}</t-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</t-drawer>
|
</t-drawer>
|
||||||
@@ -482,8 +482,10 @@ import {
|
|||||||
updateStorageEngineConfig,
|
updateStorageEngineConfig,
|
||||||
type StorageEngineConfig,
|
type StorageEngineConfig,
|
||||||
} from '@/api/system'
|
} from '@/api/system'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
const defaultConfig = (): StorageEngineConfig => ({
|
const defaultConfig = (): StorageEngineConfig => ({
|
||||||
default_provider: 'local',
|
default_provider: 'local',
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<div class="settings-group">
|
<div class="settings-group">
|
||||||
<div class="section-subheader">
|
<div class="section-subheader">
|
||||||
<h3>{{ t('vectorStoreSettings.storesTitle') }}</h3>
|
<h3>{{ t('vectorStoreSettings.storesTitle') }}</h3>
|
||||||
<t-button theme="primary" variant="outline" size="small" @click="openAddDialog">
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" variant="outline" size="small" @click="openAddDialog">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ t('vectorStoreSettings.addStore') }}
|
{{ t('vectorStoreSettings.addStore') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="item-actions">
|
<div class="item-actions">
|
||||||
<t-button
|
<t-button
|
||||||
|
v-if="authStore.hasRole('admin')"
|
||||||
theme="default" variant="outline" size="small"
|
theme="default" variant="outline" size="small"
|
||||||
:loading="testingId === store.id"
|
:loading="testingId === store.id"
|
||||||
@click="testExisting(store)"
|
@click="testExisting(store)"
|
||||||
@@ -64,13 +65,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="item-actions">
|
<div class="item-actions">
|
||||||
<t-button
|
<t-button
|
||||||
|
v-if="authStore.hasRole('admin')"
|
||||||
theme="default" variant="outline" size="small"
|
theme="default" variant="outline" size="small"
|
||||||
:loading="testingId === store.id"
|
:loading="testingId === store.id"
|
||||||
@click="testExisting(store)"
|
@click="testExisting(store)"
|
||||||
>
|
>
|
||||||
{{ t('vectorStoreSettings.testConnection') }}
|
{{ t('vectorStoreSettings.testConnection') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
<t-dropdown :options="storeActions" trigger="click" @click="(action: any) => handleAction(action, store)">
|
<t-dropdown v-if="authStore.hasRole('admin')" :options="storeActions" trigger="click" @click="(action: any) => handleAction(action, store)">
|
||||||
<t-button theme="default" variant="text" size="small" shape="square">
|
<t-button theme="default" variant="text" size="small" shape="square">
|
||||||
<template #icon><t-icon name="more" /></template>
|
<template #icon><t-icon name="more" /></template>
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -262,8 +264,10 @@ import {
|
|||||||
type VectorStoreEntity,
|
type VectorStoreEntity,
|
||||||
type VectorStoreTypeInfo,
|
type VectorStoreTypeInfo,
|
||||||
} from '@/api/vector-store'
|
} from '@/api/vector-store'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
// ===== State =====
|
// ===== State =====
|
||||||
const stores = ref<VectorStoreEntity[]>([])
|
const stores = ref<VectorStoreEntity[]>([])
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<div class="settings-toolbar">
|
<div class="settings-toolbar">
|
||||||
<h3>{{ t('webSearchSettings.providersTitle') }}</h3>
|
<h3>{{ t('webSearchSettings.providersTitle') }}</h3>
|
||||||
<t-button theme="primary" variant="outline" size="small" @click="openAddDialog">
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" variant="outline" size="small" @click="openAddDialog">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ t('webSearchSettings.addProvider') }}
|
{{ t('webSearchSettings.addProvider') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
<!-- Empty State -->
|
<!-- Empty State -->
|
||||||
<div v-else class="empty-state">
|
<div v-else class="empty-state">
|
||||||
<t-empty :description="t('webSearchSettings.noProvidersDesc')">
|
<t-empty :description="t('webSearchSettings.noProvidersDesc')">
|
||||||
<t-button theme="primary" variant="outline" size="small" @click="openAddDialog">
|
<t-button v-if="authStore.hasRole('admin')" theme="primary" variant="outline" size="small" @click="openAddDialog">
|
||||||
<template #icon><add-icon /></template>
|
<template #icon><add-icon /></template>
|
||||||
{{ t('webSearchSettings.addProvider') }}
|
{{ t('webSearchSettings.addProvider') }}
|
||||||
</t-button>
|
</t-button>
|
||||||
@@ -171,8 +171,10 @@ import CredentialResource, {
|
|||||||
type CredentialResourceApi,
|
type CredentialResourceApi,
|
||||||
} from '@/components/credentials/CredentialResource.vue'
|
} from '@/components/credentials/CredentialResource.vue'
|
||||||
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
import { useConfirmDelete } from '@/components/settings/useConfirmDelete'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const authStore = useAuthStore()
|
||||||
const confirmDelete = useConfirmDelete()
|
const confirmDelete = useConfirmDelete()
|
||||||
|
|
||||||
// ===== State =====
|
// ===== State =====
|
||||||
@@ -406,6 +408,12 @@ const testExistingConnection = async (entity: WebSearchProviderEntity) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getProviderOptions = (_entity: WebSearchProviderEntity) => {
|
const getProviderOptions = (_entity: WebSearchProviderEntity) => {
|
||||||
|
// Web search providers carry external API credentials; the backend
|
||||||
|
// gates every mutation/test behind Admin+ (RegisterWebSearchProviderRoutes).
|
||||||
|
// Hide the action menu entirely for non-Admins so they don't trip 403s.
|
||||||
|
if (!authStore.hasRole('admin')) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
{ content: t('webSearchSettings.testConnection'), value: 'test' },
|
{ content: t('webSearchSettings.testConnection'), value: 'test' },
|
||||||
{ content: t('common.edit'), value: 'edit' },
|
{ content: t('common.edit'), value: 'edit' },
|
||||||
|
|||||||
Reference in New Issue
Block a user