Skip to content

Commit 17e72d3

Browse files
committed
Complete the Add webhook view end to end #1423
Signed-off-by: tdruez <[email protected]>
1 parent 2e22dca commit 17e72d3

12 files changed

+307
-247
lines changed

scanpipe/forms.py

+8
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,11 @@ class Meta:
716716
"include_results",
717717
"is_active",
718718
]
719+
720+
def __init__(self, *args, **kwargs):
721+
super().__init__(*args, **kwargs)
722+
target_url_field = self.fields["target_url"]
723+
target_url_field.widget.attrs["class"] = "input"
724+
725+
def save(self, project):
726+
return project.add_webhook_subscription(**self.cleaned_data)

scanpipe/templates/scanpipe/includes/project_clone_form.html renamed to scanpipe/templates/scanpipe/forms/project_clone_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% include 'scanpipe/includes/form_errors.html' %}
1+
{% include 'scanpipe/forms/form_errors.html' %}
22
<div class="field">
33
<label class="label" for="{{ form.clone_name.id_for_label }}">{{ form.clone_name.label }}</label>
44
<div class="control">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
<form method="post" action="{% url 'project_settings' project.slug %}">{% csrf_token %}
2+
<div class="panel">
3+
<p id="general" class="panel-heading py-2 is-size-6">General</p>
4+
<div class="panel-block is-block px-4">
5+
<div class="field">
6+
<label class="label" for="{{ form.name.id_for_label }}">
7+
Project name
8+
</label>
9+
<div class="control">
10+
{{ form.name }}
11+
</div>
12+
</div>
13+
<div class="field">
14+
<label class="label" for="{{ form.name.id_for_label }}">
15+
PURL
16+
</label>
17+
<div class="control">
18+
{{ form.purl }}
19+
</div>
20+
<p class="help">{{ form.purl.help_text|urlize }}</p>
21+
</div>
22+
<div class="field">
23+
<label class="label" for="{{ form.notes.id_for_label }}">
24+
{{ form.notes.label }}
25+
</label>
26+
<div class="control">
27+
{{ form.notes }}
28+
</div>
29+
<p class="help">{{ form.notes.help_text }}</p>
30+
</div>
31+
<div class="field">
32+
<label class="label" for="id_uuid">UUID</label>
33+
<div class="control">
34+
<input type="text" id="id_uuid" class="input" value="{{ project.uuid }}" disabled="disabled">
35+
</div>
36+
</div>
37+
<div class="field">
38+
<label class="label" for="id_work_directory">Work directory</label>
39+
<div class="control">
40+
<input type="text" id="id_work_directory" class="input" value="{{ project.work_directory }}" disabled="disabled">
41+
</div>
42+
</div>
43+
</div>
44+
</div>
45+
46+
<div class="panel">
47+
<p id="webhooks" class="panel-heading py-2 is-size-6">Webhooks</p>
48+
<div class="panel-block is-block px-4">
49+
<table class="table mb-1">
50+
<thead>
51+
<tr>
52+
<th>URL</th>
53+
<th>Active</th>
54+
<th>Include summary</th>
55+
<th>Include results</th>
56+
<th>Trigger on each run</th>
57+
</tr>
58+
</thead>
59+
<tbody>
60+
{% for webhook in webhook_subscriptions %}
61+
<tr>
62+
<td class="pr-5">
63+
{{ webhook.target_url|truncatechars:30 }}
64+
</td>
65+
<td>
66+
<i class="fa-solid {% if webhook.is_active %}fa-check{% else %}fa-xmark{% endif %}"></i>
67+
</td>
68+
<td>
69+
<i class="fa-solid {% if webhook.include_summary %}fa-check{% else %}fa-xmark{% endif %}"></i>
70+
</td>
71+
<td>
72+
<i class="fa-solid {% if webhook.include_results %}fa-check{% else %}fa-xmark{% endif %}"></i>
73+
</td>
74+
<td>
75+
<i class="fa-solid {% if webhook.trigger_on_each_run %}fa-check{% else %}fa-xmark{% endif %}"></i>
76+
</td>
77+
</tr>
78+
{% empty %}
79+
<tr>
80+
<td colspan="42" class="p-3">
81+
No Webhooks defined.
82+
</td>
83+
</tr>
84+
{% endfor %}
85+
</tbody>
86+
</table>
87+
<a href="#" class="button is-smaller is-link modal-button mb-1" data-target="modal-add-webhook" aria-haspopup="true">
88+
Add Webhook
89+
</a>
90+
</div>
91+
</div>
92+
93+
<div class="panel">
94+
<p id="ignored" class="panel-heading py-2 is-size-6">Ignored</p>
95+
<div class="panel-block is-block px-4">
96+
<div class="field">
97+
<label class="label" for="{{ form.ignored_patterns.id_for_label }}">
98+
{{ form.ignored_patterns.label }}
99+
</label>
100+
<div class="control">
101+
{{ form.ignored_patterns }}
102+
</div>
103+
<div class="help">
104+
{{ form.ignored_patterns.help_text|safe|linebreaksbr }}
105+
</div>
106+
</div>
107+
108+
<div class="field">
109+
<label class="label" for="{{ form.scan_max_file_size.id_for_label }}">
110+
{{ form.scan_max_file_size.label }}
111+
</label>
112+
<div class="control">
113+
{{ form.scan_max_file_size }}
114+
</div>
115+
<div class="help">
116+
{{ form.scan_max_file_size.help_text|safe|linebreaksbr }}
117+
</div>
118+
</div>
119+
120+
<div class="field">
121+
<label class="label" for="{{ form.ignored_dependency_scopes.id_for_label }}">
122+
{{ form.ignored_dependency_scopes.label }}
123+
</label>
124+
<div class="control">
125+
{{ form.ignored_dependency_scopes }}
126+
</div>
127+
<div class="help">
128+
{{ form.ignored_dependency_scopes.help_text|safe|linebreaksbr }}
129+
</div>
130+
</div>
131+
132+
<div class="field">
133+
<label class="label" for="{{ form.ignored_vulnerabilities.id_for_label }}">
134+
{{ form.ignored_vulnerabilities.label }}
135+
</label>
136+
<div class="control">
137+
{{ form.ignored_vulnerabilities }}
138+
</div>
139+
<div class="help">
140+
{{ form.ignored_vulnerabilities.help_text|safe|linebreaksbr }}
141+
</div>
142+
</div>
143+
</div>
144+
</div>
145+
146+
<div class="panel">
147+
<p id="policies" class="panel-heading py-2 is-size-6">Policies</p>
148+
<div class="panel-block is-block px-4">
149+
<div>
150+
{% if project.policies_enabled %}
151+
<i class="fa-solid fa-check"></i>
152+
Policies are <strong>enabled</strong> for this project.
153+
{% else %}
154+
<i class="fa-solid fa-xmark"></i>
155+
Policies are <strong>not enabled</strong> for this project.
156+
{% endif %}
157+
</div>
158+
<div class="field mt-2">
159+
<label class="label" for="{{ form.policies.id_for_label }}">
160+
{{ form.policies.label }}
161+
</label>
162+
<div class="control">
163+
{{ form.policies }}
164+
</div>
165+
<p class="help">{{ form.policies.help_text|urlize }}</p>
166+
</div>
167+
</div>
168+
</div>
169+
170+
<div class="panel">
171+
<p id="dejacode" class="panel-heading py-2 is-size-6">DejaCode</p>
172+
<div class="panel-block is-block px-4">
173+
<div class="field">
174+
<label class="label" for="{{ form.product_name.id_for_label }}">
175+
Product name
176+
</label>
177+
<div class="control">
178+
{{ form.product_name }}
179+
</div>
180+
<p class="help">{{ form.product_name.help_text }}</p>
181+
</div>
182+
<div class="field">
183+
<label class="label" for="{{ form.product_version.id_for_label }}">
184+
Product version
185+
</label>
186+
<div class="control">
187+
{{ form.product_version }}
188+
</div>
189+
<p class="help">{{ form.product_version.help_text }}</p>
190+
</div>
191+
</div>
192+
</div>
193+
194+
<div class="panel">
195+
<p id="attribution" class="panel-heading py-2 is-size-6">Attribution</p>
196+
<div class="panel-block is-block px-4">
197+
<div class="field">
198+
<label class="label" for="{{ form.attribution_template.id_for_label }}">
199+
{{ form.attribution_template.label }}
200+
</label>
201+
<div class="control">
202+
{{ form.attribution_template }}
203+
</div>
204+
<p class="help">
205+
{{ form.attribution_template.help_text|urlize|linebreaksbr }}
206+
</p>
207+
</div>
208+
</div>
209+
</div>
210+
211+
<div class="columns mt-4 mb-5 is-variable is-1">
212+
<div class="column is-one-third">
213+
<a href="{% url 'project_detail' project.slug %}" class="button is-fullwidth">Cancel</a>
214+
</div>
215+
<div class="column">
216+
<input type="submit" class="button is-fullwidth is-link" value="Update">
217+
</div>
218+
</div>
219+
{{ form.media }}
220+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% include 'scanpipe/forms/form_errors.html' %}
2+
<div class="field">
3+
<label class="label" for="{{ form.target_url.id_for_label }}">
4+
{{ form.target_url.label }}
5+
</label>
6+
<div class="control">
7+
{{ form.target_url }}
8+
<p class="help">{{ form.target_url.help_text }}</p>
9+
</div>
10+
</div>
11+
<div class="field">
12+
<label class="checkbox" for="{{ form.trigger_on_each_run.id_for_label }}">
13+
{{ form.trigger_on_each_run }}
14+
{{ form.trigger_on_each_run.label }}
15+
</label>
16+
<p class="help">{{ form.trigger_on_each_run.help_text }}</p>
17+
</div>
18+
<div class="field">
19+
<label class="checkbox" for="{{ form.include_summary.id_for_label }}">
20+
{{ form.include_summary }}
21+
{{ form.include_summary.label }}
22+
</label>
23+
<p class="help">{{ form.include_summary.help_text }}</p>
24+
</div>
25+
<div class="field">
26+
<label class="checkbox" for="{{ form.include_results.id_for_label }}">
27+
{{ form.include_results }}
28+
{{ form.include_results.label }}
29+
</label>
30+
<p class="help">{{ form.include_results.help_text }}</p>
31+
</div>
32+
<hr>
33+
<div class="field">
34+
<label class="checkbox" for="{{ form.is_active.id_for_label }}">
35+
{{ form.is_active }}
36+
{{ form.is_active.label }}
37+
</label>
38+
<p class="help">{{ form.is_active.help_text }}</p>
39+
</div>

