Commit 7755caa3 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: Slight change in get_domain_objects

This method gets two keyword arguments: user and check_permissions.
If check_permissions is True returns only the object accessible to the user.
Otherwise list all the objects for the specific domain ignoring
permissions.
The latter case is only meaningful if user is not provided,
therefore in that case it raises AssertionError.
parent 9113fea6
......@@ -2525,12 +2525,28 @@ class ModularBackend(BaseBackend):
@debug_method
@backend_method
def get_domain_objects(self, domain, user=None, check_permissions=True):
"""List objects having metadata in the specific domain
If user is provided list only objects accessible to the user.
Otherwise list all the objects for the specific domain
ignoring permissions (check_permissions should be False)
Raises:
NotAllowedError: if check_permissions is True and user has not
access to the object
AssertionError: if check_permissions is True but user
is provided
"""
if check_permissions:
allowed_paths = self.permissions.access_list_paths(
user, include_owned=user is not None, include_containers=False)
if not allowed_paths:
return []
else:
if user is not None:
raise AssertionError('Inconsistent argument combination:'
'if user is provided '
'permission check should be enforced.')
allowed_paths = None
obj_list = self.node.domain_object_list(
domain, allowed_paths, CLUSTER_NORMAL)
......
......@@ -54,8 +54,10 @@ class TestSnapshotsMixin(object):
self.assertTrue('uuid' in meta2)
uuid = meta2['uuid']
self.assertRaises(AssertionError, self.b.update_object_status, uuid, 'invalid_state')
self.assertRaises(NameError, self.b.update_object_status, str(uuidlib.uuid4()), -1)
self.assertRaises(AssertionError, self.b.update_object_status, uuid,
'invalid_state')
self.assertRaises(NameError, self.b.update_object_status,
str(uuidlib.uuid4()), -1)
self.b.update_object_status(uuid, MAP_ERROR)
......@@ -168,13 +170,17 @@ class TestSnapshotsMixin(object):
self.assertTrue('available' in meta)
self.assertEqual(meta['available'], MAP_UNAVAILABLE)
objects = self.b.get_domain_objects(domain='test', user='somebody_else', check_permissions=True)
objects = self.b.get_domain_objects(domain='test',
user='somebody_else',
check_permissions=True)
self.assertEqual(objects, [])
objects = self.b.get_domain_objects(domain='test', user=None, check_permissions=True)
objects = self.b.get_domain_objects(domain='test', user=None,
check_permissions=True)
self.assertEqual(objects, [])
objects = self.b.get_domain_objects(domain='test', user=None, check_permissions=False)
objects = self.b.get_domain_objects(domain='test', user=None,
check_permissions=False)
self.assertEqual(len(objects), 1)
path, meta, permissios = objects[0]
self.assertEqual(path, '/'.join(t[1:]))
......@@ -183,11 +189,8 @@ class TestSnapshotsMixin(object):
self.assertTrue('available' in meta)
self.assertEqual(meta['available'], MAP_UNAVAILABLE)
objects = self.b.get_domain_objects(domain='test', user='somebody_else', check_permissions=False)
self.assertEqual(len(objects), 1)
path, meta, permissios = objects[0]
self.assertEqual(path, '/'.join(t[1:]))
self.assertTrue('uuid' in meta)
self.assertEqual(meta['uuid'], uuid)
self.assertTrue('available' in meta)
self.assertEqual(meta['available'], MAP_UNAVAILABLE)
self.assertRaises(AssertionError,
self.b.get_domain_objects,
domain='test',
user='somebody_else',
check_permissions=False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment