Skip to content

Commit

Permalink
Merge pull request #17856 from davelopez/24.0_fix_archived_histories_…
Browse files Browse the repository at this point in the history
…mixing_with_active

[24.0] Fix archived histories mixing with active in histories list
  • Loading branch information
jdavcs authored Apr 2, 2024
2 parents 7284e3e + b828a16 commit 098ec92
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15519,6 +15519,7 @@ export interface operations {
parameters?: {
/** @description The maximum number of items to return. */
/** @description Starts at the beginning skip the first ( offset - 1 ) items and begin returning at the Nth item */
/** @description Whether to include archived histories. */
/** @description Sort index by this specified attribute */
/** @description Sort in descending order? */
/**
Expand Down Expand Up @@ -15570,6 +15571,7 @@ export interface operations {
show_own?: boolean;
show_published?: boolean;
show_shared?: boolean;
show_archived?: boolean | null;
sort_by?: "create_time" | "name" | "update_time" | "username";
sort_desc?: boolean;
search?: string | null;
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Grid/configs/historiesPublished.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
show_own: false,
show_published: true,
show_shared: false,
show_archived: true,
});
const totalMatches = parseInt(headers.get("total_matches") ?? "0");
return [data, totalMatches];
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Grid/configs/historiesShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
show_own: false,
show_published: false,
show_shared: true,
show_archived: true,
});
const totalMatches = parseInt(headers.get("total_matches") ?? "0");
return [data, totalMatches];
Expand Down
7 changes: 7 additions & 0 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def index_query(
show_published = payload.show_published
show_purged = False
show_shared = payload.show_shared
show_archived = payload.show_archived
is_admin = trans.user_is_admin
user = trans.user

Expand Down Expand Up @@ -207,6 +208,12 @@ def p_tag_filter(term_text: str, quoted: bool):
self.model_class.deleted == (true() if show_deleted else false())
)

# By default, return only non-archived histories when we are showing the current user's histories
# if listing other users' histories, we don't filter out archived histories as they may be
# public or shared with the current user
if show_own and not show_archived:
stmt = stmt.where(self.model_class.archived == false())

stmt = stmt.distinct()

if include_total_count:
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/schema/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HistoryIndexQueryPayload(Model):
show_own: Optional[bool] = None
show_published: Optional[bool] = None
show_shared: Optional[bool] = None
show_archived: Optional[bool] = None
sort_by: HistorySortByEnum = Field("update_time", title="Sort By", description="Sort by this attribute.")
sort_desc: Optional[bool] = Field(default=True, title="Sort descending", description="Sort in descending order.")
search: Optional[str] = Field(default=None, title="Filter text", description="Freetext to search.")
Expand Down
8 changes: 8 additions & 0 deletions lib/galaxy/webapps/galaxy/api/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
default=False, title="Include histories shared with authenticated user.", description=""
)

ShowArchivedQueryParam: Optional[bool] = Query(
default=None,
title="Show Archived",
description="Whether to include archived histories.",
)

SortByQueryParam: HistorySortByEnum = Query(
default="update_time",
title="Sort attribute",
Expand Down Expand Up @@ -174,6 +180,7 @@ def index(
show_own: bool = ShowOwnQueryParam,
show_published: bool = ShowPublishedQueryParam,
show_shared: bool = ShowSharedQueryParam,
show_archived: Optional[bool] = ShowArchivedQueryParam,
sort_by: HistorySortByEnum = SortByQueryParam,
sort_desc: bool = SortDescQueryParam,
search: Optional[str] = SearchQueryParam,
Expand All @@ -196,6 +203,7 @@ def index(
show_own=show_own,
show_published=show_published,
show_shared=show_shared,
show_archived=show_archived,
sort_by=sort_by,
sort_desc=sort_desc,
limit=limit,
Expand Down
56 changes: 56 additions & 0 deletions lib/galaxy_test/api/test_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,62 @@ def test_index_advanced_filter(self):
index_response = self._get("histories", data=data).json()
assert len(index_response) == 1

archived_history_id = self._create_history(f"Archived history_{uuid4()}")["id"]
name_contains = "history"
data = dict(search=name_contains, show_published=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 4

# Archived histories should not be included by default
self.dataset_populator.archive_history(archived_history_id)
data = dict(search=name_contains, show_published=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 3

self._create_history_then_publish_and_archive_it(f"Public Archived history_{uuid4()}")
data = dict(search=name_contains, show_published=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 3

name_contains = "Archived"
data = dict(search=name_contains, show_published=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 0

# Archived public histories should be included when filtering by show_published and show_archived
data = dict(search="is:published", show_archived=True)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 2

# Searching all published histories will NOT include the archived if show_archived is not set
data = dict(search="is:published")
index_response = self._get("histories", data=data).json()
assert len(index_response) == 1

# Searching all published histories will include our own archived when show_own is false
# as long as they are published
data = dict(search="is:published", show_own=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 2

# Publish a history and archive it by a different user
with self._different_user(f"other_user_{uuid4()}@bx.psu.edu"):
self._create_history_then_publish_and_archive_it(f"Public Archived history_{uuid4()}")

# Searching all published histories will include archived from other users and our own
# as long as they are published
data = dict(search="is:published", show_own=False)
index_response = self._get("histories", data=data).json()
assert len(index_response) == 3

def _create_history_then_publish_and_archive_it(self, name):
history_id = self._create_history(name)["id"]
response = self._update(history_id, {"published": True})
self._assert_status_code_is_ok(response)
response = self.dataset_populator.archive_history(history_id)
self._assert_status_code_is_ok(response)
return history_id

def test_delete(self):
# Setup a history and ensure it is in the index
history_id = self._create_history("TestHistoryForDelete")["id"]
Expand Down

0 comments on commit 098ec92

Please sign in to comment.