Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        block_msg = check_blocks(raise_error=False,
                                 error_message='Task is blocked.')
        if block_msg is not False:
            return HttpResponseForbidden(block_msg)
        if self.disallow_start():
            return HttpResponseForbidden(
                'Forbidden. Such task is already started.')
        request_data = request.POST or request.data

        if self.form_class is None:
            data = request.POST.dict() or request.data
        else:
            form = self.form_class(data=request_data, files=request.FILES)
            if not form.is_valid():
                return self.json_response(form.errors, status=400)
            data = form.cleaned_data
        data['user_id'] = request.user.pk
        data['metadata'] = self.get_metadata()
        data['module_name'] = getattr(self, 'module_name',
                                      None) or self.__module__.replace(
                                          'views', 'tasks')
        data['skip_confirmation'] = request_data.get(
            'skip_confirmation') or False
        return self.start_task_and_return(data)
 def has_permission(self, request, view):
     # check for any app-wide blocks
     if request.method != 'GET':
         block_msg = check_blocks(raise_error=False, error_message='Unable to process request.')
         if block_msg is not False:
             self.message = block_msg
             return False
     return True
Exemplo n.º 3
0
 def form_valid(self, form):
     block_msg = check_blocks(raise_error=False)
     if block_msg is not False:
         return HttpResponseForbidden(block_msg)
     data = form.cleaned_data
     data['user_id'] = self.request.user.pk
     call_task(self.task_name, **data)
     return redirect(reverse('task:task-list'))
Exemplo n.º 4
0
 def get(self, request, *args, **kwargs):
     block_msg = check_blocks(raise_error=False,
                              error_message='Task is blocked.')
     if block_msg is not False:
         return HttpResponseForbidden(block_msg)
     if self.disallow_start():
         return HttpResponseForbidden(
             'Forbidden. Task "%s" is already started.' % self.task_name)
     else:
         form = self.form_class()
         data = dict(header=form.header,
                     form_class=self.html_form_class,
                     form_data=form.as_p())
     return self.json_response(data)
Exemplo n.º 5
0
 def process_view(self, request, view_func, args, kwargs):
     # check for any app-wide blocks
     if request.method != 'GET':
         # allow any actions under /admin
         if ALLOWED_ALWAYS_NON_GET_URLS.search(request.path):
             return
         block_msg = check_blocks(raise_error=False, error_message='Unable to process request.')
         if block_msg is not False:
             # 1. request is ajax
             # 2. content type is json
             # 3. any api request (except /api/app/ or /api/version/ - mostly this check is for
             # apps.project.api.v1.ProjectViewSet.send_clusters_to_project which receives form data
             if request.is_ajax() or request.META['CONTENT_TYPE'] == 'application/json' or re.search(r'^/api/v\d', request.path):
                 response = JsonResponse({'detail': block_msg}, status=403)
             else:
                 response = HttpResponseForbidden()
                 response.content = render(request, '403.html', context={'message': block_msg})
             return response
Exemplo n.º 6
0
 def has_permission(self):
     from apps.task.utils.task_utils import check_blocks
     return not check_blocks(raise_error=False)