Skip to content

Commit

Permalink
Add a new property of Crowd class (#1402)
Browse files Browse the repository at this point in the history
* 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`.
  • Loading branch information
ChowRex authored May 27, 2024
1 parent b81fff5 commit 1bb6107
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions atlassian/crowd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from jmespath import search
from bs4 import BeautifulSoup

from .rest_client import AtlassianRestAPI

Expand Down Expand Up @@ -264,3 +265,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)
soup = BeautifulSoup(response, "xml")
memberships = {}
for membership in soup.find_all("membership"):
group = membership["group"]
users = [user["name"] for user in membership.find_all("user")]
memberships[group] = users
return memberships

0 comments on commit 1bb6107

Please sign in to comment.