Skip to content

Commit

Permalink
Display webhook subscription in Project settings view #1325
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 25, 2024
1 parent b6ecf4b commit 08eb53f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<i class="fa-solid fa-gear mr-2"></i>General
</a>
</li>
<li>
<a href="#webhooks">
<i class="fa-solid fa-paper-plane mr-2"></i>Webhooks
</a>
</li>
<li>
<a href="#ignored">
<i class="fa-solid fa-forward mr-2"></i>Ignored
Expand Down
40 changes: 40 additions & 0 deletions scanpipe/templates/scanpipe/project_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@
</div>
</div>

<div class="panel">
<p id="webhooks" class="panel-heading py-2 is-size-6">Webhooks</p>
<div class="panel-block is-block px-4">
<table class="table">
<thead>
<tr>
<th>URL</th>
<th>Active</th>
<th>Include summary</th>
<th>Include results</th>
</tr>
</thead>
<tbody>
{% for webhook in webhook_subscriptions %}
<tr>
<td class="pr-5">
{{ webhook.target_url|truncatechars:30 }}
</td>
<td>
<i class="fa-solid {% if webhook.is_active %}fa-check{% else %}fa-xmark{% endif %}"></i>
</td>
<td>
<i class="fa-solid {% if webhook.include_summary %}fa-check{% else %}fa-xmark{% endif %}"></i>
</td>
<td>
<i class="fa-solid {% if webhook.include_results %}fa-check{% else %}fa-xmark{% endif %}"></i>
</td>
</tr>
{% empty %}
<tr>
<td colspan="42" class="p-3">
No Webhooks defined.
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

<div class="panel">
<p id="ignored" class="panel-heading py-2 is-size-6">Ignored</p>
<div class="panel-block is-block px-4">
Expand Down
5 changes: 5 additions & 0 deletions scanpipe/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ class ProjectSettingsView(ConditionalLoginRequired, UpdateView):
form_class = ProjectSettingsForm
success_message = 'The project "{}" settings have been updated.'

def get_queryset(self):
return super().get_queryset().prefetch_related("webhooksubscriptions")

def form_valid(self, form):
response = super().form_valid(form)
project = self.get_object()
Expand All @@ -816,7 +819,9 @@ def get(self, request, *args, **kwargs):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
project = self.get_object()
context["archive_form"] = ArchiveProjectForm()
context["webhook_subscriptions"] = project.webhooksubscriptions.all()
return context

@staticmethod
Expand Down

0 comments on commit 08eb53f

Please sign in to comment.