Skip to content

Commit 17587d9

Browse files
authored
Merge pull request DefectDojo#1012 from valentijnscholten/feature/jira-improvements
jira integration improvements including bulk push to jira
2 parents c24473a + c92e98c commit 17587d9

File tree

8 files changed

+57
-8
lines changed

8 files changed

+57
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,6 @@ venv/
101101
ENV/
102102
quick.bash
103103
*.tgz
104+
105+
#visual studio code
106+
*.code-workspace

dojo/finding/views.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
FindingImageAccessToken, JIRA_Issue, JIRA_PKey, Dojo_User, Cred_Mapping, Test, Product, User
3535
from dojo.utils import get_page_items, add_breadcrumb, FileIterWrapper, process_notifications, \
3636
add_comment, jira_get_resolution_id, jira_change_resolution_id, get_jira_connection, \
37-
get_system_setting, create_notification, apply_cwe_to_template, Product_Tab, calculate_grade
37+
get_system_setting, create_notification, apply_cwe_to_template, Product_Tab, calculate_grade, log_jira_alert
3838

3939
from dojo.tasks import add_issue_task, update_issue_task, add_comment_task
4040
from django.template.defaultfilters import pluralize
@@ -1471,6 +1471,17 @@ def finding_bulk_update_all(request, pid=None):
14711471
calculate_grade(finding.test.engagement.product)
14721472
prev_prod = finding.test.engagement.product.id
14731473

