Support creation of domain specific roles
Add support for the domain_id attribute in the role entity. Partially Implements: blueprint domain-specific-roles Change-Id: I06af7647e15aa742609b3fe1b9b222fbeaeb5735
This commit is contained in:
@@ -33,6 +33,32 @@ class RoleTests(utils.ClientTestCase, utils.CrudTests):
|
||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
def _new_domain_ref(self, **kwargs):
|
||||
kwargs.setdefault('enabled', True)
|
||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
def test_create_with_domain_id(self):
|
||||
ref = self.new_ref()
|
||||
ref['domain_id'] = uuid.uuid4().hex
|
||||
self.test_create(ref=ref)
|
||||
|
||||
def test_create_with_domain(self):
|
||||
ref = self.new_ref()
|
||||
domain_ref = self._new_domain_ref()
|
||||
domain_ref['id'] = uuid.uuid4().hex
|
||||
ref['domain_id'] = domain_ref['id']
|
||||
|
||||
self.stub_entity('POST', entity=ref, status_code=201)
|
||||
returned = self.manager.create(name=ref['name'],
|
||||
domain=domain_ref)
|
||||
self.assertIsInstance(returned, self.model)
|
||||
for attr in ref:
|
||||
self.assertEqual(
|
||||
getattr(returned, attr),
|
||||
ref[attr],
|
||||
'Expected different %s' % attr)
|
||||
|
||||
def test_domain_role_grant(self):
|
||||
user_id = uuid.uuid4().hex
|
||||
domain_id = uuid.uuid4().hex
|
||||
|
@@ -27,6 +27,7 @@ class Role(base.Resource):
|
||||
Attributes:
|
||||
* id: a uuid that identifies the role
|
||||
* name: user-facing identifier
|
||||
* domain: optional domain for the role
|
||||
|
||||
"""
|
||||
pass
|
||||
@@ -91,9 +92,14 @@ class RoleManager(base.CrudManager):
|
||||
raise exceptions.ValidationError(msg)
|
||||
|
||||
@positional(1, enforcement=positional.WARN)
|
||||
def create(self, name, **kwargs):
|
||||
def create(self, name, domain=None, **kwargs):
|
||||
domain_id = None
|
||||
if domain:
|
||||
domain_id = base.getid(domain)
|
||||
|
||||
return super(RoleManager, self).create(
|
||||
name=name,
|
||||
domain_id=domain_id,
|
||||
**kwargs)
|
||||
|
||||
def _implied_role_url_tail(self, prior_role, implied_role):
|
||||
|
Reference in New Issue
Block a user