From 00d4af18fee056b6121eaa0d683e085865625945 Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Fri, 12 May 2023 20:03:37 +0000 Subject: [PATCH] Fix #18 --- Makefile | 2 +- nb_risk/models.py | 1 - nb_risk/tables.py | 22 +++++++++++++++++++--- nb_risk/version.py | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 068ccbc..a0d2303 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,6 @@ pbuild: python3 -m pip install --upgrade build python3 -m build -pypipub: +publish: python3 -m pip install --user --upgrade twine python3 -m twine upload dist/* diff --git a/nb_risk/models.py b/nb_risk/models.py index cbf96df..b11334b 100644 --- a/nb_risk/models.py +++ b/nb_risk/models.py @@ -65,7 +65,6 @@ class Vulnerability(NetBoxModel): ) cvssbaseScore = models.FloatField("Base Score", max_length=100, blank=True) - @property def affected_assets(self): return self.vulnerability_assignments.count() diff --git a/nb_risk/tables.py b/nb_risk/tables.py index 45ec468..47e89c4 100644 --- a/nb_risk/tables.py +++ b/nb_risk/tables.py @@ -1,6 +1,8 @@ import django_tables2 as tables +from django_tables2.utils import Accessor -from netbox.tables import NetBoxTable, ChoiceFieldColumn, columns +from netbox.tables import NetBoxTable, columns +from django.db.models import Count from . import models from . import columns as riskColumns @@ -35,11 +37,25 @@ class Meta(NetBoxTable.Meta): class VulnerabilityTable(NetBoxTable): name = tables.Column(linkify=True) - affected_assets = tables.Column(verbose_name="Affected Assets") + affected = columns.LinkedCountColumn( + verbose_name="Affected Assets", + accessor=Accessor("affected_assets"), + viewname='plugins:nb_risk:vulnerabilityassignment_list', + url_params={ + 'vulnerability': 'name', + }, + ) + + def order_affected(self, queryset, is_descending): + if is_descending: + queryset = queryset.annotate(affected_assets=Count('vulnerability_assignments')).order_by('-affected_assets') + else: + queryset = queryset.annotate(affected_assets=Count('vulnerability_assignments')).order_by('affected_assets') + return (queryset, True) class Meta(NetBoxTable.Meta): model = models.Vulnerability - fields = ["name", "cve", "description", "affected_assets", "cvssbaseScore"] + fields = ["name", "cve", "description", "affected", "cvssbaseScore"] # VulnerabilityAssignment Tables diff --git a/nb_risk/version.py b/nb_risk/version.py index 94e12ff..ccea7eb 100644 --- a/nb_risk/version.py +++ b/nb_risk/version.py @@ -1 +1 @@ -__version__ = "35.0.1" +__version__ = "35.0.2"