Merge "Fix listing and removing roles from users."

This commit is contained in:
Zuul 2023-05-04 04:17:12 +00:00 committed by Gerrit Code Review
commit 2f405f1c39
3 changed files with 8 additions and 7 deletions

View File

@ -198,12 +198,14 @@ class BaseManager(HookableMixin):
else:
return self.resource_class(self, body)
def _delete(self, url):
def _delete(self, url, json=None):
"""Delete an object.
:param url: a partial URL, e.g., '/servers/my-server'
:param json: data that will be encoded as JSON and sent with the
DELETE request.
"""
return self.client.delete(url)
return self.client.delete(url, json=json)
class ManagerWithFind(BaseManager, metaclass=abc.ABCMeta):

View File

@ -171,10 +171,8 @@ class UserRoleList(command.Lister):
client = self.app.client_manager.admin_logic
user = utils.find_resource(client.users, parsed_args.user)
kwargs = {'user': user.id}
roles = [[role.id, role.name] for role
in client.user_roles.list(**kwargs)]
return ['id', 'name'], roles
return ['name'], [[role] for role in user.roles]
class ManageableRolesList(command.Lister):

View File

@ -87,6 +87,7 @@ class UserRoleManager(base.BaseManager):
def remove(self, user_id, role=None, roles=None):
"""Remove a role or roles from a user"""
if role:
params = {
'roles': [role]
@ -99,7 +100,7 @@ class UserRoleManager(base.BaseManager):
route = '/openstack/users/%s/roles'
url = route % (user_id)
try:
self._delete(url, json=params, response_key=None)
self._delete(url, json=params)
except exc.HTTPBadRequest as e:
print(e.message)
return False