コード例 #1
0
def finding_bulk_update(request, tid):
    test = get_object_or_404(Test, id=tid)
    form = FindingBulkUpdateForm(request.POST)

    if request.method == "POST":
        finding_to_update = request.POST.getlist('finding_to_update')
        if request.POST.get('delete_bulk_findings') and finding_to_update:
            finds = Finding.objects.filter(test=test, id__in=finding_to_update)
            product = Product.objects.get(engagement__test=test)
            finds.delete()
            calculate_grade(product)
        else:
            if form.is_valid() and finding_to_update:
                finding_to_update = request.POST.getlist('finding_to_update')
                finds = Finding.objects.filter(test=test, id__in=finding_to_update)
                if form.cleaned_data['severity']:
                    finds.update(severity=form.cleaned_data['severity'],
                                 numerical_severity=Finding.get_numerical_severity(form.cleaned_data['severity']),
                                 last_reviewed=timezone.now(),
                                 last_reviewed_by=request.user)
                if form.cleaned_data['status']:
                    finds.update(active=form.cleaned_data['active'],
                                 verified=form.cleaned_data['verified'],
                                 false_p=form.cleaned_data['false_p'],
                                 out_of_scope=form.cleaned_data['out_of_scope'],
                                 is_Mitigated=form.cleaned_data['is_Mitigated'],
                                 last_reviewed=timezone.now(),
                                 last_reviewed_by=request.user)
                if form.cleaned_data['tags']:
                    for finding in finds:
                        tags = request.POST.getlist('tags')
                        ts = ", ".join(tags)
                        finding.tags = ts

                # Update the grade as bulk edits don't go through save
                if form.cleaned_data['severity'] or form.cleaned_data['status']:
                    calculate_grade(test.engagement.product)

                for finding in finds:
                    if JIRA_PKey.objects.filter(product=finding.test.engagement.product).count() == 0:
                        log_jira_alert('Finding cannot be pushed to jira as there is no jira configuration for this product.', finding)
                    else:
                        old_status = finding.status()
                        if form.cleaned_data['push_to_jira']:
                            if JIRA_Issue.objects.filter(finding=finding).exists():
                                update_issue_task.delay(finding, old_status, True)
                            else:
                                add_issue_task.delay(finding, True)

                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Bulk edit of findings was successful.  Check to make sure it is what you intended.',
                                     extra_tags='alert-success')
            else:
                messages.add_message(request,
                                     messages.ERROR,
                                     'Unable to process bulk update. Required fields were not selected.',
                                     extra_tags='alert-danger')

    return HttpResponseRedirect(reverse('view_test', args=(test.id,)))
コード例 #2
0
ファイル: views.py プロジェクト: Prakhash/security-tools
def finding_bulk_update(request, tid):
    test = get_object_or_404(Test, id=tid)
    finding = test.finding_set.all()[0]
    form = FindingBulkUpdateForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            finding_to_update = request.POST.getlist('finding_to_update')
            finds = Finding.objects.filter(test=test, id__in=finding_to_update)
            finds.update(severity=form.cleaned_data['severity'],
                         active=form.cleaned_data['active'],
                         verified=form.cleaned_data['verified'],
                         false_p=form.cleaned_data['false_p'],
                         duplicate=form.cleaned_data['duplicate'],
                         out_of_scope=form.cleaned_data['out_of_scope'])
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Bulk edit of findings was successful.  Check to make sure it is what you intended.',
                                 extra_tags='alert-success')
        else:
            messages.add_message(request,
                                 messages.ERROR,
                                 'Unable to process bulk update. Required fields are invalid,  '
                                 'please update individually.',
                                 extra_tags='alert-danger')

    return HttpResponseRedirect(reverse('view_test', args=(test.id,)))
コード例 #3
0
ファイル: views.py プロジェクト: szeist/django-DefectDojo
def finding_bulk_update(request, tid):
    test = get_object_or_404(Test, id=tid)
    finding = test.finding_set.all()[0]
    form = FindingBulkUpdateForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            finding_to_update = request.POST.getlist('finding_to_update')
            finds = Finding.objects.filter(test=test, id__in=finding_to_update)
            finds.update(severity=form.cleaned_data['severity'],
                         active=form.cleaned_data['active'],
                         verified=form.cleaned_data['verified'],
                         false_p=form.cleaned_data['false_p'],
                         duplicate=form.cleaned_data['duplicate'],
                         out_of_scope=form.cleaned_data['out_of_scope'])
            messages.add_message(
                request,
                messages.SUCCESS,
                'Bulk edit of findings was successful.  Check to make sure it is what you intended.',
                extra_tags='alert-success')
        else:
            messages.add_message(
                request,
                messages.ERROR,
                'Unable to process bulk update.  The Severity field is required, '
                'all others are optional.',
                extra_tags='alert-danger')

    return HttpResponseRedirect(reverse('view_test', args=(test.id, )))
