Skip to content

Commit 34e5d8d

Browse files
MyMaloksgonchik
authored andcommitted
Add 2 application related functions for Jira (#387)
* Fix format error in log 400 code error * Add application role function - add_user_to_application - is_user_in_application
1 parent 3f5fedc commit 34e5d8d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

atlassian/jira.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,36 @@ def user_find_by_user_string(self, username, start=0, limit=50, include_inactive
306306
'maxResults': limit
307307
}
308308
return self.get(url, params=params)
309+
310+
def is_user_in_application(self, username, applicationKey):
311+
"""
312+
Utility function to test whether a user has an application role
313+
:param username: The username of the user to test.
314+
:param applicationKey: The application key of the application
315+
:return: True if the user has the application, else False
316+
"""
317+
user = self.user(username, 'applicationRoles') # Get applications roles of the user
318+
if 'self' in user:
319+
for applicationRole in user.get('applicationRoles').get('items'):
320+
if applicationRole.get('key')==applicationKey:
321+
return True
322+
323+
return False
309324

325+
def add_user_to_application(self, username, applicationKey):
326+
"""
327+
Add a user to an application
328+
:param username: The username of the user to add.
329+
:param applicationKey: The application key of the application
330+
:return: True if the user was added to the application, else False
331+
:see: https://docs.atlassian.com/software/jira/docs/api/REST/7.5.3/#api/2/user-addUserToApplication
332+
"""
333+
params = {
334+
'username': username,
335+
'applicationKey': applicationKey
336+
}
337+
return self.post('rest/api/2/user/application', params=params)==None
338+
310339
def projects(self, included_archived=None):
311340
"""Returns all projects which are visible for the currently logged in user.
312341
If no user is logged in, it returns the list of projects that are visible when using anonymous access.

0 commit comments

Comments
 (0)