[Type 3] [Search for users by email]
Summary
The user filters should support filtering based on email eq and email in.
Description
A clear and concise description of what the feature request is. If you think that the value of this feature might not be obvious, include information like how often it is needed, amount of work saved, etc. If your feature request is related to a file or server in a specific state, describe the starting state when the feature can be used, and the end state after using it. If it involves modifying files, an example file may be helpful.
Currently the user filter supports searching based on name, luid, friendlyName, and a few other fields. As mentioned in #907:
Note: Filter expressions can’t contain ampersand (&) or comma (,) characters because these characters are used as field expression separators. This is true even if those characters are encoded.
so most servers I have interacted with, friendlyName does not work for searching due to names showing up as "Last, First." Searching by email will offer up a convenient way to find intended users.
It would be great if case insensitivity were available with this as well.
Examples:
- How it works in the current version of TSC. An API call to the server for every user on the site:
def get_users_by_email(server: TSC.Server, emails: list[str]) -> dict[str, TSC.UserItem]:
no_case_emails = [e.casefold() for e in emails]
users = {}
for user in server.users.all():
user = server.users.get_by_id(user.id)
no_case = (user.email or "").casefold()
if no_case in no_case_emails:
users[user.email] = user
return users
- How it would work if the filter was in place. Only one API call needed:
def future_get_users_by_email(server: TSC.Server, emails: list[str]) -> list[TSC.UserItem]:
return list(server.users.filter(email__ciin=emails))
With #1563, this can be simplified some and requires only one API call per page, instead of one for every user on the site:
def get_users_by_email(server: TSC.Server, emails: list[str]) -> dict[str, TSC.UserItem]:
no_case_emails = {e.casefold() for e in emails}
users = {}
for user in server.users.all().fields('email'): # You can now specify you want emails in the paginated request
# user = server.users.get_by_id(user.id) # This is the call that gets eliminated.
no_case = (user.email or "").casefold()
if no_case in no_case_emails:
users[user.email] = user
return users
Still more calls required than an ideal situation, but a vast improvement over the prior way.