Skip to content

Commit

Permalink
Merge pull request #17726 from davelopez/24.0_fix_histories_api_index…
Browse files Browse the repository at this point in the history
…_serialization

[24.0] Fix histories API index_query serialization
  • Loading branch information
mvdbeek authored Mar 17, 2024
2 parents 56ffd6b + 3578159 commit e2e6ba4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions client/src/components/Grid/configs/histories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type SortKeyLiteral = "create_time" | "name" | "update_time" | undefined;
*/
async function getData(offset: number, limit: number, search: string, sort_by: string, sort_desc: boolean) {
const { data, headers } = await historiesFetcher({
view: "summary",
limit,
offset,
search,
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/Grid/configs/historiesShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type SortKeyLiteral = "create_time" | "name" | "update_time" | undefined;
*/
async function getData(offset: number, limit: number, search: string, sort_by: string, sort_desc: boolean) {
const { data, headers } = await historiesFetcher({
view: "summary",
keys: "username,create_time",
limit,
offset,
search,
Expand Down
6 changes: 4 additions & 2 deletions lib/galaxy/webapps/galaxy/api/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def index(
trans, serialization_params, filter_query_params, deleted_only=deleted, all_histories=all
)
else:
payload = HistoryIndexQueryPayload.construct(
payload = HistoryIndexQueryPayload.model_construct(
show_own=show_own,
show_published=show_published,
show_shared=show_shared,
Expand All @@ -201,7 +201,9 @@ def index(
offset=offset,
search=search,
)
entries, total_matches = self.service.index_query(trans, payload, include_total_count=True)
entries, total_matches = self.service.index_query(
trans, payload, serialization_params, include_total_count=True
)
response.headers["total_matches"] = str(total_matches)
return entries

Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/webapps/galaxy/services/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ def index_query(
self,
trans,
payload: HistoryIndexQueryPayload,
serialization_params: SerializationParams,
include_total_count: bool = False,
) -> Tuple[List[AnyHistoryView], int]:
"""Return a list of History accessible by the user
:rtype: list
:returns: dictionaries containing History details
"""
serialization_params = SerializationParams(default_view="detailed")
entries, total_matches = self.manager.index_query(trans, payload, include_total_count)
return (
[self._serialize_history(trans, entry, serialization_params) for entry in entries],
[self._serialize_history(trans, entry, serialization_params, default_view="summary") for entry in entries],
total_matches,
)

Expand Down
50 changes: 50 additions & 0 deletions lib/galaxy_test/api/test_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,56 @@ def test_index_query(self):
assert len(index_response) == 1
assert index_response[0]["name"] == expected_history_name

def test_index_views(self):
# Make sure there is at least one history
self._create_history(f"TestHistoryForViews_{uuid4()}")["id"]
# By default the view is summary
index_response = self._get("histories").json()
for history in index_response:
assert "state" not in history

# Change the view to detailed
index_response = self._get("histories?view=detailed").json()
for history in index_response:
assert "state" in history

# Expect only specific keys
expected_keys = ["name"]
unexpected_keys = ["deleted", "state"]
index_response = self._get(f"histories?keys={','.join(expected_keys)}").json()
for history in index_response:
for key in expected_keys:
assert key in history
for key in unexpected_keys:
assert key not in history

def test_index_search_mode_views(self):
# Make sure there is at least one history
expected_name_contains = "SearchMode"
self._create_history(f"TestHistory{expected_name_contains}_{uuid4()}")["id"]
# By default the view is summary
data = dict(search=expected_name_contains, show_published=False)
index_response = self._get("histories", data=data).json()
for history in index_response:
assert "state" not in history

# Change the view to detailed
data = dict(search=expected_name_contains, show_published=False)
index_response = self._get("histories?view=detailed", data=data).json()
for history in index_response:
assert "state" in history

# Expect only specific keys
expected_keys = ["name"]
unexpected_keys = ["deleted", "state"]
data = dict(search=expected_name_contains, show_published=False, keys=",".join(expected_keys))
index_response = self._get("histories", data=data).json()
for history in index_response:
for key in expected_keys:
assert key in history
for key in unexpected_keys:
assert key not in history

def test_index_case_insensitive_contains_query(self):
# Create the histories with a different user to ensure the test
# is not conflicted with the current user's histories.
Expand Down

0 comments on commit e2e6ba4

Please sign in to comment.