Skip to content

Commit

Permalink
Refactor get user by email
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Oct 3, 2023
1 parent 01e2234 commit e4fd119
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ def get_user_by_identity(self, identity):
user = get_user_by_email(self.session(), identity, self.model_class)
if not user:
# Try a case-insensitive match on the email
stmt = select(self.model_class).where(func.lower(self.model_class.email) == identity.lower()).limit(1)
user = self.session().scalars(stmt).first()
user = self._get_user_by_email_case_insensitive(self.session(), identity)
else:
user = get_user_by_username(self.session(), identity, self.model_class)
return user
Expand Down Expand Up @@ -572,8 +571,7 @@ def send_reset_email(self, trans, payload, **kwd):
def get_reset_token(self, trans, email):
reset_user = get_user_by_email(trans.sa_session, email, self.app.model.User)
if not reset_user and email != email.lower():
stmt = select(self.app.model.User).where(func.lower(self.app.model.User.email) == email.lower()).limit(1)
reset_user = trans.sa_session.scalars(stmt).first()
reset_user = self._get_user_by_email_case_insensitive(trans.sa_session, email)
if reset_user:
prt = self.app.model.PasswordResetToken(reset_user)
trans.sa_session.add(prt)
Expand Down Expand Up @@ -650,6 +648,10 @@ def get_or_create_remote_user(self, remote_user_email):
# self.log_event( "Automatically created account '%s'", user.email )
return user

def _get_user_by_email_case_insensitive(self, session, email):
stmt = select(self.app.model.User).where(func.lower(self.app.model.User.email) == email.lower()).limit(1)
return session.scalars(stmt).first()


class UserSerializer(base.ModelSerializer, deletable.PurgableSerializerMixin):
model_manager_class = UserManager
Expand Down

0 comments on commit e4fd119

Please sign in to comment.