コード例 #4
0
ファイル: views.py プロジェクト: Ravenons/django-DefectDojo
def finding_bulk_update(request, tid):
    test = get_object_or_404(Test, id=tid)
    form = FindingBulkUpdateForm(request.POST)

    if request.method == "POST":
        finding_to_update = request.POST.getlist('finding_to_update')
        if request.POST.get('delete_bulk_findings') and finding_to_update:
            finds = Finding.objects.filter(test=test, id__in=finding_to_update)
            product = Product.objects.get(engagement__test=test)
            finds.delete()
            calculate_grade(product)
        else:
            if form.is_valid() and finding_to_update:
                finding_to_update = request.POST.getlist('finding_to_update')
                finds = Finding.objects.filter(test=test,
                                               id__in=finding_to_update)
                if form.cleaned_data['severity']:
                    finds.update(
                        severity=form.cleaned_data['severity'],
                        numerical_severity=Finding.get_numerical_severity(
                            form.cleaned_data['severity']),
                        last_reviewed=timezone.now(),
                        last_reviewed_by=request.user)
                if form.cleaned_data['status']:
                    finds.update(
                        active=form.cleaned_data['active'],
                        verified=form.cleaned_data['verified'],
                        false_p=form.cleaned_data['false_p'],
                        out_of_scope=form.cleaned_data['out_of_scope'],
                        last_reviewed=timezone.now(),
                        last_reviewed_by=request.user)

                # Update the grade as bulk edits don't go through save
                if form.cleaned_data['severity'] or form.cleaned_data['status']:
                    calculate_grade(test.engagement.product)

                messages.add_message(
                    request,
                    messages.SUCCESS,
                    'Bulk edit of findings was successful.  Check to make sure it is what you intended.',
                    extra_tags='alert-success')
            else:
                messages.add_message(
                    request,
                    messages.ERROR,
                    'Unable to process bulk update. Required fields were not selected.',
                    extra_tags='alert-danger')

    return HttpResponseRedirect(reverse('view_test', args=(test.id, )))
コード例 #5
0
ファイル: views.py プロジェクト: devGregA/django-DefectDojo
def finding_bulk_update(request, tid):
    test = get_object_or_404(Test, id=tid)
    form = FindingBulkUpdateForm(request.POST)

    if request.method == "POST":
        finding_to_update = request.POST.getlist('finding_to_update')
        if request.POST.get('delete_bulk_findings') and finding_to_update:
            finds = Finding.objects.filter(test=test, id__in=finding_to_update)
            product = Product.objects.get(engagement__test=test)
            finds.delete()
            calculate_grade(product)
        else:
            if form.is_valid() and finding_to_update:
                finding_to_update = request.POST.getlist('finding_to_update')
                finds = Finding.objects.filter(test=test, id__in=finding_to_update)
                if form.cleaned_data['severity']:
                    finds.update(severity=form.cleaned_data['severity'],
                                 numerical_severity=Finding.get_numerical_severity(form.cleaned_data['severity']),
                                 last_reviewed=timezone.now(),
                                 last_reviewed_by=request.user)
                if form.cleaned_data['status']:
                    finds.update(active=form.cleaned_data['active'],
                                 verified=form.cleaned_data['verified'],
                                 false_p=form.cleaned_data['false_p'],
                                 out_of_scope=form.cleaned_data['out_of_scope'],
                                 last_reviewed=timezone.now(),
                                 last_reviewed_by=request.user)

                # Update the grade as bulk edits don't go through save
                if form.cleaned_data['severity'] or form.cleaned_data['status']:
                    calculate_grade(test.engagement.product)

                messages.add_message(request,
                                     messages.SUCCESS,
                                     'Bulk edit of findings was successful.  Check to make sure it is what you intended.',
                                     extra_tags='alert-success')
            else:
                messages.add_message(request,
                                     messages.ERROR,
                                     'Unable to process bulk update. Required fields were not selected.',
                                     extra_tags='alert-danger')

    return HttpResponseRedirect(reverse('view_test', args=(test.id,)))