# Path: protector/query.py
# class Query(object):
#     """
#         Class helps to construct a custom SQL query
#         It holds params to pass to ORM in array
#     """
#     conditions = None
#     params = None
#     fields = None
#     tables = None
# 
#     def __init__(self, conditions=None, params=None, fields=None, tables=None):
#         self.conditions = conditions or []
#         self.params = params or {}
#         self.fields = fields or []
#         self.tables = tables or []
# 
#     def get_query(self):
#         conditions_string = ") AND (".join(self.conditions)
#         tables_string = ", ".join(self.tables)
#         fields_string = ", ".join(self.fields)
#         result = "SELECT {fields!s} FROM {tables!s}".format(
#             fields=fields_string,
#             tables=tables_string
#         )
#         if self.conditions:
#             result += " WHERE({conditions!s})".format(conditions=conditions_string)
#         return result
# 
#     def get_raw_query(self):
#         return self.get_query().format(**self.params)


from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import connection
from protector.query import Query

ADD_PERMISSION_PERMISSION = 'add_permission'
VIEW_RESTRICTED_OBJECTS = 'view_restricted_objects'
VIEW_GENERIC_GROUP_HISTORY = 'view_generic_group_history'
VIEW_OWNER_TO_PERM_HISTORY = 'view_owner_to_perm_history'

VIEW_PERMISSION_NAME = 'protector.{0}'.format(VIEW_RESTRICTED_OBJECTS)


NULL_OBJECT_CONDITION = " op.object_id IS NULL AND op.content_type_id IS NULL "


# Path: protector/query.py
# class Query(object):
#     """
#         Class helps to construct a custom SQL query
#         It holds params to pass to ORM in array
#     """
#     conditions = None
#     params = None
#     fields = None
#     tables = None
# 
#     def __init__(self, conditions=None, params=None, fields=None, tables=None):
#         self.conditions = conditions or []
#         self.params = params or {}
#         self.fields = fields or []
#         self.tables = tables or []
# 
#     def get_query(self):
#         conditions_string = ") AND (".join(self.conditions)
#         tables_string = ", ".join(self.tables)
#         fields_string = ", ".join(self.fields)
#         result = "SELECT {fields!s} FROM {tables!s}".format(
#             fields=fields_string,
#             tables=tables_string
#         )
#         if self.conditions:
#             result += " WHERE({conditions!s})".format(conditions=conditions_string)
#         return result
# 
#     def get_raw_query(self):
#         return self.get_query().format(**self.params)


# Path: protector/internals.py
from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import connection
from protector.query import Query


ADD_PERMISSION_PERMISSION = 'add_permission'
VIEW_RESTRICTED_OBJECTS = 'view_restricted_objects'
VIEW_GENERIC_GROUP_HISTORY = 'view_generic_group_history'
VIEW_OWNER_TO_PERM_HISTORY = 'view_owner_to_perm_history'

VIEW_PERMISSION_NAME = 'protector.{0}'.format(VIEW_RESTRICTED_OBJECTS)


NULL_OBJECT_CONDITION = " op.object_id IS NULL AND op.content_type_id IS NULL "


DEFAULT_ROLE = 1