From c6a2f6c8cce339cfbc3f78569a8543c1a305e49e Mon Sep 17 00:00:00 2001 From: wizardchen Date: Fri, 15 May 2026 17:56:58 +0800 Subject: [PATCH] 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. --- frontend/src/views/agent/AgentList.vue | 2 +- .../src/views/knowledge/KnowledgeBase.vue | 18 +++++++++-- .../knowledge/KnowledgeBaseEditorModal.vue | 21 ++++++++++-- .../knowledge/components/FAQEntryManager.vue | 32 ++++++++++++++----- .../knowledge/settings/DataSourceSettings.vue | 17 +++++++--- .../knowledge/settings/GraphSettings.vue | 10 ++++++ .../knowledge/settings/KBShareSettings.vue | 14 +++++--- .../src/views/knowledge/wiki/WikiBrowser.vue | 9 ++++-- internal/router/router.go | 9 ++++-- 9 files changed, 104 insertions(+), 28 deletions(-) diff --git a/frontend/src/views/agent/AgentList.vue b/frontend/src/views/agent/AgentList.vue index 40c7310d..2f1458d9 100644 --- a/frontend/src/views/agent/AgentList.vue +++ b/frontend/src/views/agent/AgentList.vue @@ -352,7 +352,7 @@ {{ $t('listSpaceSidebar.mine') }} { 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 {
- +