Skip to content

Commit c8c4750

Browse files
engagement: allow unlinking of JIRA epic (#13333)
1 parent fbbc7a0 commit c8c4750

3 files changed

Lines changed: 71 additions & 7 deletions

File tree

dojo/engagement/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
name="close_engagement"),
3131
re_path(r"^engagement/(?P<eid>\d+)/reopen$", views.reopen_eng,
3232
name="reopen_engagement"),
33+
re_path(r"^engagement/(?P<eid>\d+)/jira/unlink$", views.unlink_jira,
34+
name="engagement_unlink_jira"),
3335
re_path(r"^engagement/(?P<eid>\d+)/complete_checklist$",
3436
views.complete_checklist, name="complete_checklist"),
3537
re_path(r"^engagement/(?P<eid>\d+)/risk_acceptance/add$",

dojo/engagement/views.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
from django.db.models import OuterRef, Q, Value
2020
from django.db.models.functions import Coalesce
2121
from django.db.models.query import Prefetch, QuerySet
22-
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, QueryDict, StreamingHttpResponse
22+
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, JsonResponse, QueryDict, StreamingHttpResponse
2323
from django.shortcuts import get_object_or_404, render
2424
from django.urls import Resolver404, reverse
2525
from django.utils import timezone
2626
from django.utils.translation import gettext as _
2727
from django.views import View
2828
from django.views.decorators.cache import cache_page
29+
from django.views.decorators.http import require_POST
2930
from django.views.decorators.vary import vary_on_cookie
3031
from openpyxl import Workbook
3132
from openpyxl.styles import Font
@@ -1134,6 +1135,40 @@ def close_eng(request, eid):
11341135
return HttpResponseRedirect(reverse("view_engagements", args=(eng.product.id, )))
11351136

11361137

1138+
@user_is_authorized(Engagement, Permissions.Engagement_Edit, "eid")
1139+
@require_POST
1140+
def unlink_jira(request, eid):
1141+
eng = get_object_or_404(Engagement, id=eid)
1142+
logger.info("trying to unlink a linked jira epic from engagement %d:%s", eng.id, eng.name)
1143+
if eng.has_jira_issue:
1144+
try:
1145+
jira_helper.unlink_jira(request, eng)
1146+
messages.add_message(
1147+
request,
1148+
messages.SUCCESS,
1149+
"Link to JIRA epic successfully deleted",
1150+
extra_tags="alert-success",
1151+
)
1152+
return JsonResponse({"result": "OK"})
1153+
except Exception:
1154+
logger.exception("Link to JIRA epic could not be deleted")
1155+
messages.add_message(
1156+
request,
1157+
messages.ERROR,
1158+
"Link to JIRA epic could not be deleted, see alerts for details",
1159+
extra_tags="alert-danger",
1160+
)
1161+
return HttpResponse(status=500)
1162+
else:
1163+
messages.add_message(
1164+
request,
1165+
messages.ERROR,
1166+
"Link to JIRA epic not found",
1167+
extra_tags="alert-danger",
1168+
)
1169+
return HttpResponse(status=400)
1170+
1171+
11371172
@user_is_authorized(Engagement, Permissions.Engagement_Edit, "eid")
11381173
def reopen_eng(request, eid):
11391174
eng = Engagement.objects.get(id=eid)

dojo/templates/dojo/view_eng.html

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -826,13 +826,18 @@ <h3 class="panel-title"><span class="fa-solid fa-circle-info fa-fw" aria-hidden=
826826
</td>
827827
</tr>
828828
{% if jissue and jira_project %}
829-
<tr>
830-
<td><strong>Jira</strong></td>
831-
<td><a href="{{ eng | jira_issue_url }}" target="_blank"><i class="fa-solid fa-arrow-up-right-from-square"></i> {{ eng | jira_key }}
829+
<tr>
830+
<td><strong>Jira</strong></td>
831+
<td>
832+
<a href="{{ eng | jira_issue_url }}" target="_blank"><i class="fa-solid fa-arrow-up-right-from-square"></i> {{ eng | jira_key }}
832833
<small>(epic)</small>
833-
</a>
834-
</td>
835-
</tr>
834+
</a>
835+
{% if eng|has_object_permission:"Engagement_Edit" %}
836+
&nbsp;
837+
<i id="unlink_eng_jira" class="fa-solid fa-trash" title="Unlink JIRA epic from this engagement."></i>
838+
{% endif %}
839+
</td>
840+
</tr>
836841
{% elif jira_project %}
837842
<tr>
838843
<td><strong>JIRA</strong></td>
@@ -1088,6 +1093,28 @@ <h4><span class="fa-solid fa-key" aria-hidden="true"></span>
10881093
var host = slashes.concat(window.location.host);
10891094
modal.find('p#questionnaireURL').text('Questionnaire URL: ' + host + path)
10901095
})
1096+
1097+
function jira_action(elem, url) {
1098+
$(elem).removeClass().addClass('fa-solid fa-spin fa-spinner')
1099+
1100+
$.ajax({
1101+
type: "post",
1102+
dataType:'json',
1103+
data: '',
1104+
context: this,
1105+
url: url,
1106+
beforeSend: function (jqXHR, settings) {
1107+
jqXHR.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
1108+
},
1109+
complete: function(e) {
1110+
location.reload()
1111+
}
1112+
});
1113+
}
1114+
1115+
$("#unlink_eng_jira").on('click', function(e) {
1116+
jira_action(this,'{% url 'engagement_unlink_jira' eng.id %}')
1117+
});
10911118
});
10921119

10931120
{% include 'dojo/snippets/risk_acceptance_actions_snippet_js.html' %}

0 commit comments

Comments
 (0)