Skip to content

Commit

Permalink
Adjust query allow for sorting by username
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Dec 23, 2023
1 parent 87a9b7f commit 2962b2e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 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 @@ -37,6 +37,7 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
search,
sort_by: sort_by as SortKeyLiteral,
sort_desc,
show_own: true,
show_published: false,
});
const totalMatches = parseInt(headers.get("total_matches") ?? "0");
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Grid/configs/historiesShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
search,
sort_by: sort_by as SortKeyLiteral,
sort_desc,
show_published: false,
show_own: false,
show_published: false,
show_shared: true,
});
const totalMatches = parseInt(headers.get("total_matches") ?? "0");
Expand Down
14 changes: 9 additions & 5 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def index_query(
message = "Requires user to log in."
raise RequestParameterInvalidException(message)

stmt = select(self.model_class).outerjoin(self.model_class.user)
stmt = select(self.model_class)

filters = []
if show_own or (not show_published and not is_admin):
if show_own or (not show_published and not show_shared and not is_admin):
filters = [self.model_class.user == user]
if show_published:
filters.append(self.model_class.published == true())
Expand Down Expand Up @@ -173,8 +173,8 @@ def p_tag_filter(term_text: str, quoted: bool):
if q == "importable":
stmt = stmt.where(self.model_class.importable == true())
elif q == "shared_with_me":
if not show_published:
message = "Can only use tag is:shared_with_me if show_published parameter also true."
if not show_shared:
message = "Can only use tag is:shared_with_me if show_shared parameter also true."
raise RequestParameterInvalidException(message)
stmt = stmt.where(self.user_share_model.user == user)
elif isinstance(term, RawTextTerm):
Expand All @@ -201,7 +201,11 @@ def p_tag_filter(term_text: str, quoted: bool):
total_matches = get_count(trans.sa_session, stmt)
else:
total_matches = None
sort_column = getattr(model.History, payload.sort_by)
if payload.sort_by == "username":
stmt = stmt.outerjoin(model.User)
sort_column = model.User.username
else:
sort_column = getattr(model.History, payload.sort_by)
if payload.sort_desc:
sort_column = sort_column.desc()
stmt = stmt.order_by(sort_column)
Expand Down

0 comments on commit 2962b2e

Please sign in to comment.