Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/views/knowledge-detail/library/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ onBeforeUnmount(() => {
>
<template v-if="showQuickCreate && !isWorkspaceSharedResource()" #body-prepend>
<!-- 快速创建空白文档 -->
<MkQuickCreate ref="quickCreateRef" text="快速创建空白文档" placeholder="请输入文档名称" @create="handleCreateDocument" />
<MkQuickCreate v-if="knowledgeDocPermission('docCreate')" ref="quickCreateRef" text="快速创建空白文档" placeholder="请输入文档名称" @create="handleCreateDocument" />
</template>

<el-table-column type="selection" width="40" reserve-selection v-if="!isWorkspaceSharedResource()" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
⚠️ Caution: Avoid direct function invocations inside templates for better performance; prefer computed properties.
💡 Suggestion: Confirm no overlap between existing flags like showQuickCreate and new permission gate for logical clarity.

Expand Down
Loading