File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """Utility functions for the Open edX AuthZ REST API."""
2+
3+ from django .contrib .auth import get_user_model
4+ from django .db .models import Q
5+
6+ User = get_user_model ()
7+
8+
9+ def get_user_by_username_or_email (username_or_email : str ) -> User :
10+ """
11+ Retrieve a user by their username or email address.
12+
13+ Args:
14+ username_or_email (str): The username or email address to search for.
15+
16+ Returns:
17+ User: The User object if found and not retired.
18+
19+ Raises:
20+ User.DoesNotExist: If no user matches the provided username or email,
21+ or if the user has an associated retirement request.
22+ """
23+ user = User .objects .get (Q (email = username_or_email ) | Q (username = username_or_email ))
24+ if hasattr (user , "userretirementrequest" ):
25+ raise User .DoesNotExist
26+ return user
You can’t perform that action at this time.
0 commit comments