Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,36 @@ def user_find_by_user_string(self, username, start=0, limit=50, include_inactive
'maxResults': limit
}
return self.get(url, params=params)

def is_user_in_application(self, username, applicationKey):
"""
Utility function to test whether a user has an application role
:param username: The username of the user to test.
:param applicationKey: The application key of the application
:return: True if the user has the application, else False
"""
user = self.user(username, 'applicationRoles') # Get applications roles of the user
if 'self' in user:
for applicationRole in user.get('applicationRoles').get('items'):
if applicationRole.get('key')==applicationKey:
return True

return False

def add_user_to_application(self, username, applicationKey):
"""
Add a user to an application
:param username: The username of the user to add.
:param applicationKey: The application key of the application
:return: True if the user was added to the application, else False
:see: https://docs.atlassian.com/software/jira/docs/api/REST/7.5.3/#api/2/user-addUserToApplication
"""
params = {
'username': username,
'applicationKey': applicationKey
}
return self.post('rest/api/2/user/application', params=params)==None

def projects(self, included_archived=None):
"""Returns all projects which are visible for the currently logged in user.
If no user is logged in, it returns the list of projects that are visible when using anonymous access.
Expand Down
2 changes: 1 addition & 1 deletion atlassian/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def request(self, method='GET', path='/', data=None, flags=None, params=None, he
elif response.status_code == 204:
log.debug('Received: {0}\n "No Content" response'.format(response.status_code))
elif response.status_code == 400:
log.error('Received: {0}\n Bad request \n'.format(response.status_code, response_content))
log.error('Received: {0}\n Bad request \n {1}'.format(response.status_code, response_content))
elif response.status_code == 401:
log.error('Received: {0}\n "UNAUTHORIZED" response'.format(response.status_code))
elif response.status_code == 404:
Expand Down