1474+
for finding in finds:
1475+
if JIRA_PKey.objects.filter(product=finding.test.engagement.product).count() == 0:
1476+
log_jira_alert('Finding cannot be pushed to jira as there is no jira configuration for this product.', finding)
1477+
else:
1478+
old_status = finding.status()
1479+
if form.cleaned_data['push_to_jira']:
1480+
if JIRA_Issue.objects.filter(finding=finding).exists():
1481+
update_issue_task.delay(finding, old_status, True)
1482+
else:
1483+
add_issue_task.delay(finding, True)
1484+
14741485
messages.add_message(request,
14751486
messages.SUCCESS,
14761487
'Bulk edit of findings was successful. Check to make sure it is what you intended.',

dojo/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,7 @@ class Meta:
951951

952952
class FindingBulkUpdateForm(forms.ModelForm):
953953
status = forms.BooleanField(required=False)
954+
push_to_jira = forms.BooleanField(required=False)
954955

955956
def __init__(self, *args, **kwargs):
956957
super(FindingBulkUpdateForm, self).__init__(*args, **kwargs)

dojo/models.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,15 @@ def long_desc(self):
12081208
long_desc = ''
12091209
long_desc += '*' + self.title + '*\n\n'
12101210
long_desc += '*Severity:* ' + self.severity + '\n\n'
1211-
long_desc += '*Systems*: \n'
1211+
long_desc += '*Product/Engagement:* ' + self.test.engagement.product.name + ' / ' + self.test.engagement.name + '\n\n'
1212+
if self.test.engagement.branch_tag:
1213+
long_desc += '*Branch/Tag:* ' + self.test.engagement.branch_tag + '\n\n'
1214+
if self.test.engagement.build_id:
1215+
long_desc += '*BuildID:* ' + self.test.engagement.build_id + '\n\n'
1216+
if self.test.engagement.commit_hash:
1217+
long_desc += '*Commit hash:* ' + self.test.engagement.commit_hash + '\n\n'
1218+
long_desc += '*Systems*: \n\n'
1219+
12121220
for e in self.endpoints.all():
12131221
long_desc += str(e) + '\n\n'
12141222
long_desc += '*Description*: \n' + self.description + '\n\n'

dojo/templates/dojo/findings_list.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ <h3 class="has-filters">
5757
<input id="id_out_of_scope" name="out_of_scope" type="checkbox" disabled/>
5858
<span>Out of scope</span>
5959
</label>
60+
{% if "enable_jira"|get_system_setting %}
61+
<b>Push to JIRA</b> <input id="id_push_tojira" name="push_to_jira" type="checkbox" alt="Select to push to JIRA"/><br/>
62+
{% endif %}
6063
<input type="submit" class="btn btn-sm btn-primary" value="Submit"/>
6164
</form>
6265
</li>
@@ -285,7 +288,8 @@ <h3 class="has-filters">
285288
<td class="nowrap">
286289
{% if "enable_jira"|get_system_setting %}
287290
{% if finding.jira.jira_key %}
288-
<a href="{{finding.jira_conf.url}}/browse/{{finding.jira.jira_key}}" target="_blank" alt="Jira Bug - {{finding.jira.jira_key}}"><i class="fa fa-bug fa-fw"></i></a>
291+
<a href="{{finding.jira_conf.url}}/browse/{{finding.jira.jira_key}}" target="_blank"
292+
alt="Jira Bug - {{finding.jira.jira_key}}" data-toggle="tooltip" data-placement="bottom" title="{{finding.jira.jira_key}}"><i class="fa fa-bug fa-fw"></i></a>
289293
{% endif %}
290294
{% if finding.notes.count %}
291295
<a href="{% url 'view_finding' finding.id %}#vuln_notes" alt="{{ finding.notes.count }} comment{{ finding.notes.count|pluralize }}">

dojo/templates/dojo/view_test.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ <h4>Details <span class="pull-right"><a data-toggle="collapse" href="#vuln_desc"
182182
<input id="id_out_of_scope" name="out_of_scope" type="checkbox" disabled/>
183183
<span>Out of scope</span>
184184
</label>
185+
{% if "enable_jira"|get_system_setting %}
186+
<b>Push to JIRA</b> <input id="id_push_tojira" name="push_to_jira" type="checkbox" alt="Select to push to JIRA"/><br/>
187+
{% endif %}
185188
<input type="submit" class="btn btn-sm btn-primary" value="Submit"/>
186189
</form>
187190
</li>

dojo/test/views.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from dojo.forms import NoteForm, TestForm, FindingForm, \
2121
DeleteTestForm, AddFindingForm, \
2222
ImportScanForm, ReImportScanForm, FindingBulkUpdateForm, JIRAFindingForm
23-
from dojo.models import Product, Finding, Test, Notes, BurpRawRequestResponse, Endpoint, Stub_Finding, Finding_Template, JIRA_PKey, Cred_Mapping, Dojo_User
23+
from dojo.models import Product, Finding, Test, Notes, BurpRawRequestResponse, Endpoint, Stub_Finding, Finding_Template, JIRA_PKey, Cred_Mapping, Dojo_User, JIRA_Issue
2424
from dojo.tools.factory import import_parser_factory
25-
from dojo.utils import get_page_items, add_breadcrumb, get_cal_event, message, process_notifications, get_system_setting, create_notification, Product_Tab, calculate_grade
26-
from dojo.tasks import add_issue_task
25+
from dojo.utils import get_page_items, add_breadcrumb, get_cal_event, message, process_notifications, get_system_setting, create_notification, Product_Tab, calculate_grade, log_jira_alert
26+
from dojo.tasks import add_issue_task, update_issue_task
2727

2828
logger = logging.getLogger(__name__)
2929

@@ -443,6 +443,17 @@ def finding_bulk_update(request, tid):
443443
if form.cleaned_data['severity'] or form.cleaned_data['status']:
444444
calculate_grade(test.engagement.product)
445445

446+
for finding in finds:
447+
if JIRA_PKey.objects.filter(product=finding.test.engagement.product).count() == 0:
448+
log_jira_alert('Finding cannot be pushed to jira as there is no jira configuration for this product.', finding)
449+
else:
450+
old_status = finding.status()
451+
if form.cleaned_data['push_to_jira']:
452+
if JIRA_Issue.objects.filter(finding=finding).exists():
453+
update_issue_task.delay(finding, old_status, True)
454+
else:
455+
add_issue_task.delay(finding, True)
456+
446457
messages.add_message(request,
447458
messages.SUCCESS,
448459
'Bulk edit of findings was successful. Check to make sure it is what you intended.',

dojo/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,8 +991,14 @@ def jira_long_description(find_description, find_id, jira_conf_finding_text):
991991

992992

993993
def add_issue(find, push_to_jira):
994+
logger.debug('adding issue: ' + str(find))
994995
eng = Engagement.objects.get(test=find.test)
995996
prod = Product.objects.get(engagement=eng)
997+
998+
if JIRA_PKey.objects.filter(product=prod).count() == 0:
999+
log_jira_alert('Finding cannot be pushed to jira as there is no jira configuration for this product.', find)
1000+
return
1001+
9961002
jpkey = JIRA_PKey.objects.get(product=prod)
9971003
jira_conf = jpkey.conf
9981004

@@ -1001,8 +1007,10 @@ def add_issue(find, push_to_jira):
10011007
if ((jpkey.push_all_issues and Finding.get_number_severity(
10021008
System_Settings.objects.get().jira_minimum_severity) >
10031009
Finding.get_number_severity(find.severity))):
1004-
pass
1010+
log_jira_alert('Finding below jira_minimum_severity threshold.', find)
1011+
10051012
else:
1013+
logger.debug('Trying to create a new JIRA issue')
10061014
try:
10071015
JIRAError.log_to_tempfile = False
10081016
jira = JIRA(
@@ -1055,7 +1063,7 @@ def add_issue(find, push_to_jira):
10551063
except JIRAError as e:
10561064
log_jira_alert(e.text, find)
10571065
else:
1058-
log_jira_alert("Finding not active, verified, or over threshold.",
1066+
log_jira_alert("Finding not active or not verified.",
10591067
find)
10601068

10611069

0 commit comments

Comments
 (0)