Skip to content

Add a new property of Crowd class #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024
Merged
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
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 @@
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 = {}

Check warning on line 280 in atlassian/crowd.py

View check run for this annotation

Codecov / codecov/patch

atlassian/crowd.py#L276-L280

Added lines #L276 - L280 were not covered by tests
for membership in soup.find_all("membership"):
group = membership["group"]

Check warning on line 282 in atlassian/crowd.py

View check run for this annotation

Codecov / codecov/patch

atlassian/crowd.py#L282

Added line #L282 was not covered by tests
users = [user["name"] for user in membership.find_all("user")]
memberships[group] = users
return memberships

Check warning on line 285 in atlassian/crowd.py

View check run for this annotation

Codecov / codecov/patch

atlassian/crowd.py#L284-L285

Added lines #L284 - L285 were not covered by tests
Loading