Merge "Remove unused methods"
This commit is contained in:
commit
3dfa413f00
|
@ -27,7 +27,6 @@ from oslo_log import log as logging
|
|||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
from masakari import exception
|
||||
from masakari.i18n import _
|
||||
from masakari import policy
|
||||
from masakari import utils
|
||||
|
@ -212,46 +211,3 @@ def get_admin_context(read_deleted="no"):
|
|||
is_admin=True,
|
||||
read_deleted=read_deleted,
|
||||
overwrite=False)
|
||||
|
||||
|
||||
def is_user_context(context):
|
||||
"""Indicates if the request context is a normal user."""
|
||||
if not context:
|
||||
return False
|
||||
if context.is_admin:
|
||||
return False
|
||||
if not context.user_id or not context.project_id:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def require_admin_context(ctxt):
|
||||
"""Raise exception.AdminRequired() if context is not an admin context."""
|
||||
if not ctxt.is_admin:
|
||||
raise exception.AdminRequired()
|
||||
|
||||
|
||||
def require_context(ctxt):
|
||||
"""Raise exception.Forbidden() if context is not a user or an
|
||||
admin context.
|
||||
"""
|
||||
if not ctxt.is_admin and not is_user_context(ctxt):
|
||||
raise exception.Forbidden()
|
||||
|
||||
|
||||
def authorize_project_context(context, project_id):
|
||||
"""Ensures a request has permission to access the given project."""
|
||||
if is_user_context(context):
|
||||
if not context.project_id:
|
||||
raise exception.Forbidden()
|
||||
elif context.project_id != project_id:
|
||||
raise exception.Forbidden()
|
||||
|
||||
|
||||
def authorize_user_context(context, user_id):
|
||||
"""Ensures a request has permission to access the given user."""
|
||||
if is_user_context(context):
|
||||
if not context.user_id:
|
||||
raise exception.Forbidden()
|
||||
elif context.user_id != user_id:
|
||||
raise exception.Forbidden()
|
||||
|
|
|
@ -21,10 +21,8 @@ from oslo_db import exception as db_exc
|
|||
from oslo_db.sqlalchemy import enginefacade
|
||||
from oslo_db.sqlalchemy import utils as sqlalchemyutils
|
||||
from oslo_utils import timeutils
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.sql import null
|
||||
|
||||
import masakari.conf
|
||||
from masakari.db.sqlalchemy import models
|
||||
|
@ -93,10 +91,7 @@ def create_context_manager(connection=None):
|
|||
return ctxt_mgr
|
||||
|
||||
|
||||
def model_query(context, model,
|
||||
args=None,
|
||||
read_deleted=None,
|
||||
project_only=False):
|
||||
def model_query(context, model, args=None, read_deleted=None):
|
||||
"""Query helper that accounts for context's `read_deleted` field.
|
||||
:param context: MasakariContext of the query.
|
||||
:param model: Model to query. Must be a subclass of ModelBase.
|
||||
|
@ -106,9 +101,6 @@ def model_query(context, model,
|
|||
deleted values; 'only', which only returns deleted
|
||||
values; and 'yes', which does not filter deleted
|
||||
values.
|
||||
:param project_only: If set and context is user-type, then restrict
|
||||
query to match the context's project_id. If set to
|
||||
'allow_none', restriction includes project_id = None.
|
||||
"""
|
||||
|
||||
if read_deleted is None:
|
||||
|
@ -128,13 +120,6 @@ def model_query(context, model,
|
|||
query = sqlalchemyutils.model_query(
|
||||
model, context.session, args, **query_kwargs)
|
||||
|
||||
if masakari.context.is_user_context(context) and project_only:
|
||||
if project_only == 'allow_none':
|
||||
query = query.filter(or_(model.project_id == context.project_id,
|
||||
model.project_id == null()))
|
||||
else:
|
||||
query = query.filter_by(project_id=context.project_id)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue