Repository navigation
feat: system shared knowledge MCP permission - #7765
Conversation
| mcpConfig: () => canSys(P.SHARED_KNOWLEDGE_MCP_CONFIG), | ||
| /** | ||
| * 系统「共享知识库」查看关联资源权限 | ||
| */ |
There was a problem hiding this comment.
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 functionmcpConfig: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
publishmight be defined ifpublishalso had a preceding comment.
2. Optimization Suggestions:
- Consistency Check: Ensure
P.SHARED_KNOWLEDGE_MCP_CONFIGis 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
mcpConfigis clear and consistent with the existingpublishproperty, 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.
| v-if="perm.knowledge.share.mcpConfig()" | ||
| /> | ||
|
|
||
| <!-- 授权工作空间 --> |
There was a problem hiding this comment.
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:
permexists.perm.knowledgeexists.shareexists withinperm.knowledge.mcpConfigis 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 acomputedproperty 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?.())
)
feat: system shared knowledge MCP permission