fix(knowledge): restrict source file download to Editor and above

Downloading exposes the original source file, which is more sensitive than viewing parsed content or previews. Align backend route guards, handler checks, and frontend UI so tenant Viewers and org-shared read-only access cannot download.
This commit is contained in:
wizardchen
2026-07-23 21:11:37 +08:00
committed by lyingbug
parent 697e0ae04e
commit 8cb43473e6
6 changed files with 136 additions and 5 deletions
+2 -2
View File
@@ -84,7 +84,7 @@ mermaid.initialize({
topPadding: 50
}
});
const props = defineProps(["visible", "details", "knowledgeType", "sourceInfo", "canEditKB", "parse_status", "kbId"]);
const props = defineProps(["visible", "details", "knowledgeType", "sourceInfo", "canEditKB", "canDownloadKB", "parse_status", "kbId"]);
const emit = defineEmits(["closeDoc", "getDoc", "questionDeleted"]);
const hasTimelineSpans = ref(false);
@@ -1095,7 +1095,7 @@ const handleDetailsScroll = () => {
<div class="doc-drawer-header-title">{{ getDisplayTitle() }}</div>
</div>
<div class="header-actions">
<t-button v-if="details.type === 'file' || details.type === 'manual'" class="header-action-btn" size="small"
<t-button v-if="canDownloadKB && (details.type === 'file' || details.type === 'manual')" class="header-action-btn" size="small"
variant="text" shape="square" theme="default" :title="$t('common.download') || 'Download'"
@click="downloadFile()">
<template #icon>
+12 -1
View File
@@ -303,6 +303,16 @@ const canMutateKnowledge = computed(() => {
// Effective permission: from direct org share list or from GET /knowledge-bases/:id (e.g. agent-visible KB)
const effectiveKBPermission = computed(() => orgStore.getKBPermission(kbId.value) || kbInfo.value?.my_permission || '');
// Downloading returns the original source file, which is intentionally more
// restrictive than viewing parsed content or using the preview tab. A tenant
// Viewer can never download; for cross-tenant KBs the effective share
// permission must additionally be Editor or Admin.
const canDownloadKnowledge = computed(() => {
if (!authStore.hasRole('contributor')) return false;
const permission = effectiveKBPermission.value;
return !permission || permission === 'owner' || permission === 'admin' || permission === 'editor';
});
const knowledgeList = ref<Array<{ id: string; name: string; type?: string }>>([]);
let { cardList, total, moreIndex, details, getKnowled, delKnowledge, openMore, onVisibleChange: _onVisibleChange, getCardDetails, getfDetails } = useKnowledgeBase(kbId.value)
@@ -2304,7 +2314,8 @@ async function createNewSession(value: string): Promise<void> {
</template>
<!-- DocContent drawer (shared by documents tab and wiki source refs) -->
<DocContent ref="docContentRef" :visible="isCardDetails" :details="details" :canEditKB="canEdit" :kbId="kbId"
<DocContent ref="docContentRef" :visible="isCardDetails" :details="details" :canEditKB="canEdit"
:canDownloadKB="canDownloadKnowledge" :kbId="kbId"
@closeDoc="closeDoc" @getDoc="getDoc">
</DocContent>
</div>