Skip to content

Commit 1bb6107

Browse files
authored
Add a new property of Crowd class (#1402)
* Add a new property of `Crowd` class - Fix `lxml` CVE, using `bs4` to replace. - Add a property for Crowd class to retrieves full details of all group memberships. * Fix `black` test Using `double-quotes` to replace `single-quotes`.
1 parent b81fff5 commit 1bb6107

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

atlassian/crowd.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from jmespath import search
5+
from bs4 import BeautifulSoup
56

67
from .rest_client import AtlassianRestAPI
78

@@ -264,3 +265,21 @@ def update_plugin_license(self, plugin_key, raw_license):
264265
url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
265266
data = {"rawLicense": raw_license}
266267
return self.put(url, data=data, headers=app_headers)
268+
269+
@property
270+
def memberships(self):
271+
"""
272+
Retrieves full details of all group memberships, with users and nested groups.
273+
See: https://docs.atlassian.com/atlassian-crowd/5.3.1/REST/#usermanagement/1/group-getAllMemberships
274+
:return: All membership mapping dict
275+
"""
276+
path = self._crowd_api_url("usermanagement", "group/membership")
277+
headers = {"Accept": "application/xml"}
278+
response = self.get(path, headers=headers)
279+
soup = BeautifulSoup(response, "xml")
280+
memberships = {}
281+
for membership in soup.find_all("membership"):
282+
group = membership["group"]
283+
users = [user["name"] for user in membership.find_all("user")]
284+
memberships[group] = users
285+
return memberships

0 commit comments

Comments
 (0)