From f7b899e1bbd49c553336dc53c8185f12a145cadf Mon Sep 17 00:00:00 2001 From: Madelon Dohmen <99282220+madelondohmen@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:47:47 +0200 Subject: [PATCH] Update a Boefje (#3521) Signed-off-by: Donny Peeters Co-authored-by: Donny Peeters Co-authored-by: Donny Peeters <46660228+Donnype@users.noreply.github.com> Co-authored-by: Jan Klopper --- boefjes/tests/integration/test_api.py | 1 + .../integration/test_sql_repositories.py | 8 + rocky/katalogus/client.py | 12 ++ rocky/katalogus/templates/boefje_setup.html | 17 +- .../templates/plugin_container_image.html | 13 ++ rocky/katalogus/urls.py | 7 +- rocky/katalogus/views/boefje_setup.py | 183 +++++++++++++----- rocky/katalogus/views/plugin_detail.py | 6 + rocky/rocky/locale/django.pot | 51 ++++- .../katalogus/test_katalogus_boefje_setup.py | 64 ++++++ .../katalogus/test_katalogus_create_boefje.py | 21 -- rocky/tools/forms/boefje.py | 8 +- rocky/tools/forms/settings.py | 10 +- 13 files changed, 315 insertions(+), 86 deletions(-) create mode 100644 rocky/tests/katalogus/test_katalogus_boefje_setup.py delete mode 100644 rocky/tests/katalogus/test_katalogus_create_boefje.py diff --git a/boefjes/tests/integration/test_api.py b/boefjes/tests/integration/test_api.py index 67cd3b95700..59f50b0a61c 100644 --- a/boefjes/tests/integration/test_api.py +++ b/boefjes/tests/integration/test_api.py @@ -151,6 +151,7 @@ def test_update_plugins(test_client, organisation): response = test_client.get(f"/v1/organisations/{organisation.id}/plugins/{boefje.id}") assert response.json()["description"] == "4" + assert response.json()["scan_level"] == 3 assert response.json()["enabled"] is True assert response.json()["scan_level"] == 3 assert response.json()["interval"] == 20 diff --git a/boefjes/tests/integration/test_sql_repositories.py b/boefjes/tests/integration/test_sql_repositories.py index db69569da51..0bd76c21995 100644 --- a/boefjes/tests/integration/test_sql_repositories.py +++ b/boefjes/tests/integration/test_sql_repositories.py @@ -161,9 +161,17 @@ def test_bare_boefje_storage(plugin_storage): boefje.description = "4" boefje.scan_level = 3 + assert storage.boefje_by_id(boefje.id).description == "4" boefje.description = "4" + with plugin_storage as storage: + storage.update_boefje(boefje.id, {"scan_level": 3}) + + assert storage.boefje_by_id(boefje.id).scan_level == 3 + + boefje.description = "4" + boefje.scan_level = 3 all_plugins = storage.get_all() assert all_plugins == [boefje] diff --git a/rocky/katalogus/client.py b/rocky/katalogus/client.py index 846e0739658..9cd9fa62b74 100644 --- a/rocky/katalogus/client.py +++ b/rocky/katalogus/client.py @@ -221,6 +221,18 @@ def create_plugin(self, plugin: Plugin) -> None: else: logger.info("Plugin %s could not be created", plugin.name) + def edit_plugin(self, plugin: Plugin) -> None: + response = self.session.patch( + f"{self.organization_uri}/boefjes/{plugin.id}", + content=plugin.model_dump_json(exclude_none=True), + ) + response.raise_for_status() + + if response.status_code == codes.CREATED: + logger.info("Plugin %s", plugin.name) + else: + logger.info("Plugin %s could not be created", plugin.name) + def parse_boefje(boefje: dict) -> Boefje: scan_level = SCAN_LEVEL(boefje["scan_level"]) diff --git a/rocky/katalogus/templates/boefje_setup.html b/rocky/katalogus/templates/boefje_setup.html index ecf96d52b47..48c2d75c0fe 100644 --- a/rocky/katalogus/templates/boefje_setup.html +++ b/rocky/katalogus/templates/boefje_setup.html @@ -11,6 +11,8 @@
{% if boefje_variant %}

{% translate "Boefje variant setup" %}

+ {% elif edit_boefje_name %} +

{% translate "Edit" %} "{{ edit_boefje_name }}"

{% else %}

{% translate "Boefje setup" %}

{% endif %} @@ -25,8 +27,19 @@

{% translate "Boefje setup" %}

{% include "partials/form/fieldset.html" with legend=fieldset_legend fields=form %}
- - + {% if edit_boefje_name %} + + {% translate "Discard changes" %} + {% elif boefje_variant %} + + {% translate "Discard variant" %} + {% else %} + + {% translate "Discard new Boefje" %} + {% endif %}
diff --git a/rocky/katalogus/templates/plugin_container_image.html b/rocky/katalogus/templates/plugin_container_image.html index b823ef14e3c..17ddba9b025 100644 --- a/rocky/katalogus/templates/plugin_container_image.html +++ b/rocky/katalogus/templates/plugin_container_image.html @@ -1,4 +1,5 @@ {% load static %} +{% load humanize %} {% load i18n %}
@@ -44,6 +45,7 @@

{% translate "Variants" %}

{% translate "Name" %} {% translate "Scan level" %} {% translate "Status" %} + {% translate "Age" %} @@ -70,6 +72,9 @@

{% translate "Variants" %}

{% translate "Disabled" %} {% endif %} + + {{ variant.created|naturaltime }} +