Skip to content

Commit 98609db

Browse files
committed
Merge branch 'ChowRex-master'
2 parents 33392bb + 2fda01a commit 98609db

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

atlassian/crowd.py

Lines changed: 21 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 lxml import etree
56

67
from .rest_client import AtlassianRestAPI
78

@@ -264,3 +265,23 @@ 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+
Retrieves full details of all group memberships, with users and nested groups.
275+
This resource is optimised for streaming XML responses, and does not support JSON responses.
276+
:return: All membership mapping dict
277+
"""
278+
path = self._crowd_api_url("usermanagement", "group/membership")
279+
headers = {"Accept": "application/xml"}
280+
response = self.get(path, headers=headers, advanced_mode=True)
281+
root = etree.fromstring(response.content)
282+
memberships = {}
283+
for member in root.xpath("//membership"):
284+
group = member.get("group")
285+
users = [user.get("name") for user in member.xpath("./users/user")]
286+
memberships[group] = users
287+
return memberships

docs/crowd.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ Manage groups
3838
# Get group's members
3939
crowd.group_members(group, kind='direct', max_results=99999)
4040
41+
Get memberships
42+
----------------
43+
44+
.. code-block:: python
45+
46+
# Retrieves full details of all group memberships.
47+
# Return data structure:
48+
# {
49+
# GroupName1<str>: [ Member1<str>, Member2<str>, ... ],
50+
# GroupName2<str>: [ MemberA<str>, MemberB<str>, ... ],
51+
# ...
52+
# }
53+
crowd.memberships

requirements-dev.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ python-magic
1414
# On October 4, 2022 importlib-metadata released importlib-metadata 5.0.0 and in version 5.0.0
1515
# They have Deprecated EntryPoints and that's why you are facing this error.
1616
importlib-metadata<=4.13.0
17-
# Add this package to search string in json
18-
jmespath
17+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ six
44
oauthlib
55
requests_oauthlib
66
requests-kerberos==0.14.0
7+
# Add this package to search string in json
78
jmespath
89
beautifulsoup4
910
lxml

0 commit comments

Comments
 (0)