Skip to content

Commit

Permalink
Add more Crowd functions
Browse files Browse the repository at this point in the history
- Using universal request to get user's group, controled by `kind` param
- Using universal request to get group's member, controled by `kind` param
- Add a new function to determine whether the user is a member of a group
  • Loading branch information
ChowRex authored Dec 8, 2023
1 parent fe5b158 commit f3acc56
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions atlassian/crowd.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,44 @@ def user_delete(self, username):

return self.delete(self._crowd_api_url("usermanagement", "user"), params=params)

def user_groups(self, username):
def user_groups(self, username, kind='direct'):
"""
Get user's all group info
:param username: str - username
:param kind: str - group type
:return: The specify user's group info
"""
path = self._crowd_api_url("usermanagement", "user/group/direct")
path = self._crowd_api_url("usermanagement",
"user/group/{kind}".format(kind=kind))
response = self.get(path, params={'username': username})
return search('groups[*].name', response)

def group_members(self, group, kind='direct'):
"""
Get group's all direct members
:param group: str - group name
:param kind: str - group type
:return: The specify group's direct members info
"""
path = self._crowd_api_url("usermanagement",
"group/user/{kind}".format(kind=kind))
response = self.get(path, params={'groupname': group})
return search('users[*].name', response)

def is_user_in_group(self, username, group, kind='direct'):
"""
Check if the user is a member of the group
:param username: str - username
:param group: str - group name
:param kind: str - group type
:return: bool - Return `True` or `False`
"""
path = self._crowd_api_url("usermanagement",
"group/user/{kind}".format(kind=kind))
params = {'username': username, 'groupname': group}
response = self.get(path, params=params, advanced_mode=True)
return response.status_code == 200

def group_add_user(self, username, groupname):
"""
Add user to group
Expand All @@ -157,15 +185,6 @@ def group_add_user(self, username, groupname):
json=data,
)

def group_nested_members(self, group):
"""
Get nested members of group
:param group:
:return:
"""
params = {"groupname": group}
return self.get(self._crowd_api_url("group", "nested"), params=params)

def health_check(self):
"""
Get health status
Expand Down

0 comments on commit f3acc56

Please sign in to comment.