Add support for an user admin can see details any cluster, profile

In currently, i can't get/find details of cluster with user have role is admin.
I want I can do this for something my developing such as monitors a cluster, ...
Thanks

Change-Id: I9a42cf52fdbc8baac4ca2646cb2bdec0f0237190
Closes-Bug: #1823188
This commit is contained in:
Bo Tran 2019-06-03 10:28:54 +07:00
parent bb35ef8e53
commit 85bf2626d9
3 changed files with 15 additions and 5 deletions

View File

@ -429,7 +429,8 @@ class EngineService(service.Service):
:return: A dictionary containing the profile details, or an exception
of type `ResourceNotFound` if no matching object is found.
"""
profile = profile_obj.Profile.find(ctx, req.identity)
kwargs = {"project_safe": not ctx.is_admin}
profile = profile_obj.Profile.find(ctx, req.identity, **kwargs)
return profile.to_dict()
@request_context
@ -709,7 +710,9 @@ class EngineService(service.Service):
:param req: An instance of the ClusterGetRequest.
:return: A dictionary containing the details about a cluster.
"""
cluster = co.Cluster.find(context, req.identity)
kwargs = {"project_safe": not context.is_admin}
cluster = co.Cluster.find(context, req.identity, **kwargs)
return cluster.to_dict()
def check_cluster_quota(self, context):

View File

@ -276,12 +276,15 @@ class ClusterTest(base.SenlinTestCase):
x_cluster = mock.Mock()
x_cluster.to_dict.return_value = {'foo': 'bar'}
mock_find.return_value = x_cluster
project_safe = not self.ctx.is_admin
req = orco.ClusterGetRequest(identity='C1')
result = self.eng.cluster_get(self.ctx, req.obj_to_primitive())
self.assertEqual({'foo': 'bar'}, result)
mock_find.assert_called_once_with(self.ctx, 'C1')
mock_find.assert_called_once_with(
self.ctx, 'C1', project_safe=project_safe)
@mock.patch.object(co.Cluster, 'find')
def test_cluster_get_not_found(self, mock_find):

View File

@ -213,11 +213,13 @@ class ProfileTest(base.SenlinTestCase):
mock_find.return_value = x_obj
x_obj.to_dict.return_value = {'foo': 'bar'}
req = vorp.ProfileGetRequest(identity='FAKE_PROFILE')
project_safe = not self.ctx.is_admin
result = self.eng.profile_get(self.ctx, req.obj_to_primitive())
self.assertEqual({'foo': 'bar'}, result)
mock_find.assert_called_once_with(self.ctx, 'FAKE_PROFILE')
mock_find.assert_called_once_with(
self.ctx, 'FAKE_PROFILE', project_safe=project_safe)
@mock.patch.object(po.Profile, 'find')
def test_profile_get_not_found(self, mock_find):
@ -227,11 +229,13 @@ class ProfileTest(base.SenlinTestCase):
ex = self.assertRaises(rpc.ExpectedException,
self.eng.profile_get, self.ctx,
req.obj_to_primitive())
project_safe = not self.ctx.is_admin
self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
self.assertEqual("The profile 'Bogus' could not be found.",
six.text_type(ex.exc_info[1]))
mock_find.assert_called_once_with(self.ctx, 'Bogus')
mock_find.assert_called_once_with(
self.ctx, 'Bogus', project_safe=project_safe)
@mock.patch.object(pb.Profile, 'load')
@mock.patch.object(po.Profile, 'find')