Repository navigation
feat: workspace tool edit permission #7781
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 |
|---|---|---|
|
|
@@ -10,6 +10,17 @@ import DataSourceFormDrawer from '@/views/tool/tool-form/DataSourceFormDrawer.vu | |
| import McpFormDrawer from '@/views/tool/tool-form/McpFormDrawer.vue' | ||
| import SkillToolFormDrawer from '@/views/tool/tool-form/SkillToolFormDrawer.vue' | ||
| import WorkflowFormDialog from '@/views/tool/tool-form/WorkflowFormDialog.vue' | ||
| import { computed } from 'vue' | ||
| import perm from '@/permission/index.ts' | ||
| import { isSystemResource, isSystemSharedResource } from '@/utils/resource-context' | ||
|
|
||
| const canEdit = computed(() => { | ||
| const id = tool.value?.id | ||
| if (!id) return false | ||
| if (isSystemResource()) return perm.tool.system.edit() | ||
| if (isSystemSharedResource()) return perm.tool.share.edit() | ||
| return perm.tool.workspace.edit(id) | ||
| }) | ||
|
|
||
| defineOptions({ name: 'EditToolForm' }) | ||
|
|
||
|
|
@@ -95,6 +106,7 @@ defineExpose({ open }) | |
| :folder-id="tool.folder_id ?? ''" | ||
| @closed="handleFormClosed" | ||
| @update="emit('update', $event)" | ||
| :can-edit="canEdit" | ||
| /> | ||
| </template> | ||
| </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. ReviewPotential issues
Optimization suggestions
VerdictFunctionally looks correct assuming |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,10 @@ defineOptions({ name: 'ToolFormDrawer' }) | |
|
|
||
| const { auth } = useStore() | ||
|
|
||
| const props = defineProps<{ api: typeof ToolApi | typeof SystemSharedToolApi | typeof SystemResourceToolApi; title: string; folderId: string }>() | ||
| const props = withDefaults( | ||
| defineProps<{ api: typeof ToolApi | typeof SystemSharedToolApi | typeof SystemResourceToolApi; title: string; folderId: string; canEdit?: boolean }>(), | ||
| { canEdit: true }, | ||
| ) | ||
|
|
||
| const emit = defineEmits<{ closed: []; refresh: []; update: [tool: ToolItem] }>() | ||
|
|
||
|
|
@@ -228,8 +231,8 @@ defineExpose({ open }) | |
|
|
||
| <template #footer> | ||
| <el-button plain :disabled="loading || formLoading" @click="handleBeforeClose">取消</el-button> | ||
| <el-button plain :disabled="loading || formLoading" @click="handleOpenDebug">调试</el-button> | ||
| <el-button type="primary" :disabled="formLoading" :loading="loading" @click="handleSubmit"> | ||
| <el-button v-if="canEdit" plain :disabled="loading || formLoading" @click="handleOpenDebug">调试</el-button> | ||
| <el-button v-if="canEdit" type="primary" :disabled="formLoading" :loading="loading" @click="handleSubmit"> | ||
| {{ editId ? '保存' : '创建' }} | ||
| </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. Review1. Prop name
|
||
|
|
||
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.
Code Review
Issues Found
1. Permission regression:
edit→read(likely a bug)The function is named
handleOpenEditTooland opens an edit form (editToolFormRef). Gatekeeping it withread()instead ofedit(tool.id)means:edit(tool.id)(per-tool check) toread()(no tool argument). Ifread()is workspace-wide, you lose per-tool granularity.Recommendation: Keep
perm.tool.workspace.edit(tool.id). If a read-then-edit flow is intentional, rename the function or split into separate open/view handlers.2. Inconsistent indentation
+return editToolFormRef.value?.open(tool)The
+returnline lost its two-space indentation relative to the function body. This will fail lint/prettier checks in most setups.Fix:
3. API signature mismatch on
read()edit(tool.id)accepts an argument;read()is called with none. Confirm the permission API actually exposesread()(vs. e.g.read(tool.id)), otherwise this throws or silently returns undefined.4. Silent failure — no user feedback
When the permission check fails, the function silently returns. Consider surfacing a toast/notification ("No permission to edit this tool") so users understand why nothing happened. Same issue pre-existed, but it's worth addressing while touching this code.
5.
returntype inconsistencyThe first branch returns implicitly
undefined; the second returns the result of?.open(...)(boolean | undefinedor whateveropenreturns). Not wrong, but if callers ever rely on the return value, define an explicit return type (e.g.: void) to avoid surprises.Suggested Refactor
Bottom line: The diff introduces what looks like an unintended permission downgrade and a formatting glitch. Verify whether switching from
edit(tool.id)toread()was intentional — if not, revert it.