Skip to content

Commit 7232627

Browse files
committed
Move get_user_by_username into repositories
1 parent 0eb5f71 commit 7232627

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

lib/galaxy/managers/users.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
and_,
2121
exc,
2222
func,
23-
select,
2423
true,
2524
)
2625
from sqlalchemy.orm.exc import NoResultFound
@@ -838,15 +837,3 @@ def _add_parsers(self):
838837
)
839838

840839
self.fn_filter_parsers.update({})
841-
842-
843-
def get_user_by_username(session, user_class, username):
844-
"""
845-
Get a user from the database by username.
846-
(We pass the session and the user_class to accommodate usage from the tool_shed app.)
847-
"""
848-
try:
849-
stmt = select(user_class).filter(user_class.username == username)
850-
return session.execute(stmt).scalar_one()
851-
except Exception:
852-
return None

lib/galaxy/model/repositories/user.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import cast
22

3+
from sqlalchemy import select
4+
35
from galaxy.model import User
46
from galaxy.model.repositories import (
57
BaseRepository,
@@ -13,3 +15,12 @@ def __init__(self, session: SessionType):
1315

1416
def get(self, primary_key: int) -> User:
1517
return cast(User, super().get(primary_key))
18+
19+
20+
def get_user_by_username(session: SessionType, user_class, username: str):
21+
"""Get a user from the database by username."""
22+
# This may be called from the tool_shed app, which has a different
23+
# definition of the User mapped class. Therefore, we must pass the User
24+
# class as an argument instead of importing from galaxy.model.
25+
stmt = select(user_class).filter(user_class.username == username)
26+
return session.execute(stmt).scalar_one() # type:ignore[union-attr]

lib/tool_shed/webapp/controllers/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
util,
2525
web,
2626
)
27-
from galaxy.managers.users import get_user_by_username
2827
from galaxy.model.base import transaction
28+
from galaxy.model.repositories.user import get_user_by_username
2929
from galaxy.tool_shed.util import dependency_display
3030
from galaxy.tools.repositories import ValidationContext
3131
from galaxy.web.form_builder import (

0 commit comments

Comments
 (0)