Repository navigation
fix: knowledge details document and image permission error #8286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| <script setup lang="ts"> | ||
| import { ref } from 'vue' | ||
| import { computed, ref } from 'vue' | ||
| import { useI18n } from 'vue-i18n' | ||
| import type { ParagraphQuestionDraft } from './types.ts' | ||
| import type { ParagraphDetail, ParagraphItem, ParagraphUpdatePayload } from '@/api/types' | ||
| import type { DocumentResourceType, ParagraphDetail, ParagraphItem, ParagraphUpdatePayload } from '@/api/types' | ||
| import { DOCUMENT_RESOURCE_TYPE } from '@/api/enums' | ||
| import { useDocumentDetailContext } from '@/views/document-detail/context' | ||
| import ParagraphForm from './components/ParagraphForm.vue' | ||
| import ParagraphPreview from './components/ParagraphPreview.vue' | ||
|
|
@@ -23,13 +24,33 @@ function knowledgeDocPermission(method: KnowledgeDocPermissionMethod): boolean { | |
| return Boolean(perm.knowledge.workspace[method](props.knowledgeId)) | ||
| } | ||
|
|
||
| type KnowledgeImagePermissionMethod = 'edit' | ||
|
|
||
| function knowledgeImagePermission(method: KnowledgeImagePermissionMethod): boolean { | ||
| if (isSystemResource()) return Boolean(perm.knowledge.system.image[method]()) | ||
| if (isSystemSharedResource()) return Boolean(perm.knowledge.share.image[method]()) | ||
| if (isWorkspaceSharedResource()) return false // 共享知识库在工作空间侧只读 | ||
| return Boolean(perm.knowledge.workspace.image[method](props.knowledgeId)) | ||
| } | ||
|
|
||
| /** | ||
| * 知识库「问题」只读权限判断 | ||
| */ | ||
| function hasProblemReadPermission(): boolean { | ||
| if (isSystemResource()) return Boolean(perm.knowledge.system.problemRead()) | ||
| if (isSystemSharedResource()) return Boolean(perm.knowledge.share.problemRead()) | ||
| if (isWorkspaceSharedResource()) return false // 共享知识库在工作空间侧只读 | ||
| return Boolean(perm.knowledge.workspace.problemRead(props.knowledgeId)) | ||
| } | ||
|
|
||
| defineOptions({ name: 'EditParagraphDialog' }) | ||
| const { t } = useI18n({ useScope: 'global' }) | ||
| const props = defineProps<{ | ||
| knowledgeId: string | ||
| documentId: string | ||
| sourceFileId?: string | ||
| title?: string | ||
| resourceType?: DocumentResourceType | ||
| }>() | ||
| const { resourceApi } = useDocumentDetailContext() | ||
| const emit = defineEmits<{ success: [paragraph: ParagraphItem]; closed: [] }>() | ||
|
|
@@ -44,6 +65,8 @@ const targetParagraphId = ref('') | |
| const loading = ref(false) | ||
| const detailFailed = ref(false) | ||
| const relatedQuestions = ref<ParagraphQuestionDraft[]>([]) | ||
| const isImageDocument = computed(() => props.resourceType === DOCUMENT_RESOURCE_TYPE.IMAGE) | ||
| const showQuestions = computed(() => hasProblemReadPermission()) | ||
|
|
||
| function loadParagraphDetail() { | ||
| if (loading.value) return | ||
|
|
@@ -129,7 +152,7 @@ defineExpose({ open, close }) | |
| <el-card v-if="mode === 'detail'" shadow="never" class="mk-paragraph-card group relative min-w-0 flex-1" body-class="flex-column h-full"> | ||
| <!-- 编辑分段标题和内容 --> | ||
| <el-button | ||
| v-if="!isWorkspaceSharedResource() && knowledgeDocPermission('docEdit')" | ||
| v-if="!isWorkspaceSharedResource() && (isImageDocument ? knowledgeImagePermission('edit') : knowledgeDocPermission('docEdit'))" | ||
| circle | ||
| class="group-hover-visible absolute! top-2 right-2 z-10 shadow-md" | ||
| @click="handleEdit" | ||
|
|
@@ -152,6 +175,7 @@ defineExpose({ open, close }) | |
| <!-- 关联问题 --> | ||
| <ParagraphQuestions | ||
| v-model="relatedQuestions" | ||
| :show="showQuestions" | ||
| :knowledge-id="targetKnowledgeId" | ||
| :document-id="targetDocumentId" | ||
| :paragraph-id="targetParagraphId" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's my review of the diff: Issues & Observations1. Inconsistent behavior:
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,24 @@ import type { DocumentImportParagraph, ParagraphUpdatePayload } from '@/api/type | |
| import type { ParagraphQuestionDraft } from '@/views/document-detail/paragraph-dialog/types' | ||
| import ParagraphForm from '@/views/document-detail/paragraph-dialog/components/ParagraphForm.vue' | ||
| import ParagraphQuestions from '@/views/document-detail/paragraph-dialog/components/ParagraphQuestions.vue' | ||
| import { isSystemResource, isSystemSharedResource, isWorkspaceSharedResource } from '@/utils/resource-context' | ||
| import { perm } from '@/permission' | ||
|
|
||
| defineOptions({ name: 'EditImportParagraphDialog' }) | ||
| const { t } = useI18n({ useScope: 'global' }) | ||
| defineProps<{ knowledgeId: string }>() | ||
| const props = defineProps<{ knowledgeId: string }>() | ||
| const emit = defineEmits<{ submit: [paragraph: DocumentImportParagraph]; closed: [] }>() | ||
|
|
||
| /** | ||
| * 知识库「问题」只读权限判断 | ||
| */ | ||
| function knowledgeQuestionPermission(): boolean { | ||
| if (isSystemResource()) return Boolean(perm.knowledge.system.problemRead()) | ||
| if (isSystemSharedResource()) return Boolean(perm.knowledge.share.problemRead()) | ||
| if (isWorkspaceSharedResource()) return false // 共享知识库在工作空间侧只读 | ||
| return Boolean(perm.knowledge.workspace.problemRead(props.knowledgeId)) | ||
| } | ||
|
|
||
| /* 编辑弹窗按需挂载,保存前仅维护导入分段和关联问题的本地草稿。 */ | ||
| const visible = ref(false) | ||
| const paragraphDraft = ref<DocumentImportParagraph>({ title: '', content: '' }) | ||
|
|
@@ -71,7 +83,7 @@ defineExpose({ open, close }) | |
| <div v-loading="loading" class="flex w-full gap-4"> | ||
| <ParagraphForm ref="paragraphFormRef" v-model="paragraphForm" :knowledge-id="knowledgeId" /> | ||
| <!-- 关联问题仅保存到导入草稿,未创建文档不传入分段 ID --> | ||
| <ParagraphQuestions v-model="relatedQuestions" :knowledge-id="knowledgeId" document-id="" /> | ||
| <ParagraphQuestions v-model="relatedQuestions" :show="knowledgeQuestionPermission()" :knowledge-id="knowledgeId" document-id="" /> | ||
| </div> | ||
| <template #footer> | ||
| <!-- 取消分段编辑 --> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff is syntactically valid. Main concerns are reactivity, permission semantics, and ensuring the UI permission is actually enforced. Potential issues
Recommended refactorconst canReadQuestions = computed(() => {
if (isSystemResource()) return Boolean(perm.knowledge.system.problemRead())
if (isSystemSharedResource()) return Boolean(perm.knowledge.share.problemRead())
if (isWorkspaceSharedResource()) return false
return Boolean(perm.knowledge.workspace.problemRead(props.knowledgeId))
})
watch(canReadQuestions, (allowed) => {
if (!allowed) relatedQuestions.value = []
})Template: <ParagraphQuestions
v-if="canReadQuestions"
v-model="relatedQuestions"
:knowledge-id="knowledgeId"
document-id=""
/>Or, if <ParagraphQuestions
v-model="relatedQuestions"
:show="canReadQuestions"
:knowledge-id="knowledgeId"
document-id=""
/>Optimization suggestions
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
No major irregularities. The diff is clean and consistent with the existing patterns (
isSystemResource,perm.*.problemRead). Notes below are minor.1. Import path consistency (verify)
Most codebases in this style import permissions at a specific granularity. Confirm the symbol exists and returns functions (it's called as
perm.knowledge.system.problemRead()andperm.knowledge.workspace.problemRead(id)— i.e. methods, not booleans). IfproblemReadis a static boolean, calling it will throw at runtime. Double-check the API shape.2. Naming / intent
knowledgeQuestionPermission()reads like a getter but acts as a permission check. A clearer name:canShowKnowledgeQuestions()orhasQuestionReadPerm(). Also, it takes no args yet closes overprops.knowledgeId— acceptable, but a named param would be more explicit:3. Called directly in template
This runs on every re-render (cheap here, but if
perm.*.problemReadever becomes async or expensive it'll thrash). Safer pattern: acomputed.Then
:show="showQuestions".This also gives you a single place to unit-test the branch logic.
4. Ordering of branches (behavioral assumption)
The
isWorkspaceSharedResource()→falsebranch means "shared KB is read-only on the workspace side." That encodes a product decision inside a view component. Consider moving the "which resource context am I in?" resolution intoresource-context.ts(e.g.getResourceScope()), so this file only maps scope → permission. Keeps the switch testable and avoids drift if another context is added later.Otherwise, ordering is correct: system → shared → workspace-shared → workspace.
5. Default fallthrough
If none of the
is*guards match (e.g. an unknown/new context), it silently falls through toperm.knowledge.workspace.problemRead(props.knowledgeId). If that's intentional, fine; if a new context should be denied by default, make the default explicit:6.
props.knowledgeIdvstargetKnowledgeIdThe template passes
:knowledge-id="targetKnowledgeId", but the permission check usesprops.knowledgeId. Confirm these are always the same at render time. Duringopen(...)there may be a tick wheretargetKnowledgeIdis set butprops.knowledgeIdisn't (or vice versa) — thenshowcould disagree with whatParagraphQuestionsactually queries. If they can differ, usetargetKnowledgeIdfor the check too:7. Comment language
Code comments (
知识库「问题」只读权限判断,共享知识库在工作空间侧只读) are Chinese while the project apparently mixes English naming. Not a bug — flag only if the repo lint/convention requires English comments.8.
defineExpose/ reactivity (unchanged, just FYI)knowledgeQuestionPermissionis not exposed — fine, since it's only used in the template. No issue.Summary of suggested changes
perm.*.problemReadare methods, not booleanscomputedfor clarity/perf/ testabilityprops.knowledgeIdwithtargetKnowledgeIdcanReadQuestions/canShowQuestions