Skip to content

Commit

Permalink
Add Crowd a new attr
Browse files Browse the repository at this point in the history
Add a new property of class `Crowd`, can retrieves full details of all group memberships, see: https://docs.atlassian.com/atlassian-crowd/5.3.1/REST/#usermanagement/1/group-getAllMemberships
  • Loading branch information
ChowRex authored May 24, 2024
1 parent 33392bb commit e25fc06
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions atlassian/crowd.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,21 @@ def update_plugin_license(self, plugin_key, raw_license):
url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
data = {"rawLicense": raw_license}
return self.put(url, data=data, headers=app_headers)

@property
def memberships(self):
"""
Retrieves full details of all group memberships, with users and nested groups.
See: https://docs.atlassian.com/atlassian-crowd/5.3.1/REST/#usermanagement/1/group-getAllMemberships
:return: All membership mapping dict
"""
path = self._crowd_api_url("usermanagement", "group/membership")
headers = {'Accept': 'application/xml'}
response = self.get(path, headers=headers, advanced_mode=True)
root = etree.fromstring(response.content)
memberships = {}
for member in root.xpath('//membership'):
group = member.get('group')
users = [user.get('name') for user in member.xpath('./users/user')]
memberships[group] = users
return memberships

0 comments on commit e25fc06

Please sign in to comment.