@@ -20,29 +20,60 @@ def getUserQuery():
2020 "LEFT JOIN Sponsors as s ON u.sponsor_id = s.sponsor_id "
2121
2222
23- def getUsers (status = None , is_virtual = None ) -> list :
23+ def getUsers (applicationStatusFilterList : List [str ] = None , is_virtual = None , firstName = None , lastName = None , userId = None ,
24+ email = None , applicationId = None ) -> list :
2425 """
2526 Get a filtered list of all users in json/dictionary format
26- :param status: string matching user application status
27+ :param applicationId:
28+ :param email:
29+ :param userId:
30+ :param lastName:
31+ :param firstName:
32+ :param applicationStatusFilterList: list of statuses to match
2733 :param is_virtual: boolean for if you want all virtual/in person users
28- :return: list of dictionaries with user information
34+ :return: list of dictionaries with user information, None if error
2935 """
30-
3136 sql = getUserQuery ()
37+ firstWhereClause = True
3238 args = ()
33- if status is not None :
34- sql += "WHERE app.status = %s"
35- args = args + (status ,)
36- if is_virtual is not None :
37- sql += "AND WHERE app.is_virtual = %s"
38- args = args + (is_virtual ,)
39- elif is_virtual is not None :
40- sql += "WHERE app.is_virtual = %s"
39+
40+ if applicationStatusFilterList is not None :
41+ sql += f" WHERE app.status in ({ ',' .join (['%s' ] * len (applicationStatusFilterList ))} ) "
42+ args = args + (tuple (applicationStatusFilterList ),)
43+ if is_virtual is not None :
44+ sql += getOptionalAnd (firstWhereClause ) + " WHERE app.is_virtual = %s "
4145 args = args + (is_virtual ,)
46+ if firstName is not None :
47+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.first_name = %s "
48+ args = args + (firstName ,)
49+ if lastName is not None :
50+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.last_name = %s "
51+ args = args + (lastName ,)
52+ if userId is not None :
53+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.user_id = %s "
54+ args = args + (userId ,)
55+ if email is not None :
56+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.email = %s "
57+ args = args + (email ,)
58+ if applicationId is not None :
59+ sql += getOptionalAnd (firstWhereClause ) + " WHERE app.application_id = %s "
60+ args = args + (applicationId ,)
4261
4362 return exec_get_all (sql , args )
4463
4564
65+ def getOptionalAnd (isFirstWhereClause ) -> str :
66+ """
67+ Helper function, returns "AND " if clause isn't the first and empty string if it is
68+ :param isFirstWhereClause:
69+ :return:
70+ """
71+ if isFirstWhereClause :
72+ return ""
73+ else :
74+ return " AND "
75+
76+
4677def getUserByAuthID (auth_id ) -> dict :
4778 """
4879 wrapper for getting user using auth0 id
@@ -94,7 +125,7 @@ def getUserById(auth_id=None, user_id=None) -> dict:
94125 if auth_id is not None :
95126 sql += "WHERE u.auth0_id = %s"
96127 args = args + (auth_id ,)
97- if user_id is not None :
128+ elif user_id is not None :
98129 sql += "WHERE u.user_id = %s"
99130 args = args + (user_id ,)
100131
@@ -121,4 +152,3 @@ def getUserEmailsWithFilter(applicationStatusFilterList: List[str]):
121152 if len (u ['email' ]) > 1 :
122153 emailList .append (u ['email' ])
123154 return emailList
124-
0 commit comments