diff --git a/glance/db/simple/api.py b/glance/db/simple/api.py index d52009fd71..6887181faf 100644 --- a/glance/db/simple/api.py +++ b/glance/db/simple/api.py @@ -290,14 +290,14 @@ def is_image_mutable(context, image): def is_image_sharable(context, image, **kwargs): """Return True if the image can be shared to others in this context.""" - # Only allow sharing if we have an owner - if context.owner is None: - return False - # Is admin == image sharable if context.is_admin: return True + # Only allow sharing if we have an owner + if context.owner is None: + return False + # If we own the image, we can share it if context.owner == image['owner']: return True diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index e151d65d9a..5e8ae8de7a 100644 --- a/glance/db/sqlalchemy/api.py +++ b/glance/db/sqlalchemy/api.py @@ -267,14 +267,14 @@ def is_image_mutable(context, image): def is_image_sharable(context, image, **kwargs): """Return True if the image can be shared to others in this context.""" - # Only allow sharing if we have an owner - if context.owner is None: - return False - # Is admin == image sharable if context.is_admin: return True + # Only allow sharing if we have an owner + if context.owner is None: + return False + # If we own the image, we can share it if context.owner == image['owner']: return True diff --git a/glance/tests/unit/test_context.py b/glance/tests/unit/test_context.py index e79ec8a6bb..026c16bec6 100644 --- a/glance/tests/unit/test_context.py +++ b/glance/tests/unit/test_context.py @@ -102,12 +102,12 @@ def test_empty_private_owned(self): def test_empty_shared(self): """ - Tests that an empty context (with is_admin set to True) can + Tests that an empty context (with is_admin set to False) can not share an image, with or without membership. """ - self.do_sharable(False, 'pattieblack', None, is_admin=True) + self.do_sharable(False, 'pattieblack', None, is_admin=False) self.do_sharable(False, 'pattieblack', _fake_membership(True), - is_admin=True) + is_admin=False) def test_anon_public(self): """