server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

[Type 3] [Search for users by email]

Open jorwoods opened this issue 11 months ago • 3 comments

Summary

The user filters should support filtering based on email eq and email in.

****Type 3: new functionality**** Requests for totally new functionality will generally be passed to the relevant dev team, but we probably can't give any useful estimate of how or when it might be implemented. If it is a feature that is 'about' the API or programmable access, here might be the best place to suggest it, but generally feature requests will be more visible in the [Tableau Community Ideas](https://community.tableau.com/s/ideas) forum and should go there instead.

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.

jorwoods avatar Feb 03 '25 15:02 jorwoods

It would be great if case insensitivity were available with this as well.

jorwoods avatar Feb 03 '25 15:02 jorwoods

Examples:

  1. 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
  1. 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))

jorwoods avatar Feb 03 '25 16:02 jorwoods

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.

jorwoods avatar May 14 '25 03:05 jorwoods