Skip to content

Commit b5f2f63

Browse files
authored
[JIRA] User search required parameters additions (#727)
* Jira: Support required user search params. * Jira: Remove username parameter from user search. * Update documentation. * Jira: Add username as an optional param in user_find_by_user_string and check if its being ran on cloud or not before enforcing required params. * Jira: Only add query and property key to params if we're on cloud. * Fix logic on cloud vs. non cloud parameters. * More logical fixes.
1 parent a9981bc commit b5f2f63

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

atlassian/jira.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,15 +1432,28 @@ def invalidate_websudo(self):
14321432

14331433
def user_find_by_user_string(
14341434
self,
1435-
username,
1435+
username=None,
1436+
query=None,
1437+
account_id=None,
1438+
property_key=None,
14361439
start=0,
14371440
limit=50,
14381441
include_inactive_users=False,
14391442
include_active_users=True,
14401443
):
14411444
"""
1442-
Fuzzy search using username and display name
1443-
:param username: Use '.' to find all users
1445+
Fuzzy search using display name, emailAddress or property, or an exact search for accountId or username
1446+
1447+
On Jira Cloud, you can use only one of query or account_id params. You may not specify username.
1448+
On Jira Server, you must specify a username. You may not use query, account_id or property_key.
1449+
1450+
:param username: OPTIONAL: Required for Jira Server, cannot be used on Jira Cloud.
1451+
Use '.' to find all users.
1452+
:param query: OPTIONAL: String matched against "displayName" and "emailAddress" user attributes
1453+
:param account_id: OPTIONAL: String matched exactly against a user "accountId".
1454+
Required unless "query" or "property" parameters are specified.
1455+
:param property_key: OPTIONAL: String used to search properties by key. Required unless
1456+
"account_id" or "query" is specified.
14441457
:param start: OPTIONAL: The start point of the collection to return. Default: 0.
14451458
:param limit: OPTIONAL: The limit of the number of users to return, this may be restricted by
14461459
fixed system limits. Default by built-in method: 50
@@ -1450,12 +1463,33 @@ def user_find_by_user_string(
14501463
"""
14511464
url = "rest/api/2/user/search"
14521465
params = {
1453-
"username": username,
14541466
"includeActive": include_active_users,
14551467
"includeInactive": include_inactive_users,
14561468
"startAt": start,
14571469
"maxResults": limit,
14581470
}
1471+
1472+
if self.cloud:
1473+
if username:
1474+
return "Jira Cloud no longer supports a username parameter, use account_id, query or property_key"
1475+
elif account_id and query:
1476+
return "You cannot specify both the query and account_id parameters"
1477+
elif not any([account_id, query, property_key]):
1478+
return "You must specify at least one parameter: query or account_id or property_key"
1479+
elif account_id:
1480+
params["accountId"] = account_id
1481+
1482+
if query:
1483+
params["query"] = query
1484+
if property_key:
1485+
params["property"] = property_key
1486+
elif not username:
1487+
return "Username parameter is required for user search on Jira Server"
1488+
elif any([account_id, query, property_key]):
1489+
return "Jira Server does not support account_id, query or property_key parameters"
1490+
else:
1491+
params["username"] = username
1492+
14591493
return self.get(url, params=params)
14601494

14611495
def is_user_in_application(self, username, application_key):

docs/jira.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Manage users
3737
.. code-block:: python
3838
3939
# Get user
40-
jira.user(username)
40+
jira.user(account_id)
4141
4242
# Remove user
4343
jira.user_remove(username)
@@ -48,8 +48,8 @@ Manage users
4848
# Get web sudo cookies using normal http request
4949
jira.user_get_websudo()
5050
51-
# Fuzzy search using username and display name
52-
jira.user_find_by_user_string(username, start=0, limit=50, include_inactive_users=False)
51+
# Fuzzy search using emailAddress or displayName
52+
jira.user_find_by_user_string(query, start=0, limit=50, include_inactive_users=False)
5353
5454
Manage groups
5555
-------------

0 commit comments

Comments
 (0)