Skip to content

Commit

Permalink
Move get_user_by_username function to managers.users
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Aug 8, 2023
1 parent 3072dfe commit 705ec09
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
11 changes: 11 additions & 0 deletions lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
and_,
exc,
func,
select,
true,
)
from sqlalchemy.orm.exc import NoResultFound
Expand Down Expand Up @@ -837,3 +838,13 @@ def _add_parsers(self):
)

self.fn_filter_parsers.update({})


def get_user_by_username(session, username):
"""Get a user from the database by username."""
try:
stmt = select(model.User).filter(model.User.username == username)
user = session.execute(stmt).scalar_one()
return user
except Exception:
return None
11 changes: 0 additions & 11 deletions lib/galaxy/util/tool_shed/common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,6 @@ def get_tool_shed_repository_url(app: HasToolShedRegistry, tool_shed: str, owner
return tool_shed_url


def get_user_by_username(app, username):
"""Get a user from the database by username."""
sa_session = app.model.session
try:
user = sa_session.query(app.model.User).filter(app.model.User.table.c.username == username).one()
return user
except Exception:
return None


def handle_galaxy_url(trans, **kwd):
galaxy_url = kwd.get("galaxy_url", None)
if galaxy_url:
Expand Down Expand Up @@ -303,7 +293,6 @@ def remove_protocol_from_tool_shed_url(tool_shed_url: str) -> str:
"get_tool_shed_repository_ids",
"get_tool_shed_url_from_tool_shed_registry",
"get_tool_shed_repository_url",
"get_user_by_username",
"handle_galaxy_url",
"handle_tool_shed_url_protocol",
"parse_repository_dependency_tuple",
Expand Down
2 changes: 0 additions & 2 deletions lib/tool_shed/util/common_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
get_tool_shed_repository_ids,
get_tool_shed_repository_url,
get_tool_shed_url_from_tool_shed_registry,
get_user_by_username,
handle_galaxy_url,
handle_tool_shed_url_protocol,
parse_repository_dependency_tuple,
Expand All @@ -30,7 +29,6 @@
"get_tool_shed_repository_ids",
"get_tool_shed_url_from_tool_shed_registry",
"get_tool_shed_repository_url",
"get_user_by_username",
"handle_galaxy_url",
"handle_tool_shed_url_protocol",
"parse_repository_dependency_tuple",
Expand Down
5 changes: 3 additions & 2 deletions lib/tool_shed/webapp/controllers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
util,
web,
)
from galaxy.managers.users import get_user_by_username
from galaxy.model.base import transaction
from galaxy.tool_shed.util import dependency_display
from galaxy.tools.repositories import ValidationContext
Expand Down Expand Up @@ -2292,7 +2293,7 @@ def set_malicious(self, trans, id, ctx_str, **kwd):
def sharable_owner(self, trans, owner):
"""Support for sharable URL for each repository owner's tools, e.g. http://example.org/view/owner."""
try:
user = common_util.get_user_by_username(trans, owner)
user = get_user_by_username(trans.sa_session, owner)
except Exception:
user = None
if user:
Expand Down Expand Up @@ -2320,7 +2321,7 @@ def sharable_repository(self, trans, owner, name):
else:
# If the owner is valid, then show all of their repositories.
try:
user = common_util.get_user_by_username(trans, owner)
user = get_user_by_username(trans.sa_session, owner)
except Exception:
user = None
if user:
Expand Down

0 comments on commit 705ec09

Please sign in to comment.