2929 WorkflowLandingRequest ,
3030)
3131from galaxy .security .idencoding import IdEncodingHelper
32- from galaxy .structured_app import StructuredApp
32+ from galaxy .structured_app import (
33+ MinimalManagerApp ,
34+ StructuredApp ,
35+ )
36+ from galaxy .tool_util .parameters import (
37+ landing_decode ,
38+ LandingRequestInternalToolState ,
39+ LandingRequestToolState ,
40+ )
3341from galaxy .util import safe_str_cmp
3442from .context import ProvidesUserContext
43+ from .tools import (
44+ get_tool_from_toolbox ,
45+ ToolRunReference ,
46+ )
3547
3648LandingRequestModel = Union [ToolLandingRequestModel , WorkflowLandingRequestModel ]
3749
@@ -43,16 +55,37 @@ def __init__(
4355 sa_session : galaxy_scoped_session ,
4456 security : IdEncodingHelper ,
4557 workflow_contents_manager : WorkflowContentsManager ,
58+ app : MinimalManagerApp ,
4659 ):
4760 self .sa_session = sa_session
4861 self .security = security
4962 self .workflow_contents_manager = workflow_contents_manager
63+ self .app = app
5064
5165 def create_tool_landing_request (self , payload : CreateToolLandingRequestPayload , user_id = None ) -> ToolLandingRequest :
66+ tool_id = payload .tool_id
67+ tool_version = payload .tool_version
68+ request_state = payload .request_state
69+
70+ ref = ToolRunReference (tool_id = tool_id , tool_version = tool_version , tool_uuid = None )
71+ tool = get_tool_from_toolbox (self .app .toolbox , ref )
72+ landing_request_state = LandingRequestToolState (request_state or {})
73+ # Okay this is a hack until tool request API commit is merged, tools don't yet have a parameter
74+ # schema - so we can't do this properly.
75+ if hasattr (tool , "parameters" ):
76+ internal_landing_request_state = landing_decode (landing_request_state , tool , self .security .decode_id )
77+ else :
78+ assert tool .id == "__DATA_FETCH__"
79+ # we have validated the payload as part of the API request
80+ # nothing else to decode ideally so just swap to internal model state object
81+ internal_landing_request_state = LandingRequestInternalToolState (
82+ input_state = landing_request_state .input_state
83+ )
84+
5285 model = ToolLandingRequestModel ()
53- model .tool_id = payload . tool_id
54- model .tool_version = payload . tool_version
55- model .request_state = payload . request_state
86+ model .tool_id = tool_id
87+ model .tool_version = tool_version
88+ model .request_state = internal_landing_request_state . input_state
5689 model .uuid = uuid4 ()
5790 model .client_secret = payload .client_secret
5891 model .public = payload .public
0 commit comments