Skip unprivileged tool resolution if we don't have appropriate permissions

This commit is contained in:
mvdbeek
2025-05-12 10:54:53 +02:00
parent 74a6f31f4f
commit 7c52e9fc79
4 changed files with 15 additions and 6 deletions
+1 -1
View File
@@ -735,7 +735,7 @@ class AbstractToolBox(ManagesIntegratedToolPanelMixin):
) -> Union[Optional["Tool"], List["Tool"]]:
"""Attempt to locate a tool in the tool box. Note that `exact` only refers to the `tool_id`, not the `tool_version`."""
if tool_uuid and user:
unprivileged_tool = self.get_unprivileged_tool(user, tool_uuid=tool_uuid)
unprivileged_tool = self.get_unprivileged_tool_or_none(user, tool_uuid=tool_uuid)
if unprivileged_tool:
return unprivileged_tool
if tool_version:
+6
View File
@@ -625,6 +625,12 @@ class ToolBox(AbstractToolBox):
dynamic_tool = self.app.dynamic_tool_manager.get_unprivileged_tool_by_uuid(user, tool_uuid)
return self.dynamic_tool_to_tool(dynamic_tool)
def get_unprivileged_tool_or_none(self, user: model.User, tool_uuid: Union[UUID, str]) -> Optional["Tool"]:
try:
return self.get_unprivileged_tool(user, tool_uuid=tool_uuid)
except exceptions.InsufficientPermissionsException:
return None
def dynamic_tool_to_tool(self, dynamic_tool: Optional[model.DynamicTool]) -> Optional["Tool"]:
if dynamic_tool and dynamic_tool.active and dynamic_tool.value:
tool_source = YamlToolSource(dynamic_tool.value)
+2 -2
View File
@@ -124,8 +124,8 @@ class ToolsService(ServiceBase):
raise exceptions.RequestParameterMissingException("Must specify either a tool_id or a tool_uuid.")
tool: Optional[Tool] = None
if tool_uuid:
tool = trans.app.toolbox.get_unprivileged_tool(trans.user, tool_uuid=tool_uuid)
if tool_uuid and trans.user:
tool = trans.app.toolbox.get_unprivileged_tool_or_none(trans.user, tool_uuid=tool_uuid)
if not tool:
tool = trans.app.toolbox.get_tool(**get_kwds)
if not tool:
+6 -3
View File
@@ -1859,9 +1859,12 @@ class ToolModule(WorkflowModule):
self.tool_uuid = tool_uuid
self.tool: Optional[Tool] = None
if getattr(trans.app, "toolbox", None):
self.tool = trans.app.toolbox.get_tool(
tool_id, tool_version=tool_version, exact=exact_tools, tool_uuid=tool_uuid, user=trans.user
)
if trans.user and tool_uuid:
self.tool = trans.app.toolbox.get_unprivileged_tool_or_none(trans.user, tool_uuid=tool_uuid)
if not self.tool:
self.tool = trans.app.toolbox.get_tool(
tool_id, tool_version=tool_version, exact=exact_tools, tool_uuid=tool_uuid
)
if self.tool:
current_tool_version = str(self.tool.version)
if exact_tools and self.tool_version and self.tool_version != current_tool_version: