Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Jira Form: Make express the default #11041

Merged
merged 4 commits into from
Oct 11, 2024
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
7 changes: 5 additions & 2 deletions dojo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2425,7 +2425,7 @@ def clean(self):
return self.cleaned_data


class JIRAForm(BaseJiraForm):
class AdvancedJIRAForm(BaseJiraForm):
issue_template_dir = forms.ChoiceField(required=False,
choices=JIRA_TEMPLATE_CHOICES,
help_text="Choose the folder containing the Django templates used to render the JIRA issue description. These are stored in dojo/templates/issue-trackers. Leave empty to use the default jira_full templates.")
Expand All @@ -2445,8 +2445,11 @@ class Meta:
exclude = [""]


class ExpressJIRAForm(BaseJiraForm):
class JIRAForm(BaseJiraForm):
issue_key = forms.CharField(required=True, help_text="A valid issue ID is required to gather the necessary information.")
issue_template_dir = forms.ChoiceField(required=False,
choices=JIRA_TEMPLATE_CHOICES,
help_text="Choose the folder containing the Django templates used to render the JIRA issue description. These are stored in dojo/templates/issue-trackers. Leave empty to use the default jira_full templates.")

class Meta:
model = JIRA_Instance
Expand Down
3 changes: 2 additions & 1 deletion dojo/jira_link/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
re_path(r"^jira/webhook/(?P<secret>[\w-]+)$", views.webhook, name="jira_web_hook_secret"),
re_path(r"^jira/webhook/", views.webhook, name="jira_web_hook"),
re_path(r"^jira/add", views.NewJiraView.as_view(), name="add_jira"),
re_path(r"^jira/advanced", views.AdvancedJiraView.as_view(), name="add_jira_advanced"),
re_path(r"^jira/(?P<jid>\d+)/edit$", views.EditJiraView.as_view(), name="edit_jira"),
re_path(r"^jira/(?P<tid>\d+)/delete$", views.DeleteJiraView.as_view(), name="delete_jira"),
re_path(r"^jira$", views.ListJiraView.as_view(), name="jira"),
re_path(r"^jira/express", views.ExpressJiraView.as_view(), name="express_jira")]
]
24 changes: 12 additions & 12 deletions dojo/jira_link/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from dojo.authorization.authorization import user_has_configuration_permission

# Local application/library imports
from dojo.forms import DeleteJIRAInstanceForm, ExpressJIRAForm, JIRAForm
from dojo.forms import AdvancedJIRAForm, DeleteJIRAInstanceForm, JIRAForm
from dojo.models import JIRA_Instance, JIRA_Issue, Notes, System_Settings, User
from dojo.notifications.helper import create_notification
from dojo.utils import add_breadcrumb, add_error_message_to_response, get_setting
Expand Down Expand Up @@ -285,24 +285,24 @@ def get_custom_field(jira, label):
return field


class ExpressJiraView(View):
class NewJiraView(View):
def get_template(self):
return "dojo/express_new_jira.html"
return "dojo/new_jira.html"

def get_fallback_template(self):
return "dojo/new_jira.html"
return "dojo/new_jira_advanced.html"

def get_form_class(self):
return ExpressJIRAForm
return JIRAForm

def get_fallback_form_class(self):
return JIRAForm
return AdvancedJIRAForm

def get(self, request):
if not user_has_configuration_permission(request.user, "dojo.add_jira_instance"):
raise PermissionDenied
jform = self.get_form_class()()
add_breadcrumb(title="New Jira Configuration (Express)", top_level=False, request=request)
add_breadcrumb(title="New Jira Configuration", top_level=False, request=request)
return render(request, self.get_template(), {"jform": jform})

def post(self, request):
Expand Down Expand Up @@ -391,18 +391,18 @@ def post(self, request):
return render(request, self.get_template(), {"jform": jform})


class NewJiraView(View):
class AdvancedJiraView(View):
def get_template(self):
return "dojo/new_jira.html"
return "dojo/new_jira_advanced.html"

def get_form_class(self):
return JIRAForm
return AdvancedJIRAForm

def get(self, request):
if not user_has_configuration_permission(request.user, "dojo.add_jira_instance"):
raise PermissionDenied
jform = self.get_form_class()()
add_breadcrumb(title="New Jira Configuration", top_level=False, request=request)
add_breadcrumb(title="New Jira Configuration (Advanced)", top_level=False, request=request)
return render(request, self.get_template(), {"jform": jform})

def post(self, request):
Expand Down Expand Up @@ -442,7 +442,7 @@ def get_template(self):
return "dojo/edit_jira.html"

def get_form_class(self):
return JIRAForm
return AdvancedJIRAForm

def get(self, request, jid=None):
if not user_has_configuration_permission(request.user, "dojo.change_jira_instance"):
Expand Down
16 changes: 0 additions & 16 deletions dojo/templates/dojo/express_new_jira.html

This file was deleted.

8 changes: 4 additions & 4 deletions dojo/templates/dojo/jira.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ <h3 class="has-filters">
<ul class="dropdown-menu dropdown-menu-right" role="menu"
aria-labelledby="dropdownMenu1">
<li role="presentation">
<a href="{% url 'express_jira' %}">
<i class="fa-solid fa-plus"></i> Add Jira Instance (Express)
<a href="{% url 'add_jira' %}">
<i class="fa-solid fa-plus"></i> Add Jira Instance
</a>
</li>
<li role="presentation">
<a href="{% url 'add_jira' %}">
<i class="fa-solid fa-plus"></i> Add Jira Instance
<a href="{% url 'add_jira_advanced' %}">
<i class="fa-solid fa-plus"></i> Add Jira Instance (Advanced)
</a>
</li>
</ul>
Expand Down
7 changes: 5 additions & 2 deletions dojo/templates/dojo/new_jira.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ <h3> Add a JIRA Configuration </h3>
{% include "dojo/form_fields.html" with form=jform %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input class="btn btn-primary" type="submit" value="Submit"/>
<input class="btn btn-primary" title="Submit" type="submit" value="Submit"/>
</div>
<div class="col-sm-offset-2 col-sm-10"><br>
<i>Finding severity mappings and other options can be edited after configuration is complete.</i>
</div>
</div>
</form>
{% endblock %}
{% endblock %}
13 changes: 13 additions & 0 deletions dojo/templates/dojo/new_jira_advanced.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "base.html"%}
{% block content %}
{{ block.super }}
<h3> Add a JIRA Configuration (Advanced) </h3>
<form class="form-horizontal" action="{% url 'add_jira_advanced' %}" method="post">{% csrf_token %}
{% include "dojo/form_fields.html" with form=jform %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input class="btn btn-primary" type="submit" value="Submit"/>
</div>
</div>
</form>
{% endblock %}
2 changes: 1 addition & 1 deletion unittests/test_jira_config_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUp(self):

@patch("dojo.jira_link.views.jira_helper.get_jira_connection_raw")
def add_jira_instance(self, data, jira_mock):
response = self.client.post(reverse("add_jira"), urlencode(data), content_type="application/x-www-form-urlencoded")
response = self.client.post(reverse("add_jira_advanced"), urlencode(data), content_type="application/x-www-form-urlencoded")
# check that storing a new config triggers a login call to JIRA
call_1 = call(data["url"], data["username"], data["password"])
call_2 = call(data["url"], data["username"], data["password"])
Expand Down
Loading