Skip to content

Commit

Permalink
Merge branch 'ChowRex-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gonchik committed May 24, 2024
2 parents 33392bb + 2fda01a commit 98609db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
21 changes: 21 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,23 @@ 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
Retrieves full details of all group memberships, with users and nested groups.
This resource is optimised for streaming XML responses, and does not support JSON responses.
: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
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ python-magic
# On October 4, 2022 importlib-metadata released importlib-metadata 5.0.0 and in version 5.0.0
# They have Deprecated EntryPoints and that's why you are facing this error.
importlib-metadata<=4.13.0
# Add this package to search string in json
jmespath

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ six
oauthlib
requests_oauthlib
requests-kerberos==0.14.0
# Add this package to search string in json
jmespath
beautifulsoup4
lxml

0 comments on commit 98609db

Please sign in to comment.