Repository navigation
fix: knowledge quick create document permission - #7913
Conversation
| <MkQuickCreate v-if="knowledgeDocPermission('docCreate')" ref="quickCreateRef" text="快速创建空白文档" placeholder="请输入文档名称" @create="handleCreateDocument" /> | ||
| </template> | ||
|
|
||
| <el-table-column type="selection" width="40" reserve-selection v-if="!isWorkspaceSharedResource()" /> |
There was a problem hiding this comment.
The code snippet adds a permission check (v-if) to the MkQuickCreate component, which is a good security practice. However, here are some observations and suggestions:
1. Redundant Permission Check?
If showQuickCreate already implies that the user has creation permissions, adding knowledgeDocPermission('docCreate') might be redundant. Ensure that these two conditions are logically distinct or that both are strictly necessary.
2. Performance Optimization
- Calling
knowledgeDocPermission('docCreate')directly in the template may execute the function on every re-render, which can be inefficient if it involves complex logic or API calls. - Suggestion: Compute the permission result in
<script setup>using a computed property instead of calling it directly in the template.
<script setup>
import { computed } from 'vue';
const canCreateDoc = computed(() => knowledgeDocPermission('docCreate'));
</script>
<template>
<MkQuickCreate v-if="canCreateDoc" ... />
</template>3. Consistency with Other Conditions
Ensure this new condition aligns with how other permission checks are handled in the file (e.g., whether they’re always via direct function call vs. computed properties). Consistent style improves maintainability.
4. Accessibility/UX Consideration
If the button is hidden due to lack of permissions, ensure there’s still feedback if users try to access features needing these permissions elsewhere (e.g., disabled buttons + tooltip explaining why). This prevents confusion when UI elements disappear unexpectedly.
If you want a concise review summary:
✅ Fix: Adding fine-grained permissions enhances security/accessibility control.
💡 Suggestion: Confirm no overlap between existing flags like showQuickCreate and new permission gate for logical clarity.
fix: knowledge quick create document permission