Repository navigation
fix: knowledge problem permission #7752
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 |
|---|---|---|
|
|
@@ -291,7 +291,7 @@ onMounted(() => loadProblems()) | |
| </template> | ||
| </MkTable> | ||
| <ProblemDetailDrawer | ||
| v-if="detailProblem && knowledgeProblemPermission('problemRelate')" | ||
| v-if="detailProblem && knowledgeProblemPermission('problemEdit')" | ||
| ref="problemDetailDrawerRef" | ||
| v-model="detailProblem" | ||
| :has-previous="hasPrevious" | ||
|
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 this diff: Change summary: The permission check for rendering Potential issues / irregularities:
Recommendation: If the goal is "only editors can open the detail drawer," the change is fine — just add tests and confirm backend parity. If the drawer serves viewers too, prefer keeping |
||
|
|
||
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.
Here's my review of the code changes:
Issues & Suggestions
1. Significant flaw:
knowledgeId.valueusage in a plain functionknowledgeIdis referenced but not shown as defined in this diff. If it's a ref declared after this function (e.g., below in<script setup>), this works at call time due to hoisting/closures — but it's fragile and confusing.knowledgeIdis not aref(e.g., a prop or computed differently),.valuewill beundefined. Verify its type.knowledgeIddeclaration, or passknowledgeIdas an explicit parameter for clarity.2. Style: missing spaces after commas
Inconsistent spacing (
isWorkspaceSharedResource,isSystemResource). Run Prettier/ESLint.3. Missing return fallback / exhaustive check
KnowledgeProblemPermissionMethodcurrently has only one method ('problemRelate'), so the fallthroughreturnfor workspace is fine today. But:perm.knowledge.*objects each expose the same keys.assertNever(method)pattern if this union grows.4.
v-ifplacement on<el-button>Template:
This is functionally OK, but:
v-iffirst for readability:v-if="..." plain :disabled=....knowledgeProblemPermission('problemRelate')is called on every render. Since it reads reactive refs (knowledgeId.value) and permission state, Vue will re-evaluate reliably, but ifperm.knowledge.*calls have side effects or are expensive, consider wrapping in acomputed:v-if="canRelateProblem".5.
isWorkspaceSharedResource() → falsehardcodedFine, but this bypasses any per-method logic. If later some methods should be allowed on workspace-shared resources, this becomes wrong. Document or extract into a map if it grows.
6. Naming: "问题" (problem) vs. variable
problemNo functional issue, but
knowledgeProblemPermissionnaming is consistent with the model name — good.7. Redundant
Boolean(...)castsThe
Boolean()wrappers assume theperm.*methods may return non-boolean. That's defensive and OK, but if their signatures already guaranteeboolean, the casts are noise. Keep only if you're unsure of the contract.8. Order of checks
Current priority: system → system-shared → workspace-shared → workspace. Confirm that's intended precedence. A resource being both system and shared could match multiple predicates; make sure the priority matches business rules.
9. Import ordering
Imports are appended at the top-of-file region rather than sorted alongside existing
@/imports. Consistency with project import-order lint rule would fail CI if enforced.Summary of recommended fixes
knowledgeIdis arefdeclared before use, or pass explicitlycomputedfor the templatev-ifto be the first attributeOtherwise the logic is sound and the feature (hiding "关联分段" when unauthorized) is implemented correctly.