Skip to content

Commit

Permalink
Allow admins to share images regardless of owner.
Browse files Browse the repository at this point in the history
Updates the Glance DB's is_image_sharable function so that
an admin can share an image regardless of the context ownership.

This fixes issues when trying to write Glance functional tests
which use the noauth middleware (UnauthenticatedContextMiddleware).

The motivation behind this change is I'd like to write some
functional tests for image-members that work with noauth.

Fix bug 1021054

Change-Id: I6d939876a4c4bf5f191463f5ca434fc524a6ac59
  • Loading branch information
dprince authored and bcwaldon committed Jul 4, 2012
1 parent 517a026 commit a61b4bc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions glance/db/simple/api.py
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions glance/db/sqlalchemy/api.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions glance/tests/unit/test_context.py
Expand Up @@ -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):
"""
Expand Down

0 comments on commit a61b4bc

Please sign in to comment.