Repository navigation
fix: honor question permissions in paragraph dialogs #8288
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 |
|---|---|---|
|
|
@@ -66,7 +66,6 @@ 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 | ||
|
|
@@ -174,8 +173,8 @@ defineExpose({ open, close }) | |
| </div> | ||
| <!-- 关联问题 --> | ||
| <ParagraphQuestions | ||
| v-if="hasProblemReadPermission()" | ||
| 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. The diff is small, but there are a few things to verify and potential improvements:
Overall, the change is reasonable if the goal is to avoid mounting |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ const props = defineProps<{ | |
| knowledgeId: string | ||
| documentId: string | ||
| paragraphId?: string | ||
| show: boolean | ||
| }>() | ||
| const { resourceApi } = useDocumentDetailContext() | ||
| const relatedProblems = defineModel<ParagraphQuestionDraft[]>({ required: true }) | ||
|
|
@@ -142,7 +141,7 @@ function handleRemoveProblem(index: number) { | |
| </script> | ||
|
|
||
| <template> | ||
| <aside v-if="show" v-loading="loading" class="mk-gray-card-lg flex-column w-60 shrink-0"> | ||
| <aside v-loading="loading" class="mk-gray-card-lg flex-column w-60 shrink-0"> | ||
| <div class="mb-4 flex-between shrink-0 gap-3"> | ||
| <h4>{{ t('knowledge.paragraph.relatedQuestions.label') }}</h4> | ||
| <!-- 添加关联问题 --> | ||
|
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 removes the Potential Issues
Suggestions
Summary: The change is safe only if (a) all consumers no longer pass |
||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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 of the Diff
What changed
ParagraphQuestionswas always rendered; visibility was delegated to the child via a:showprop driven byknowledgeQuestionPermission().v-if="knowledgeQuestionPermission()", and theshowprop is removed.Potential issues
Permission function called during render —
knowledgeQuestionPermission()is invoked on every re-render. If it performs non-trivial work (API calls, store lookups, deep checks), this hurts performance. Prefer a computed:then
v-if="canShowQuestions". A computed also avoids redundant recomputation across renders.Loss of child-side control — Removing
:showshifts behavior from "child decides how to hide" (e.g., keeps state/mounted instance) to "parent unmounts." Confirm the child doesn't rely on being mounted while hidden (e.g., internal watchers, form init, telemetry). If it does,v-showmay be more appropriate thanv-if.v-if+v-modelinteraction — When permission flips false→true, the component remounts. Any local edits inrelatedQuestionsheld inside the child could be reset. Ensurev-modelbinding survives remount correctly.Reactivity assumption —
v-ifrequiresknowledgeQuestionPermission()to be reactive (depends on refs/reactive state). If permission comes from a non-reactive source (plain function reading a module variable), the block won't update. Verify reactivity.Stale prop type / unused prop in child — Since
:showwas removed, check thatParagraphQuestionsno longer declares/expects a requiredshowprop and that its internal logic doesn't still gate on it (dead code / warnings).Naming consistency —
knowledgeQuestionPermission()reads like a boolean getter; consider naming ithasKnowledgeQuestionPermissionfor clarity, or exposing it as a computed boolean directly in the template.Nested single-condition
v-if— Fine here, but if more conditions are added later, consider computing a single predicate to keep the template clean.Optimization suggestion
Verdict
The change itself is reasonable and arguably cleaner (permission gating at the parent avoids rendering an unauthorized component at all). Main risks are: calling a possibly non-reactive/expensive function in the template, and behavioral differences from
remountvshide. Address those two and the diff is sound.