refactor(permissions): enhance role-based access controls across knowledge base and agent views

- Updated visibility conditions for various UI elements based on user roles, ensuring that only users with appropriate permissions (Admin, Contributor, or KB creator) can access certain actions.
- Introduced computed properties to manage permissions for sharing knowledge bases, managing data sources, and executing graph extraction.
- Adjusted the AgentList and KnowledgeBase components to reflect these changes, improving user experience by preventing unauthorized actions from being displayed.
- Ensured that the backend routes are aligned with the updated frontend role checks, enhancing security and clarity in user interactions.
This commit is contained in:
wizardchen
2026-05-15 17:56:58 +08:00
committed by lyingbug
parent e7f9a6580a
commit c6a2f6c8cc
9 changed files with 104 additions and 28 deletions
+15 -3
View File
@@ -231,6 +231,18 @@ const canManage = computed(() => {
return orgStore.canManageKB(kbId.value, false);
});
// Can mutate knowledge (move / batch-delete): the backend gate for these
// two endpoints is g.Contributor(), so the caller MUST be Contributor+
// in their tenant on top of having KB edit permission. Without the extra
// role check, an org-share-editor whose tenant role is Viewer would see
// the "Move" / "Batch manage" entries and 403 on click.
const canMutateKnowledge = computed(() => {
if (!canEdit.value) return false;
if (isOwner.value) return true;
if (authStore.hasRole('admin')) return true;
return authStore.hasRole('contributor');
});
// Current KB's shared record (when accessed via organization share)
const currentSharedKb = computed(() =>
orgStore.sharedKnowledgeBases.find((s) => s.knowledge_base?.id === kbId.value) ?? null,
@@ -2036,7 +2048,7 @@ async function createNewSession(value: string): Promise<void> {
<!-- Wiki Browser / Graph (shown when wiki or graph tab is active) -->
<div v-if="isWiki && (activeKbTab === 'wiki' || activeKbTab === 'graph')" class="wiki-main-area">
<WikiBrowser v-if="kbId" :knowledge-base-id="kbId" :view="activeKbTab === 'graph' ? 'graph' : 'browser'" @open-source-doc="openSourceDoc" @status-change="onWikiStatusChange" />
<WikiBrowser v-if="kbId" :knowledge-base-id="kbId" :view="activeKbTab === 'graph' ? 'graph' : 'browser'" :can-edit="canEdit" @open-source-doc="openSourceDoc" @status-change="onWikiStatusChange" />
</div>
<template v-if="activeKbTab === 'documents' || !isWiki">
@@ -2390,11 +2402,11 @@ async function createNewSession(value: string): Promise<void> {
<t-icon class="icon" name="refresh" />
<span>{{ t('knowledgeBase.rebuildDocument') }}</span>
</div>
<div class="card-menu-item" @click.stop="handleMoveKnowledge(item)">
<div v-if="canMutateKnowledge" class="card-menu-item" @click.stop="handleMoveKnowledge(item)">
<t-icon class="icon" name="swap" />
<span>{{ t('knowledgeBase.moveDocument') }}</span>
</div>
<div class="card-menu-item" @click.stop="handleEnterBatchFromCard(item)">
<div v-if="canMutateKnowledge" class="card-menu-item" @click.stop="handleEnterBatchFromCard(item)">
<t-icon class="icon" name="queue" />
<span>{{ t('menu.batchManage') }}</span>
</div>