Skip to content

feat: system shared knowledge MCP permission - #7765

Merged
peslyn merged 1 commit into
v3from
pr@v3@feat_system_shared_knowledge_mcp_permission
Nov 9, 2026
Merged

peslyn merged 1 commit into
v3from
pr@v3@feat_system_shared_knowledge_mcp_permission

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

feat: system shared knowledge MCP permission

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.

@peslyn
peslyn merged commit 2a98267 into v3 Nov 9, 2026
3 of 4 checks passed
@peslyn
peslyn deleted the pr@v3@feat_system_shared_knowledge_mcp_permission branch November 9, 2026 09:18
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?.())
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants