pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.92k stars 857 forks source link

Add ability to search users by email #1842

Closed agileminor closed 3 months ago

agileminor commented 3 months ago

Problem trying to solve

Using search_user uses rest/api/2/user/search?username=XXX, which throws the following error for me from Jira Cloud - "The query parameter 'username' is not supported in GDPR strict mode."

Possible solution(s)

Looks like they want people to use accountId instead, so it would be good to get that added to the supported search commands. Also, email would be useful - /rest/api/3/user/search?query=

Alternatives

No response

Additional Context

This is discussed here https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-user-privacy-api-migration-guide/

supermitch commented 3 months ago

You can do that by using the query argument via:

jira.search_users(query="first.last@company.com")

Sample using requests:

        response = requests.get(
            url="https://company.atlassian.net/rest/api/2/user/search/",
            params={"query": "first.last@domain.com"},
            headers={"Authorization": "Basic  <basic auth secret>"},
        )

Sample using curl:

curl "https://company.atlassian.net/rest/api/2/user/search/?query=first.last%40company.com"

returns the following:

[
  {
    "self": "https://company.atlassian.net/rest/api/2/user?accountId=5f2...",
    "accountId": "5f2...",
    "accountType": "atlassian",
    "emailAddress": "first.last@company.com",
    "avatarUrls": {
      "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5f2...",
    },
    "displayName": "First Last",
    "active": true,
    "timeZone": "blah",
    "locale": "en_US"
  }
]
agileminor commented 3 months ago

True - but the current code doesn't use query=...., it uses username=..., which has the issue I mentioned above. The workaround I'm using is to bypass search_user and directly call the rest API with query=.

supermitch commented 3 months ago

I see. I posted an edit to how I use this library (you replied too fast!) See above. You can use the query arg with the search_users function to search by email.

I found this comment in the code: https://github.com/pycontribs/jira/blob/eb0ec90e08ae24823e266b0128b852022d212982/jira/client.py#L3955-L3956

agileminor commented 3 months ago

Thanks - much appreciated.

supermitch commented 3 months ago

@agileminor glad that helped. I also just checked, and this seems to match the v3 API behaviour: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-user-search/#api-rest-api-3-user-search-get