Repository navigation
fix: application workflow permission error - #7962
Conversation
| <MkTooltip content="保存" placement="bottom" v-if="applicationWorkflowPermission('edit')"> | ||
| <el-button plain :disabled="loading" @click="handleSave()" class="w-8! min-w-8!"> | ||
| <MkIcon name="icon_save_outlined" /> | ||
| </el-button> |
There was a problem hiding this comment.
Here are my observations on the diff:
Potential issues
-
v-ifon<MkTooltip>rather than the button itself — ifMkTooltipuses a slot/teleport or Popper internally, hiding it may leave unintended behavior (e.g., an empty wrapper in DOM). It's usually safer to applyv-ifdirectly on the interactive element:<el-button v-if="applicationWorkflowPermission('edit')" ...>
Or wrap both in a
<template v-if>. -
Permission check called on every render —
applicationWorkflowPermission('edit')runs inside the template, so it will be re-evaluated on every reactivity-triggered re-render (and this looks like a toolbar item that likely re-renders frequently). Consider moving it into acomputed:const canEdit = computed(() => applicationWorkflowPermission('edit'))
Especially important because
isSystemResource()andperm.application.*calls inside the helper could have non-trivial cost or side effects. -
Consistency of permission gating — the
handleSave()handler itself is not guarded by the new'edit'permission. If the button is ever reachable via other paths (keyboard shortcut, programmatic call, stale reactive state before re-render), users withouteditpermission could still trigger save. Prefer also guarding insidehandleSave():function handleSave() { if (!applicationWorkflowPermission('edit')) return ... }
-
Naming / semantics — adding
'edit'toApplicationWorkflowPermissionMethodalongside'publish'broadens the type, but the existing permission tables (perm.application.system[...],perm.application.workspace[...]) must actually expose aneditmethod; otherwise TypeScript will complain, or worse, silently allow runtimeundefined()errors. Double-check thatperm.application.{system,workspace}.editexists and returns a boolean. -
No tooltip when hidden — using
placement="bottom"with a conditional on the tooltip means keyboard-only or screen-reader users get no affordance change; if you want better UX for permission denial, consider rendering disabled + tooltip "no permission" instead of hiding entirely (product decision, but worth noting).
Minor / style
- Attribute order — place
v-iffirst for readability:<MkTooltip v-if="..." content="保存" placement="bottom">. - The diff context has an unrelated-looking
.tsextension on imports (@/utils/resource-context.ts,@/permission/index.ts) — verify your bundler/TS config supports explicit extensions where required (Vite/ESM ok; some loaders not). - Nothing wrong with widening the union type per se, but consider whether
'edit'should map to an existing'write'/'update'perm key for consistency across the codebase.
Suggested refactor
<!-- 保存 -->
<MkTooltip v-if="canEdit" content="保存" placement="bottom">
<el-button plain :disabled="loading || !canEdit" @click="handleSave()" class="w-8! min-w-8!">
<MkIcon name="icon_save_outlined" />
</el-button>
</MkTooltip>const canEdit = computed(() => applicationWorkflowPermission('edit'))
function handleSave() {
if (!canEdit.value) return
// ...
}No functional bugs visible in the snippet itself, but points 2 and 3 (computed caching + handler-level guard) are the most important corrections.
fix: application workflow permission error