diff --git a/cylc/uiserver/resolvers.py b/cylc/uiserver/resolvers.py index 621906df..9a145c44 100644 --- a/cylc/uiserver/resolvers.py +++ b/cylc/uiserver/resolvers.py @@ -189,7 +189,8 @@ def __init__(self, data, log, **kwargs): # Mutations async def mutator(self, info, *m_args): """Mutate workflow.""" - _, w_args, _ = m_args + _, w_args, _, _ = m_args + auth_user = info.context.get('current_user', 'unknown user') w_ids = [ flow[WORKFLOW].id for flow in await self.get_workflows_data(w_args)] @@ -209,7 +210,7 @@ async def mutator(self, info, *m_args): 'variables': variables, } return await self.workflows_mgr.multi_request( - 'graphql', w_ids, graphql_args + 'graphql', w_ids, graphql_args, auth_user=auth_user ) async def service(self, info, *m_args): @@ -229,6 +230,8 @@ async def nodes_mutator(self, info, *m_args): if not w_ids: return [{ 'response': (False, 'No matching workflows')}] + auth_user = info.context.get('current_user', 'unknown user') + # Pass the multi-node request to the workflow GraphQL endpoints _, variables, _, _ = info.context.get('graphql_params') @@ -243,5 +246,5 @@ async def nodes_mutator(self, info, *m_args): } multi_args = {w_id: graphql_args for w_id in w_ids} return await self.workflows_mgr.multi_request( - 'graphql', w_ids, multi_args=multi_args + 'graphql', w_ids, multi_args=multi_args, auth_user=auth_user ) diff --git a/cylc/uiserver/tests/conftest.py b/cylc/uiserver/tests/conftest.py index 02520f2a..23b993cb 100644 --- a/cylc/uiserver/tests/conftest.py +++ b/cylc/uiserver/tests/conftest.py @@ -51,7 +51,9 @@ def __init__(self): def will_return(self, returns): self.returns = returns - async def async_request(self, command, args=None, timeout=None): + async def async_request( + self, command, args=None, timeout=None, auth_user=None + ): if ( inspect.isclass(self.returns) and issubclass(self.returns, Exception) diff --git a/cylc/uiserver/workflows_mgr.py b/cylc/uiserver/workflows_mgr.py index 3aede578..de2823b8 100644 --- a/cylc/uiserver/workflows_mgr.py +++ b/cylc/uiserver/workflows_mgr.py @@ -53,6 +53,7 @@ async def workflow_request( req_context=None, *, log=None, + auth_user=None ): """Workflow request command. @@ -70,7 +71,8 @@ async def workflow_request( if req_context is None: req_context = command try: - result = await client.async_request(command, args, timeout) + result = await client.async_request( + command, args, timeout, auth_user=auth_user) return (req_context, result) except ClientTimeout as exc: if log: @@ -271,7 +273,8 @@ async def multi_request( workflows, args=None, multi_args=None, - timeout=None + timeout=None, + auth_user=None ): """Send requests to multiple workflows.""" if args is None: @@ -288,7 +291,12 @@ async def multi_request( if w_id in self.active } gathers = [ - workflow_request(req_context=info, *request_args, log=self.log) + workflow_request( + req_context=info, + *request_args, + log=self.log, + auth_user=auth_user + ) for info, request_args in req_args.items() ] results = await asyncio.gather(*gathers, return_exceptions=True)