Exemple #1
0
    def has_permission(self, request, view):
        try:
            split_url = request.META.get('PATH_INFO').split("/")

            if split_url[3] == "docs":
                return request.user.is_authenticated()

            if len(view.kwargs) == 0 or split_url[3] != "company":
                if request.user.is_superuser:
                    return request.user and request.user.is_authenticated()
                else:
                    raise UnauthorizedAccess

            is_valid_company, message = Utils.check_company_exists(view.kwargs["pk"])
            if not is_valid_company:
                raise ResourceNotFound

            if request.user.is_superuser:
                return request.user and request.user.is_authenticated()
            else:

                return ((request.user.is_superuser or request.user.company.id == int(
                    view.kwargs["pk"])) and request.user.is_authenticated())

        except APIException as err:
            raise err
Exemple #2
0
 def get(self, request, *args, **kwargs):
     try:
         company_id = request.GET.get('company', None)
         # Check company is exists
         is_valid_company, message = Utils.check_company_exists(company_id)
         if not is_valid_company:
             return Utils.dispatch_failure(request, "RESOURCE_NOT_FOUND")
         return Accounting().get_instance_by_id(company_id).connect(request, company_id)
     except KeyError:
         return redirect(request.META["HTTP_REFERRER"])
     except Exception as e:
         return Utils.dispatch_failure(request, 'INTERNAL_SERVER_ERROR')
Exemple #3
0
 def get(self, request, pk, *args, **kwargs):
     try:
         # Check company is exists
         is_valid_company, message = Utils.check_company_exists(pk)
         if not is_valid_company:
             return Utils.dispatch_failure(request, 'RESOURCE_NOT_FOUND')
         login_status = Utils.get_login_status(pk)
         if login_status:
             return Utils.dispatch_success(request, login_status.data)
         return Utils.dispatch_failure(request, 'UNAUTHORIZED_ACCESS')
     except Exception as e:
         print(e)
         return Utils.dispatch_failure(request, 'INTERNAL_SERVER_ERROR')