fix(rbac): hide UI mutation surfaces for Viewer / non-creator

Several mutation entry points stayed visible to users who lacked the
backend-required role, so Viewers (and non-creator Contributors) hit
403 on click instead of seeing the disabled state. Surgical fixes,
all matching the existing backend matrix:

  - KnowledgeBaseList: gate the entire 3-dot popup (both the 'all'
    and 'mine' tabs) behind canManageKBCard. Pin/unpin used to be
    unguarded; settings/delete were per-item gated but the trigger
    still showed. Now non-managers don't see the popup at all.

  - AgentList: the popup trigger now requires at least one menu item
    to be visible (edit OR copy OR disable OR delete), via a compound
    v-if on the popup itself. Disable/enable on own custom agents
    and shared agents both gain a hasRole('admin') guard to match
    POST /shared-agents/disabled, which writes a tenant-level
    preference and is Admin-gated.

  - AgentEditorModal: new readOnly prop hides the '确定' (save)
    button and replaces 'Cancel' with 'Close'. AgentList passes
    readOnly when the user can't manage the agent (built-in agents
    and others' custom agents for Viewers). Form-input disabling is
    intentionally NOT wired here yet — the modal has 3000+ lines of
    inputs and the only mutation surface that 403s is the save
    button. Hiding it removes the broken path without rewiring the
    whole form.

  - doc-content: generated-question delete button gated by a new
    canEditKB prop driven by KnowledgeBase.vue's existing canEdit
    computed (KB creator OR Admin OR org-share-edit). Defaults to
    Admin-only when the prop is missing — fail-closed since the
    backend matrix is now stricter (see follow-up commit).

The server still enforces the same matrix on every mutation; these
gates only stop the user from staring at a 'failed' toast.
This commit is contained in:
wizardchen
2026-05-15 12:15:26 +08:00
committed by lyingbug
parent 1e8b5c8d40
commit f7a264ca93
5 changed files with 37 additions and 14 deletions
+7 -5
View File
@@ -89,7 +89,7 @@
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
</div>
<t-popup
v-if="agent.isMine"
v-if="agent.isMine && (canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin')))"
:visible="openMoreAgentId === agent.id"
trigger="hover"
overlayClassName="card-more-popup"
@@ -105,7 +105,7 @@
<div class="popup-menu">
<div v-if="canManageAgent(agent)" class="popup-menu-item" @click="handleEdit(agent)"><t-icon class="menu-icon" name="edit" /><span>{{ $t('common.edit') }}</span></div>
<div v-if="authStore.hasRole('contributor')" class="popup-menu-item" @click="handleCopy(agent)"><t-icon class="menu-icon" name="file-copy" /><span>{{ $t('common.copy') }}</span></div>
<div v-if="!agent.is_builtin" class="popup-menu-item" @click="handleToggleDisabled(agent)">
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item" @click="handleToggleDisabled(agent)">
<t-icon class="menu-icon" name="poweroff" />
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
</div>
@@ -114,7 +114,7 @@
</template>
</t-popup>
<t-popup
v-else
v-else-if="!agent.isMine && authStore.hasRole('admin')"
:visible="openMoreAgentId === 'shared-' + agent.share_id"
trigger="hover"
overlayClassName="card-more-popup"
@@ -226,6 +226,7 @@
<span class="card-title" :title="agent.name">{{ agent.name }}</span>
</div>
<t-popup
v-if="canManageAgent(agent) || authStore.hasRole('contributor') || (!agent.is_builtin && authStore.hasRole('admin'))"
:visible="openMoreAgentId === agent.id"
trigger="hover"
overlayClassName="card-more-popup"
@@ -251,7 +252,7 @@
<t-icon class="menu-icon" name="file-copy" />
<span>{{ $t('common.copy') }}</span>
</div>
<div v-if="!agent.is_builtin" class="popup-menu-item" @click="handleToggleDisabled(agent)">
<div v-if="!agent.is_builtin && authStore.hasRole('admin')" class="popup-menu-item" @click="handleToggleDisabled(agent)">
<t-icon class="menu-icon" name="poweroff" />
<span>{{ agent.disabled_by_me ? $t('agent.enable') : $t('agent.disable') }}</span>
</div>
@@ -536,11 +537,12 @@
</Transition>
<!-- 智能体编辑器弹窗 -->
<AgentEditorModal
<AgentEditorModal
:visible="editorVisible"
:mode="editorMode"
:agent="editingAgent"
:initialSection="editorInitialSection"
:readOnly="editorMode === 'edit' && editingAgent != null && !canManageAgent(editingAgent as AgentWithUI)"
@update:visible="editorVisible = $event"
@success="handleEditorSuccess"
/>