Repository navigation
fix: has "view" permission for shared resource tools but cannot view details - #8169
Conversation
| if (!canOpenEditTool(tool)) return | ||
| return editToolFormRef.value?.open(tool) | ||
| } | ||
|
|
There was a problem hiding this comment.
Looking at this diff, here are my observations:
Correctness / Potential Issues
-
Naming mismatch —
viewableTypesvs. actual intent. The variable is namedviewableTypes, implying "readable", but the function iscanOpenEditTooland it gates opening an edit form. Usingperm.tool.share.read()to gate an edit action is semantically questionable. If a user only hasreadpermission, opening an edit form may allow them to attempt edits that will fail server-side, or worse, silently surface editable UI. Consider whetherreadgenuinely grants "open edit form" semantics, or if the form is read-only in that case. -
ToolItem/TOOL_TYPEtypes not shown. Confirmtool.tool_typeis always defined and matchesToolType. Iftool_typecan beundefined/null,includeswill safely returnfalse(fine), but worth confirming the type allows this. -
Early-return ordering.
if (perm.tool.share.edit()) return trueshort-circuits before checking tool type. This means a user witheditpermission can open the form for any tool type, including ones not inviewableTypes. Is that intended? If some tool types (e.g. a future type) should never be opened, the current logic bypasses that guard for editors. Likely fine, but worth documenting. -
Permission checks called repeatedly.
perm.tool.share.edit()andperm.tool.share.read()are invoked on each call. If these are getters that recompute/traverse state, consider hoisting or memoizing — minor.
Optimization / Style Suggestions
-
Hoist constant array.
viewableTypesis allocated on every call. Move it to module scope:const EDITABLE_VIEW_TYPES: ReadonlySet<ToolType> = new Set([ TOOL_TYPE.CUSTOM, TOOL_TYPE.MCP, TOOL_TYPE.SKILL, TOOL_TYPE.DATA_SOURCE, ])
Then use
EDITABLE_VIEW_TYPES.has(tool.tool_type)— clearer intent and avoids array re-creation + O(n)includes. -
Rename for clarity. Either rename to reflect intent (e.g.
readableEditTypesorsupportedTypes) or add a comment explaining whyreadpermission suffices to open the edit form for these types. -
Type narrowing. If
tool.tool_typecould be a broader type, ensureSet<ToolType>membership check is type-safe; otherwise anarrowinghelper/type-guard could improve safety. -
Return type annotation on
canOpenEditTool(: boolean) would aid readability and catch accidental truthy returns. -
Test coverage. Since the gating logic changed from a single permission to a composite rule, add unit tests for the matrix:
{edit: yes/no} × {type in set: yes/no} × {read: yes/no}to prevent regressions.
The change itself is small and safe; the main concern is the semantic coupling of a read permission to an "open edit form" action (#1), which you should confirm is truly intended behavior.
fix: has "view" permission for shared resource tools but cannot view details