Пример #1
0
def request_audit(request, project_uuid):
    if request.method == "POST":
        check_if_member_of_project(request.user.id, project_uuid)
        project = get_object_or_404(Project, pk=project_uuid)
        audit_parameters_list = project.audit_parameters_list.all()

        created_audits = []
        for audit_parameters in audit_parameters_list:
            for page in project.pages.all():
                audit = Audit.objects.create(page=page, parameters=audit_parameters)
                task_request_audit.delay(audit.uuid)
                AuditStatusHistory.objects.create(
                    audit=audit,
                    status=AvailableStatuses.REQUESTED.value,
                    details="Audit created in database",
                )
                created_audits.append(audit)

            for script in project.scripts.all():
                audit = Audit.objects.create(script=script, parameters=audit_parameters)
                task_request_audit.delay(audit.uuid)
                AuditStatusHistory.objects.create(
                    audit=audit,
                    status=AvailableStatuses.REQUESTED.value,
                    details="Audit created in database",
                )
                created_audits.append(audit)

        created_audit_serializers = AuditSerializer(created_audits, many=True)

        return JsonResponse(
            created_audit_serializers.data, status=status.HTTP_201_CREATED, safe=False
        )
Пример #2
0
    def submit_form(self, project, user):
        try:
            check_if_member_of_project(user.id, project.uuid)
            page_or_script_to_audit_uuid = self.data["page_or_script_to_audit"]
            audit_parameters_uuid = self.data["audit_parameters_to_use"]

            if "__all__" == page_or_script_to_audit_uuid:
                pages_to_audit = project.pages.all()
                scripts_to_audit = project.scripts.all()
            else:
                pages_to_audit = project.pages.filter(
                    uuid=page_or_script_to_audit_uuid)
                scripts_to_audit = project.scripts.filter(
                    uuid=page_or_script_to_audit_uuid)

            if "__all__" == audit_parameters_uuid:
                audit_parameters_list = project.audit_parameters_list.all()
            else:
                audit_parameters_list = project.audit_parameters_list.filter(
                    uuid=audit_parameters_uuid)

            for audit_parameters in audit_parameters_list:
                for page_to_audit in pages_to_audit:
                    new_page_audit = Audit(page=page_to_audit,
                                           parameters=audit_parameters)
                    new_page_audit.save()
                    request_audit.delay(new_page_audit.uuid)

                for script_to_audit in scripts_to_audit:
                    new_script_audit = Audit(script=script_to_audit,
                                             parameters=audit_parameters)
                    new_script_audit.save()
                    request_audit.delay(new_script_audit.uuid)

        except Exception as e:
            error_message = str(e)
            self.add_error(None, error_message)
            raise

        return True