Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dojo/engagement/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
name="close_engagement"),
re_path(r"^engagement/(?P<eid>\d+)/reopen$", views.reopen_eng,
name="reopen_engagement"),
re_path(r"^engagement/(?P<eid>\d+)/jira/unlink$", views.unlink_jira,
name="engagement_unlink_jira"),
re_path(r"^engagement/(?P<eid>\d+)/complete_checklist$",
views.complete_checklist, name="complete_checklist"),
re_path(r"^engagement/(?P<eid>\d+)/risk_acceptance/add$",
Expand Down
37 changes: 36 additions & 1 deletion dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
from django.db.models import OuterRef, Q, Value
from django.db.models.functions import Coalesce
from django.db.models.query import Prefetch, QuerySet
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, QueryDict, StreamingHttpResponse
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, JsonResponse, QueryDict, StreamingHttpResponse
from django.shortcuts import get_object_or_404, render
from django.urls import Resolver404, reverse
from django.utils import timezone
from django.utils.translation import gettext as _
from django.views import View
from django.views.decorators.cache import cache_page
from django.views.decorators.http import require_POST
from django.views.decorators.vary import vary_on_cookie
from openpyxl import Workbook
from openpyxl.styles import Font
Expand Down Expand Up @@ -1134,6 +1135,40 @@ def close_eng(request, eid):
return HttpResponseRedirect(reverse("view_engagements", args=(eng.product.id, )))


@user_is_authorized(Engagement, Permissions.Engagement_Edit, "eid")
@require_POST
def unlink_jira(request, eid):
eng = get_object_or_404(Engagement, id=eid)
logger.info("trying to unlink a linked jira epic from engagement %d:%s", eng.id, eng.name)
if eng.has_jira_issue:
try:
jira_helper.unlink_jira(request, eng)
messages.add_message(
request,
messages.SUCCESS,
"Link to JIRA epic successfully deleted",
extra_tags="alert-success",
)
return JsonResponse({"result": "OK"})
except Exception:
logger.exception("Link to JIRA epic could not be deleted")
messages.add_message(
request,
messages.ERROR,
"Link to JIRA epic could not be deleted, see alerts for details",
extra_tags="alert-danger",
)
return HttpResponse(status=500)
else:
messages.add_message(
request,
messages.ERROR,
"Link to JIRA epic not found",
extra_tags="alert-danger",
)
return HttpResponse(status=400)


@user_is_authorized(Engagement, Permissions.Engagement_Edit, "eid")
def reopen_eng(request, eid):
eng = Engagement.objects.get(id=eid)
Expand Down
39 changes: 33 additions & 6 deletions dojo/templates/dojo/view_eng.html
Original file line number Diff line number Diff line change
Expand Up @@ -826,13 +826,18 @@ <h3 class="panel-title"><span class="fa-solid fa-circle-info fa-fw" aria-hidden=
</td>
</tr>
{% if jissue and jira_project %}
<tr>
<td><strong>Jira</strong></td>
<td><a href="{{ eng | jira_issue_url }}" target="_blank"><i class="fa-solid fa-arrow-up-right-from-square"></i> {{ eng | jira_key }}
<tr>
<td><strong>Jira</strong></td>
<td>
<a href="{{ eng | jira_issue_url }}" target="_blank"><i class="fa-solid fa-arrow-up-right-from-square"></i> {{ eng | jira_key }}
<small>(epic)</small>
</a>
</td>
</tr>
</a>
{% if eng|has_object_permission:"Engagement_Edit" %}
&nbsp;
<i id="unlink_eng_jira" class="fa-solid fa-trash" title="Unlink JIRA epic from this engagement."></i>
{% endif %}
</td>
</tr>
{% elif jira_project %}
<tr>
<td><strong>JIRA</strong></td>
Expand Down Expand Up @@ -1088,6 +1093,28 @@ <h4><span class="fa-solid fa-key" aria-hidden="true"></span>
var host = slashes.concat(window.location.host);
modal.find('p#questionnaireURL').text('Questionnaire URL: ' + host + path)
})

function jira_action(elem, url) {
$(elem).removeClass().addClass('fa-solid fa-spin fa-spinner')

$.ajax({
type: "post",
dataType:'json',
data: '',
context: this,
url: url,
beforeSend: function (jqXHR, settings) {
jqXHR.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
},
complete: function(e) {
location.reload()
}
});
}

$("#unlink_eng_jira").on('click', function(e) {
jira_action(this,'{% url 'engagement_unlink_jira' eng.id %}')
});
});

{% include 'dojo/snippets/risk_acceptance_actions_snippet_js.html' %}
Expand Down