diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1b65ece9..65036a82 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -53,6 +53,11 @@ Release notes new `data` dict. https://github.com/aboutcode-org/dejacode/issues/202 +- Add the `vulnerabilities_risk_threshold` field to the Product and + DataspaceConfiguration models. + This threshold helps prioritize and control the level of attention to vulnerabilities. + https://github.com/aboutcode-org/dejacode/issues/97 + ### Version 5.2.1 - Fix the models documentation navigation. diff --git a/dje/admin.py b/dje/admin.py index 7b5dcefc..ef7ae47c 100644 --- a/dje/admin.py +++ b/dje/admin.py @@ -1077,6 +1077,7 @@ class DataspaceConfigurationInline(DataspacedFKMixin, admin.StackedInline): "scancodeio_api_key", "vulnerablecode_url", "vulnerablecode_api_key", + "vulnerabilities_risk_threshold", "purldb_url", "purldb_api_key", ] diff --git a/dje/migrations/0005_dataspaceconfiguration_vulnerabilities_risk_threshold.py b/dje/migrations/0005_dataspaceconfiguration_vulnerabilities_risk_threshold.py new file mode 100644 index 00000000..84d78a91 --- /dev/null +++ b/dje/migrations/0005_dataspaceconfiguration_vulnerabilities_risk_threshold.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.9 on 2024-12-13 08:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dje', '0004_dataspace_vulnerabilities_updated_at'), + ] + + operations = [ + migrations.AddField( + model_name='dataspaceconfiguration', + name='vulnerabilities_risk_threshold', + field=models.DecimalField(blank=True, decimal_places=1, help_text='Enter a risk value between 0.0 and 10.0. This threshold helps prioritize and control the level of attention to vulnerabilities.', max_digits=3, null=True), + ), + ] diff --git a/dje/models.py b/dje/models.py index ff997166..45ad43bc 100644 --- a/dje/models.py +++ b/dje/models.py @@ -391,6 +391,19 @@ def get_configuration(self, field_name=None): return getattr(configuration, field_name, None) return configuration + def set_configuration(self, field_name, value): + """ + Set the `value` for `field_name` on the DataspaceConfiguration linked + with this Dataspace instance. + """ + try: + configuration = self.configuration + except ObjectDoesNotExist: + configuration = DataspaceConfiguration(dataspace=self) + + setattr(configuration, field_name, value) + configuration.save() + @property def has_configuration(self): """Return True if an associated DataspaceConfiguration instance exists.""" @@ -473,6 +486,17 @@ class DataspaceConfiguration(models.Model): ), ) + vulnerabilities_risk_threshold = models.DecimalField( + null=True, + blank=True, + max_digits=3, + decimal_places=1, + help_text=_( + "Enter a risk value between 0.0 and 10.0. This threshold helps prioritize " + "and control the level of attention to vulnerabilities." + ), + ) + purldb_url = models.URLField( _("PurlDB URL"), max_length=1024, diff --git a/dje/templates/object_details_base.html b/dje/templates/object_details_base.html index 15d37841..2510698d 100644 --- a/dje/templates/object_details_base.html +++ b/dje/templates/object_details_base.html @@ -91,7 +91,7 @@