scanpipe/templates/scanpipe/includes/filters_breadcrumb.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
</div>
1414
{% if filterset.errors %}
1515
<div class="mb-2">
16-
{% include 'scanpipe/includes/form_errors.html' with form=filterset %}
16+
{% include 'scanpipe/forms/form_errors.html' with form=filterset %}
1717
</div>
1818
{% endif %}

scanpipe/templates/scanpipe/includes/run_step_selection_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Warning: Step Selection is an advanced feature.<br>
44
Removing steps may compromise data integrity. Use with caution.
55
</div>
6-
{% include 'scanpipe/includes/form_errors.html' %}
6+
{% include 'scanpipe/forms/form_errors.html' %}
77
<form hx-post="{% url 'project_run_step_selection' run.uuid %}"
88
hx-target="#run-step-selection-box"
99
hx-swap="outerHTML"

scanpipe/templates/scanpipe/modals/clone_modal.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</header>
88
<form hx-post="{% url 'project_clone' project.slug %}" hx-target="#clone-modal-form-body" hx-on::after-settle="removeOverlay()">{% csrf_token %}
99
<section id="clone-modal-form-body" class="modal-card-body">
10-
{% include 'scanpipe/includes/project_clone_form.html' with form=project_clone_form %}
10+
{% include 'scanpipe/forms/project_clone_form.html' with form=project_clone_form %}
1111
</section>
1212
<footer class="modal-card-foot is-flex is-justify-content-space-between">
1313
<button class="button" type="reset">Cancel</button>

scanpipe/templates/scanpipe/modals/project_add_webhook_modal.html

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
{% load humanize %}
21
<div class="modal" id="modal-add-webhook">
32
<div class="modal-background"></div>
43
<div class="modal-card">
54
<header class="modal-card-head">
65
<p class="modal-card-title">Add webhook</p>
76
<button class="delete" aria-label="close"></button>
87
</header>
9-
<form action="{% url 'project_settings_add_webhook' project.slug %}" method="post" id="add-webhook-form">{% csrf_token %}
10-
<section class="modal-card-body">
11-
{{ webhook_form }}
8+
<form hx-post="{% url 'project_settings_add_webhook' project.slug %}" hx-target="#webhook-modal-form-body" hx-on::after-settle="removeOverlay()">{% csrf_token %}
9+
<section id="webhook-modal-form-body" class="modal-card-body">
10+
{% include 'scanpipe/forms/project_webhook_form.html' with form=webhook_form %}
1211
</section>
1312
<footer class="modal-card-foot is-flex is-justify-content-space-between">
14-
<button class="button has-text-weight-semibold" type="reset">No, Cancel</button>
15-
<button class="button is-link" type="submit">Add webhook</button>
13+
<button class="button" type="reset">Cancel</button>
14+
<button class="button is-no-close is-link" type="submit">Add webhook</button>
1615
</footer>
1716
</form>
1817
</div>

scanpipe/templates/scanpipe/project_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h2 class="subtitle mb-0 mb-4">
99
Create a <strong>Project</strong>
1010
</h2>
1111

12-
{% include 'scanpipe/includes/form_errors.html' %}
12+
{% include 'scanpipe/forms/form_errors.html' %}
1313

1414
<div class="columns">
1515
<div class="column is-7 pr-5 pb-0">

0 commit comments

Comments
 (0)