Skip to content

Commit

Permalink
Add ability to see deleted and active records.
Browse files Browse the repository at this point in the history
Fixes bug #900564

Changes `Context`.`read_deleted` from a bool to an enum string with values
"yes" (can read deleted records), "no" (cannot read deleted records), and
"only" (can only see deleted records, for backwards compatibility).

Change-Id: Ic81db3664c33f23f751b73973782efb06fce90d9
  • Loading branch information
rconradharris committed Dec 7, 2011
1 parent c3b7cce commit c40ee5c
Show file tree
Hide file tree
Showing 10 changed files with 720 additions and 973 deletions.
2 changes: 1 addition & 1 deletion bin/nova-manage
Expand Up @@ -1379,7 +1379,7 @@ class VsaCommands(object):
raise

is_admin = self.manager.is_admin(user_id)
ctxt = context.RequestContext(user_id, project_id, is_admin)
ctxt = context.RequestContext(user_id, project_id, is_admin=is_admin)
if not is_admin and \
not self.manager.is_project_member(user_id, project_id):
msg = _("%(user_id)s must be an admin or a "
Expand Down
37 changes: 21 additions & 16 deletions nova/context.py
Expand Up @@ -19,6 +19,7 @@

"""RequestContext: context for requests that persist through all of nova."""

import copy
import uuid

from nova import local
Expand All @@ -32,9 +33,14 @@ class RequestContext(object):
"""

def __init__(self, user_id, project_id, is_admin=None, read_deleted=False,
def __init__(self, user_id, project_id, is_admin=None, read_deleted="no",
roles=None, remote_address=None, timestamp=None,
request_id=None, auth_token=None, strategy='noauth'):
"""
:param read_deleted: 'no' indicates deleted records are hidden, 'yes'
indicates deleted records are visible, 'only' indicates that
*only* deleted records are visible.
"""
self.user_id = user_id
self.project_id = project_id
self.roles = roles or []
Expand Down Expand Up @@ -73,18 +79,17 @@ def from_dict(cls, values):

def elevated(self, read_deleted=None):
"""Return a version of this context with admin flag set."""
rd = self.read_deleted if read_deleted is None else read_deleted
return RequestContext(user_id=self.user_id,
project_id=self.project_id,
is_admin=True,
read_deleted=rd,
roles=self.roles,
remote_address=self.remote_address,
timestamp=self.timestamp,
request_id=self.request_id,
auth_token=self.auth_token,
strategy=self.strategy)


def get_admin_context(read_deleted=False):
return RequestContext(None, None, True, read_deleted)
context = copy.copy(self)
context.is_admin = True

if read_deleted is not None:
context.read_deleted = read_deleted

return context


def get_admin_context(read_deleted="no"):
return RequestContext(user_id=None,
project_id=None,
is_admin=True,
read_deleted=read_deleted)

0 comments on commit c40ee5c

Please sign in to comment.