from rest_framework.permissions import BasePermission

class StaffOnly_perm(BasePermission):
    """
    Allows access only to staff users.
    """
    def has_permission(self, request, view):
        return request.user and request.user.is_staff


class api_1C_perm(BasePermission):
    """
    Allows access only 1C users.
    """

    # def has_object_permission(self, request, view, obj):
    def has_permission(self, request, view):
        if request.user.id == 8751:
            try:
                if request.req_type == 'warehouse_import':
                    return True
                else:
                    return False
            except:
                return False
        perm = request.user.has_perm('AuthApp.1c_api')
        return perm


class full_api_perm(BasePermission):
    """
    Allows access only users w full access.
    """
    def has_permission(self, request, view):
        return request.user.has_perm('AuthApp.full_api')

