Skip to content
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

Add Crowd a new attr #1400

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
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 lxml import etree

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, 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
13 changes: 13 additions & 0 deletions docs/crowd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ Manage groups
# Get group's members
crowd.group_members(group, kind='direct', max_results=99999)

Get memberships
----------------

.. code-block:: python

# Retrieves full details of all group memberships.
# Return data structure:
# {
# GroupName1<str>: [ Member1<str>, Member2<str>, ... ],
# GroupName2<str>: [ MemberA<str>, MemberB<str>, ... ],
# ...
# }
crowd.memberships
Loading