Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions ui/src/permission/modules/knowledge/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const share = {
* 系统「共享知识库」发布权限
*/
publish: () => canSys(P.SHARED_KNOWLEDGE_WORKFLOW_PUBLISH),
/**
* 系统「共享知识库」MCP配置详情权限
*/
mcpConfig: () => canSys(P.SHARED_KNOWLEDGE_MCP_CONFIG),
/**
* 系统「共享知识库」查看关联资源权限
*/

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.

Here is the analysis of the provided code snippet:

1. Irregularities & Issues:

  • Inconsistent Indentation: The added comment and property (mcpConfig) use a mix of indentation levels that likely do not match the surrounding file's standard (which appears to use 2 spaces). The comment /** starts at column 0, while the function mcpConfig: starts with 2 spaces. If the surrounding code uses 2 spaces for properties, the comment should also be indented accordingly.
  • JSDoc Placement: While technically valid, placing the JSDoc comment immediately before the property without a blank line from the previous block can reduce readability if the previous block did not have its own comment. However, in this diff context, it seems consistent with how publish might be defined if publish also had a preceding comment.

2. Optimization Suggestions:

  • Consistency Check: Ensure P.SHARED_KNOWLEDGE_MCP_CONFIG is actually defined in your permissions enum/map. If this constant is missing or misspelled, the application will fail or behave unexpectedly.
  • Naming Convention: The name mcpConfig is clear and consistent with the existing publish property, assuming other permissions follow simple camelCase naming for feature-specific access.

3. Recommended Fix:

const share = {
    /**
     * 系统「共享知识库」发布权限
     */
    publish: () => canSys(P.SHARED_KNOWLEDGE_WORKFLOW_PUBLISH),
    /**
     * 系统「共享知识库」MCP配置详情权限
     */
    mcpConfig: () => canSys(P.SHARED_KNOWLEDGE_MCP_CONFIG), // Ensure this constant exists
    /**
     * 系统「共享知识库」查看关联资源权限
     */
    // ... rest of the code
}

Summary: The logic is sound and follows the existing pattern. The primary recommendation is to verify the existence of P.SHARED_KNOWLEDGE_MCP_CONFIG and ensure indentation matches your project's linting rules.

Expand Down
1 change: 1 addition & 0 deletions ui/src/views/system/shared-resources/knowledge/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function handleSearchChange(query?: Dict<unknown>) {
label="MCP 服务配置"
:api="SystemSharedKnowledgeApi"
:knowledge="knowledge"
v-if="perm.knowledge.share.mcpConfig()"
/>

<!-- 授权工作空间 -->

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.

Here is the review of the provided code snippet:

1. Syntax Error (Critical)

The most significant issue is that v-if is placed after the component’s props/attributes and before the closing bracket (/>). In Vue templates, directives (like v-if, v-for) should typically preced other attributes or at least be clearly separated. While some parsers might tolerate this, it is bad practice and can lead to unexpected behavior or linting errors.

✅ Fix: Move v-if to the beginning of the tag.

-                  <component-or-tag
+                  <component-or-tag
+                    v-if="perm.knowledge.share.mcpConfig()"
                     label="MCP 服务配置"
                     :api="SystemSharedKnowledgeApi"
                     :knowledge="knowledge"
-                    v-if="perm.knowledge.share.mcpConfig()"
                   />

2. Potential Runtime Error

The expression perm.knowledge.share.mcpConfig() assumes that:

  • perm exists.
  • perm.knowledge exists.
  • share exists within perm.knowledge.
  • mcpConfig is a method/function.

If any intermediate object in this chain is undefined or null, this will throw a TypeError: Cannot read properties of undefined (reading '...').

✅ Optimization/Safety: Add optional chaining (?.) to make it safe.

v-if="perm?.knowledge?.share?.mcpConfig?"

Note: Be careful with function calls in templates. If mcpConfig() is an expensive operation, calling it on every re-render may cause performance issues. It’s better to compute this value in a computed property or a data ref.

3. Performance & Best Practice

Calling methods like mcpConfig() directly in a template is discouraged in Vue because:

  • It triggers on every component re-render.
  • It’s not cached by Vue’s reactivity system (unlike computed properties).

✅ Suggestion: Wrap the condition in a computed property.

// In <script setup> or Options API computed
const showMcpConfig = computed(() => 
  perm?.value?.knowledge?.share?.mcpConfig?.() ?? false
)
<!-- In template -->
v-if="showMcpConfig"

4. Localization/I18n (Minor)

The label "MCP 服务配置" is hardcoded. If your application supports multiple languages, consider using i18n (e.g., t('key.mcpConfig')).


✅ Recommended Final Code

<SomeComponent
  v-if="showMcpConfig"
  label="MCP 服务配置"
  :api="SystemSharedKnowledgeApi"
  :knowledge="knowledge"
/>

With corresponding script logic:

const showMcpConfig = computed(() => 
  Boolean(perm.value?.knowledge?.share?.mcpConfig?.())
)

Expand Down
Loading