# Path: tutelary/models.py
# def check_perms(user, actions, objs, method=None):
#     ensure_permission_set_tree_cached(user)
#     if actions is False:
#         return False
#     if actions is not None:
#         for a in actions:
#             for o in objs:
#                 test_obj = None
#                 if o is not None:
#                     test_obj = o.get_permissions_object(a)
#                 if not user.has_perm(a, test_obj):
#                     return False
#     return True
# 
# Path: tutelary/decorators.py
# def action_error_message(actions, req_actions, default=None):
#     for req in req_actions:
#         for a in actions:
#             if isinstance(a, tuple) and a[0] == req:
#                 if 'error_message' in a[1]:
#                     return (a[1]['error_message'],)
#     if default is not None:
#         return (default,)
#     else:
#         return ()


from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from collections.abc import Sequence
from django.contrib.auth.views import redirect_to_login
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http.response import Http404
from .models import check_perms
from .decorators import action_error_message



class BasePermissionRequiredMixin:
    def get_permission_required(self):
        if (not hasattr(self, 'permission_required') or
           self.permission_required is None):
            raise ImproperlyConfigured(
                '{0} is missing the permission_required attribute. Define '
                '{0}.permission_required, or override '
                '{0}.get_permission_required().'.format(
                    self.__class__.__name__)
            )

        perms = self.permission_required
        if isinstance(self.permission_required, dict):
            perms = self.permission_required.get(self.request.method, ())

        if callable(perms):
            perms = perms(self, self.request)

        if isinstance(perms, str):
            perms = (perms, )

        return perms

    def get_permission_denied_message(self, default=None):
        if hasattr(self, 'permission_denied_message'):

# Path: tutelary/models.py
# def check_perms(user, actions, objs, method=None):
#     ensure_permission_set_tree_cached(user)
#     if actions is False:
#         return False
#     if actions is not None:
#         for a in actions:
#             for o in objs:
#                 test_obj = None
#                 if o is not None:
#                     test_obj = o.get_permissions_object(a)
#                 if not user.has_perm(a, test_obj):
#                     return False
#     return True
# 
# Path: tutelary/decorators.py
# def action_error_message(actions, req_actions, default=None):
#     for req in req_actions:
#         for a in actions:
#             if isinstance(a, tuple) and a[0] == req:
#                 if 'error_message' in a[1]:
#                     return (a[1]['error_message'],)
#     if default is not None:
#         return (default,)
#     else:
#         return ()


# Path: tutelary/mixins.py
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from collections.abc import Sequence
from django.contrib.auth.views import redirect_to_login
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http.response import Http404
from .models import check_perms
from .decorators import action_error_message




class BasePermissionRequiredMixin:
    def get_permission_required(self):
        if (not hasattr(self, 'permission_required') or
           self.permission_required is None):
            raise ImproperlyConfigured(
                '{0} is missing the permission_required attribute. Define '
                '{0}.permission_required, or override '
                '{0}.get_permission_required().'.format(
                    self.__class__.__name__)
            )

        perms = self.permission_required
        if isinstance(self.permission_required, dict):
            perms = self.permission_required.get(self.request.method, ())

        if callable(perms):
            perms = perms(self, self.request)

        if isinstance(perms, str):
            perms = (perms, )

        return perms

    def get_permission_denied_message(self, default=None):
        if hasattr(self, 'permission_denied_message'):

            return (self.permission_denied_message,)