From 08eb53fd65d1f0807304142c0bfb1093a3493e56 Mon Sep 17 00:00:00 2001 From: tdruez Date: Thu, 25 Jul 2024 14:40:17 +0400 Subject: [PATCH] Display webhook subscription in Project settings view #1325 Signed-off-by: tdruez --- .../includes/project_settings_menu.html | 5 +++ .../templates/scanpipe/project_settings.html | 40 +++++++++++++++++++ scanpipe/views.py | 5 +++ 3 files changed, 50 insertions(+) diff --git a/scanpipe/templates/scanpipe/includes/project_settings_menu.html b/scanpipe/templates/scanpipe/includes/project_settings_menu.html index 2ac35631f..ac07326b3 100644 --- a/scanpipe/templates/scanpipe/includes/project_settings_menu.html +++ b/scanpipe/templates/scanpipe/includes/project_settings_menu.html @@ -5,6 +5,11 @@ General +
  • + + Webhooks + +
  • Ignored diff --git a/scanpipe/templates/scanpipe/project_settings.html b/scanpipe/templates/scanpipe/project_settings.html index df6fa8635..d2ec52f58 100644 --- a/scanpipe/templates/scanpipe/project_settings.html +++ b/scanpipe/templates/scanpipe/project_settings.html @@ -50,6 +50,46 @@ +
    +

    Webhooks

    +
    + + + + + + + + + + + {% for webhook in webhook_subscriptions %} + + + + + + + {% empty %} + + + + {% endfor %} + +
    URLActiveInclude summaryInclude results
    + {{ webhook.target_url|truncatechars:30 }} + + + + + + +
    + No Webhooks defined. +
    +
    +
    +

    Ignored

    diff --git a/scanpipe/views.py b/scanpipe/views.py index 0ce24de35..e092079d3 100644 --- a/scanpipe/views.py +++ b/scanpipe/views.py @@ -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() @@ -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