Skip to content

Commit 6c37be2

Browse files
committed
Fixes #174
1 parent d822696 commit 6c37be2

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

dojo/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class AdHocFindingForm(forms.ModelForm):
645645

646646
def clean(self):
647647
# self.fields['endpoints'].queryset = Endpoint.objects.all()
648-
cleaned_data = super(AddFindingForm, self).clean()
648+
cleaned_data = super(AdHocFindingForm, self).clean()
649649
if ((cleaned_data['active'] or cleaned_data['verified'])
650650
and cleaned_data['duplicate']):
651651
raise forms.ValidationError('Duplicate findings cannot be'

dojo/product/views.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from dojo.filters import ProductFilter, ProductFindingFilter
2121
from dojo.forms import ProductForm, EngForm, DeleteProductForm, ProductMetaDataForm, JIRAPKeyForm, JIRAFindingForm, AdHocFindingForm
2222
from dojo.models import Product_Type, Finding, Product, Engagement, ScanSettings, Risk_Acceptance, Test, JIRA_PKey, \
23-
Tool_Product_Settings, Cred_User, Cred_Mapping, Finding_Template, Endpoint
23+
Tool_Product_Settings, Cred_User, Cred_Mapping, Finding_Template, Endpoint, Test_Type
2424
from dojo.utils import get_page_items, add_breadcrumb, get_punchcard_data
2525
from custom_field.models import CustomFieldValue, CustomField
2626
from dojo.tasks import add_epic_task, add_issue_task
@@ -569,8 +569,25 @@ def edit_meta_data(request, pid):
569569

570570
@user_passes_test(lambda u: u.is_staff)
571571
def ad_hoc_finding(request, pid):
572-
eng=Engagement()
573-
test = Test()
572+
prod = Product.objects.get(id=pid)
573+
test = None
574+
try:
575+
eng = Engagement.objects.get(product=prod, name="Ad Hoc Engagement")
576+
tests = Test.objects.filter(engagement=eng)
577+
578+
if len(tests) != 0:
579+
test = tests[0]
580+
else:
581+
test = Test(engagement=eng, test_type=Test_Type.objects.get(name="Pen Test"),
582+
target_start=datetime.now(tz=localtz), target_end=datetime.now(tz=localtz))
583+
test.save()
584+
except:
585+
eng = Engagement(name="Ad Hoc Engagement", target_start=datetime.now(tz=localtz),
586+
target_end=datetime.now(tz=localtz), active=False, product=prod)
587+
eng.save()
588+
test = Test(engagement=eng, test_type=Test_Type.objects.get(name="Pen Test"),
589+
target_start=datetime.now(tz=localtz), target_end=datetime.now(tz=localtz))
590+
test.save()
574591
form_error = False
575592
enabled = False
576593
jform = None
@@ -643,11 +660,12 @@ def ad_hoc_finding(request, pid):
643660
messages.ERROR,
644661
'The form has errors, please correct them below.',
645662
extra_tags='alert-danger')
646-
add_breadcrumb(parent=test, title="Add Finding", top_level=False, request=request)
647-
return render(request, 'dojo/add_findings.html',
663+
add_breadcrumb(parent=prod, title="Add Finding", top_level=False, request=request)
664+
return render(request, 'dojo/ad_hoc_findings.html',
648665
{'form': form,
649666
'temp': False,
650-
'tid': tid,
667+
'tid' : test.id,
668+
'pid': pid,
651669
'form_error': form_error,
652670
'jform': jform,
653671
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{% extends "base.html" %}
2+
{% load event_tags %}
3+
{% load static from staticfiles %}
4+
{% block content %}
5+
<div>
6+
<h3> Add findings to a test</h3>
7+
</div>
8+
<div>
9+
<form class="form-horizontal" action="{% url 'ad_hoc_finding' pid %}" method="post">
10+
{% csrf_token %}
11+
{% include "dojo/form_fields.html" with form=form %}
12+
{% if jform %}
13+
<h4> JIRA </h4>
14+
<hr>
15+
{% include "dojo/form_fields.html" with form=jform %}
16+
{% endif %}
17+
<div class="form-group">
18+
<div class="col-sm-offset-2 col-sm-10">
19+
<input class="btn btn-primary" type="submit" value="Add Another Finding"/>
20+
<input class="btn btn-primary" name="_Finished" type="submit" value="Finished"/>
21+
</div>
22+
</div>
23+
</form>
24+
</div>
25+
{% endblock %}
26+
{% block postscript %}
27+
<script type="text/javascript" src="{% static "admin/js/jquery.init.js"%}"></script>
28+
<script type="application/javascript" src="{% static "admin/js/admin/RelatedObjectLookups.js" %}"></script>
29+
<script type="application/javascript">
30+
$ = django.jQuery;
31+
$('#add_id_endpoints').attr('href', "{% url 'add_endpoint' pid %}?_popup");
32+
{% if not form_error %}
33+
$('#id_endpoints').find('option').remove();
34+
{% endif %}
35+
</script>
36+
37+
38+
{% endblock %}

0 commit comments

Comments
 (0)