Repository navigation
fix: workspace trigger error #7790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -230,7 +230,7 @@ onMounted(() => loadTriggers()) | |||||||||||||
|
|
||||||||||||||
| <div class="flex"> | ||||||||||||||
| <!-- 编辑当前触发器 --> | ||||||||||||||
| <MkTooltip content="编辑" placement="top" v-if="perm.trigger.edit()"> | ||||||||||||||
| <MkTooltip content="编辑" placement="top"> | ||||||||||||||
| <el-button type="primary" text @click.stop="handleOpenTriggerDrawer(row)"> | ||||||||||||||
| <MkIcon name="icon_edit_outlined" /> | ||||||||||||||
| </el-button> | ||||||||||||||
|
|
@@ -265,5 +265,5 @@ onMounted(() => loadTriggers()) | |||||||||||||
| </template> | ||||||||||||||
| </MkViewLayout> | ||||||||||||||
| <TriggerTaskRecordDrawer ref="recordDrawerRef" /> | ||||||||||||||
| <TriggerFormDrawer ref="triggerDrawerRef" @refresh="loadTriggers" /> | ||||||||||||||
| <TriggerFormDrawer :can-edit="perm.trigger.edit()" ref="triggerDrawerRef" @refresh="loadTriggers" /> | ||||||||||||||
| </template> | ||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the analysis of the provided code snippets, focusing on security, logic consistency, and UI/UX implications. 1. Critical Security & Logic Issue: Permission Enforcement Moved to Child ComponentThe most significant change is moving the permission check
<!-- RECOMMENDED CHANGE -->
<MkTooltip
content="编辑"
placement="top"
v-if="perm.trigger.edit()"> <!-- Keep this -->
<el-button
type="primary" text
@click.stop="handleOpenTriggerDrawer(row)">
<MkIcon name="icon_edit_outlined" />
</el-button>
</MkTooltip>
<!-- Then pass permission to child if needed for fine-grained control -->
<TriggerFormDrawer
:can-edit="perm.trigger.edit()"
ref="triggerDrawerRef"
@refresh="loadTriggers" />2. Potential Prop Naming & Type Safety
3. Unused Import / Variable Warning (Contextual)Check if 4. Performance Consideration
Summary of Recommendations
Fixed Code Example<!-- Template -->
<div class="flex">
<!-- Edit current trigger -->
<MkTooltip content="编辑" placement="top" v-if="perm.trigger.edit()">
<el-button type="primary" text @click.stop="handleOpenTriggerDrawer(row)">
<MkIcon name="icon_edit_outlined" />
</el-button>
</MkTooltip>
<!-- ... other buttons ... -->
</div>
<!-- ... -->
<TriggerTaskRecordDrawer ref="recordDrawerRef" />
<TriggerFormDrawer
:can-edit="perm.trigger.edit()"
ref="triggerDrawerRef"
@refresh="loadTriggers" /> |
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,9 @@ const props = withDefaults( | |
| applicationApi?: typeof ApplicationApi | typeof SystemResourceApplicationApi | ||
| toolApi?: typeof ToolApi | typeof SystemToolApi | ||
| toolWorkflowApi?: typeof WorkflowApi | ||
| canEdit?: boolean | ||
| }>(), | ||
| { resourceApi: () => ResourceTriggerApi, applicationApi: () => ApplicationApi, toolApi: () => ToolApi, toolWorkflowApi: () => WorkflowApi }, | ||
| { resourceApi: () => ResourceTriggerApi, applicationApi: () => ApplicationApi, toolApi: () => ToolApi, toolWorkflowApi: () => WorkflowApi, canEdit: true }, | ||
| ) | ||
| const emit = defineEmits<{ refresh: []; closed: [] }>() | ||
| /* 抽屉生命周期与详情 */ | ||
|
|
@@ -432,7 +433,7 @@ defineExpose({ open }) | |
| <!-- 取消触发器编辑 --> | ||
| <el-button plain :disabled="saving" @click="visible = false">取消</el-button> | ||
| <!-- 保存触发器配置 --> | ||
| <el-button type="primary" :loading="saving" :disabled="loading || detailFailed" @click="handleSave"> | ||
| <el-button v-if="canEdit" type="primary" :loading="saving" :disabled="loading || detailFailed" @click="handleSave"> | ||
| {{ editingId ? '保存' : '创建' }} | ||
| </el-button> | ||
| </template> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a review of the provided code diff with identified issues, potential problems, and optimization suggestions. 1. Critical Issue: Prop Default SyntaxLocation: The syntax
✅ Recommendation: Ensure consistency. While 2. UI/UX Logic Flaw: Missing "Cancel" Button ConditionalityLocation: <el-button plain :disabled="saving" @click="visible = false">取消</el-button>
<el-button v-if="canEdit" type="primary" ... >Save/Create</el-button>If
3. Accessibility & Semantics:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an analysis of the provided code snippet, focusing on correctness, best practices, and potential issues.
1. Vue Directive Order /
:vsv-bind:can-edit="applicationTriggerPermission('triggerEdit')", you are using shorthand binding (:) but placed it at the end of a list that already includes both static props and event handlers. While syntactically valid in Vue 3, mixing@eventand:propwithout clear grouping can reduce readability.:can-editis a valid prop for the component (not covered here).2. Permission Logic Shift
v-if="applicationTriggerPermission('triggerEdit')"check was removed from the button and moved into a:can-editprop passed to a child component.can-editprop (e.g., ignores it when rendering internal buttons), users without permission might still see interactive elements or trigger unintended actions.can-editcorrectly, this is a good refactoring as it centralizes permission logic inside the child.TriggerFormDialogor similar) properly evaluatesprops.canEditbefore enabling editing controls.v-if) is preferable for performance/UX consistency if the child always shows some UI regardless.3. Removal of
v-ifvs. Prop-based Controlv-if. If unauthorized, no element rendered.applicationTriggerPermission()is expensive or asynchronous, consider caching the result or using a computed property to avoid recalculating on every render.4. Naming Convention
:can-editis kebab-case, which is correct for Vue templates. Ensure the corresponding prop in the child component is defined as eithercanEdit(camelCase in script/setup) or explicitly declared with hyphenated name if needed (Vue handles conversion automatically).5. General Best Practice
applicationTriggerPermission()is called multiple times in the template (as it likely is now in two places: previously button, now prop), wrap it in a computed property for efficiency:Then use
:can-edit="hasEditPermission".✅ Suggested Improved Code Snippet:
Summary of Actions:
:can-edit.v-if).