Merge "Add listing of groups for a user"

This commit is contained in:
Zuul 2025-04-08 12:29:59 +00:00 committed by Gerrit Code Review
commit bbe9c96d99
5 changed files with 44 additions and 0 deletions

View File

@ -84,6 +84,7 @@ User Operations
.. autoclass:: openstack.identity.v3._proxy.Proxy
:noindex:
:members: create_user, update_user, delete_user, get_user, find_user, users,
user_groups
Trust Operations
^^^^^^^^^^^^^^^^

View File

@ -10,3 +10,12 @@ The ``Group`` class inherits from :class:`~openstack.resource.Resource`.
.. autoclass:: openstack.identity.v3.group.Group
:members:
The UserGroup Class
-------------------
The ``UserGroup`` class inherits from
:class:`~openstack.identity.v3.group.Group`
.. autoclass:: openstack.identity.v3.group.UserGroup
:members:

View File

@ -939,6 +939,18 @@ class Proxy(proxy.Proxy):
"""
return self._get(_user.User, user)
def user_groups(self, user):
"""List groups a user is in
:param user: Either the ID of a user or a
:class:`~openstack.identity.v3.user.User` instance
:return: List of :class:`~openstack.identity.v3.group.group`
"""
user_id = self._get_resource(_user.User, user).id
groups = self._list(_group.UserGroup, user_id=user_id)
return groups
def users(self, **query):
"""Retrieve a generator of users

View File

@ -74,3 +74,17 @@ class Group(resource.Resource):
if resp.status_code == 204:
return True
return False
class UserGroup(Group):
base_path = '/users/%(user_id)%/groups'
#: The ID for the user from the URI of the resource
user_id = resource.URI('user_id')
# capabilities
allow_create = False
allow_fetch = False
allow_commit = False
allow_delete = False
allow_list = True

View File

@ -385,6 +385,14 @@ class TestIdentityProxyUser(TestIdentityProxyBase):
def test_user_update(self):
self.verify_update(self.proxy.update_user, user.User)
def test_user_groups(self):
self.verify_list(
self.proxy.user_groups,
group.UserGroup,
method_kwargs={"user": 'user'},
expected_kwargs={"user_id": "user"},
)
class TestIdentityProxyTrust(TestIdentityProxyBase):
def test_trust_create_attrs(self):