From c933732b1d7323706d841c923fc87cdc824194a6 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 4 May 2022 11:32:09 -0400 Subject: [PATCH 1/6] Fix stray non-breaking typo in workflows.py. --- lib/galaxy/webapps/galaxy/services/workflows.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/galaxy/webapps/galaxy/services/workflows.py b/lib/galaxy/webapps/galaxy/services/workflows.py index 4f056978b83..c8c754d2f67 100644 --- a/lib/galaxy/webapps/galaxy/services/workflows.py +++ b/lib/galaxy/webapps/galaxy/services/workflows.py @@ -115,7 +115,6 @@ class WorkflowsService(ServiceBase): parsed_search = parse_filters_structured(search_query, INDEX_SEARCH_FILTERS) def tag_filter(term_text: str, quoted: bool): - term_text = term.text if ":" in term_text: key, value = term_text.rsplit(":", 1) if not quoted: From d2e555d0a73b66d0d0fa0781c161dbd4db9afb61 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Fri, 29 Apr 2022 12:00:52 -0400 Subject: [PATCH 2/6] Docs for workflow index filter tags. --- lib/galaxy/webapps/galaxy/api/__init__.py | 57 ++++++++++++++++++++++ lib/galaxy/webapps/galaxy/api/workflows.py | 29 +++++++++-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/api/__init__.py b/lib/galaxy/webapps/galaxy/api/__init__.py index 33d136bb7c9..9bcd7894e92 100644 --- a/lib/galaxy/webapps/galaxy/api/__init__.py +++ b/lib/galaxy/webapps/galaxy/api/__init__.py @@ -3,10 +3,12 @@ This module *does not* contain API routes. It exclusively contains dependencies """ import inspect from enum import Enum +from string import Template from typing import ( Any, AsyncGenerator, cast, + NamedTuple, Optional, Tuple, Type, @@ -410,3 +412,58 @@ async def try_get_request_body_as_json(request: Request) -> Optional[Any]: body = await request.json() return body return None + + +search_description_template = Template( + """A mix of free text and GitHub-style tags used to filter the index operation. + +## Query Structure + +GitHub-style filter tags (not be confused with Galaxy tags) are tags of the form +`:` or `:''`. The tag name +*generally* (but not exclusively) corresponds to the name of an attribute on the model +being indexed (i.e. a column in the database). + +If the tag is quoted, the attribute will be filtered exactly. If the tag is unquoted, +generally a partial match will be used to filter the query (i.e. in terms of the implementation +this means the database operation `ILIKE` will typically be used). + +Once the tagged filters are extracted from the search query, the remaing text is just +used to search various documented attributes of the object. + +## GitHub-style Tags Available + +${tags} + +## Free Text + +Free text search terms will be searched against the following attributes of the +${model_name}s: ${freetext}. + +""" +) + + +class IndexQueryTag(NamedTuple): + tag: str + description: str + alias: Optional[str] = None + + def as_markdown(self): + desc = self.description + alias = self.alias + if alias: + desc += f" (The tag `{alias}` can be used a short hand alias for this tag to filter on this attribute.)" + return f"`{self.tag}`\n: {desc}" + + +def search_query_param(model_name: str, tags: list, free_text_fields: list) -> Optional[str]: + tags_markdown_str = "\n\n".join([t.as_markdown() for t in tags]) + description = search_description_template.safe_substitute( + model_name=model_name, tags=tags_markdown_str, freetext=", ".join([f"`{t}`" for t in free_text_fields]) + ) + return Query( + default=None, + title="Search query.", + description=description, + ) diff --git a/lib/galaxy/webapps/galaxy/api/workflows.py b/lib/galaxy/webapps/galaxy/api/workflows.py index e45e838710a..df23c878b2c 100644 --- a/lib/galaxy/webapps/galaxy/api/workflows.py +++ b/lib/galaxy/webapps/galaxy/api/workflows.py @@ -85,7 +85,9 @@ from . import ( BaseGalaxyAPIController, depends, DependsOnTrans, + IndexQueryTag, Router, + search_query_param, ) log = logging.getLogger(__name__) @@ -1442,10 +1444,27 @@ OffsetQueryParam: Optional[int] = Query( title="Number of workflows to skip in sorted query (to enable pagination).", ) -SearchQueryParam: Optional[str] = Query( - default=None, - title="Search query.", - description="Free text used to filter the query. Filters on a name and tags, Github-style tags can be used to be more specific. Free-text search is case-insensitive.", +query_tags = [ + IndexQueryTag("name", "The stored workflow's name.", "n"), + IndexQueryTag( + "tag", + "The workflow's tag, if the tag contains a colon an approach will be made to match the key and value of the tag separately.", + "t", + ), + IndexQueryTag( + "is:published", + "Include only published workflows in the final result. Be sure the the query parameter `show_published` is set to `true` if to include all published workflows and not just the requesting user's.", + ), + IndexQueryTag( + "is:share_with_me", + "Include only workflows shared with the requesting user. Be sure the the query parameter `show_shared` is set to `true` if to include shared workflows.", + ), +] + +SearchQueryParam: Optional[str] = search_query_param( + model_name="Stored Workflow", + tags=query_tags, + free_text_fields=["name", "tag"], ) SkipStepCountsQueryParam: bool = Query( @@ -1480,7 +1499,7 @@ class FastAPIWorkflows: search: Optional[str] = SearchQueryParam, skip_step_counts: bool = SkipStepCountsQueryParam, ) -> List[Dict[str, Any]]: - """Return the sharing status of the item.""" + """Lists stored workflows viewable by the user.""" payload = WorkflowIndexPayload( show_published=show_published, show_hidden=show_hidden, From caa5c56a0a9eabdaaf357f1a86fae84d8a8d6962 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Tue, 3 May 2022 19:46:23 -0400 Subject: [PATCH 3/6] Allow filtering workflows on sharing tags. Implement is:published and is:shared_with_me in the query 'search' parameter. --- .../src/components/Workflow/WorkflowList.vue | 23 ++++++++++++---- .../src/components/Workflow/Workflows.test.js | 26 +++++++++++++++++++ .../webapps/galaxy/services/workflows.py | 9 +++++++ lib/galaxy_test/api/test_workflows.py | 18 +++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/client/src/components/Workflow/WorkflowList.vue b/client/src/components/Workflow/WorkflowList.vue index 63d0803d263..a52c960bfd0 100644 --- a/client/src/components/Workflow/WorkflowList.vue +++ b/client/src/components/Workflow/WorkflowList.vue @@ -62,8 +62,18 @@