From 10c31658775314aefa22f0b1a9b05a512168186b Mon Sep 17 00:00:00 2001 From: wkoot <3715211+wkoot@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:33:28 +0200 Subject: [PATCH] Update PluginMenuItem permissions and remove bulk import/edit --- netbox_slm/__init__.py | 2 +- netbox_slm/forms/__init__.py | 28 +++---------------- netbox_slm/forms/software_license.py | 24 +--------------- netbox_slm/forms/software_product.py | 25 +---------------- .../forms/software_product_installation.py | 19 ++----------- netbox_slm/forms/software_product_version.py | 25 +++-------------- netbox_slm/navigation.py | 28 +++---------------- netbox_slm/urls.py | 18 ------------ netbox_slm/views/__init__.py | 8 ------ netbox_slm/views/software_license.py | 13 --------- netbox_slm/views/software_product.py | 14 ---------- .../views/software_product_installation.py | 13 --------- netbox_slm/views/software_product_version.py | 13 --------- 13 files changed, 18 insertions(+), 212 deletions(-) diff --git a/netbox_slm/__init__.py b/netbox_slm/__init__.py index fc15c18..215d6c2 100644 --- a/netbox_slm/__init__.py +++ b/netbox_slm/__init__.py @@ -1,6 +1,6 @@ from netbox.plugins import PluginConfig -__version__ = "1.6.0" +__version__ = "1.7.0" class SLMConfig(PluginConfig): diff --git a/netbox_slm/forms/__init__.py b/netbox_slm/forms/__init__.py index 7ce40a8..f8d7033 100644 --- a/netbox_slm/forms/__init__.py +++ b/netbox_slm/forms/__init__.py @@ -1,24 +1,4 @@ -from .software_license import ( - SoftwareLicenseForm, - SoftwareLicenseFilterForm, - SoftwareLicenseImportForm, - SoftwareLicenseBulkEditForm, -) -from .software_product import ( - SoftwareProductForm, - SoftwareProductFilterForm, - SoftwareProductImportForm, - SoftwareProductBulkEditForm, -) -from .software_product_installation import ( - SoftwareProductInstallationForm, - SoftwareProductInstallationFilterForm, - SoftwareProductInstallationImportForm, - SoftwareProductInstallationBulkEditForm, -) -from .software_product_version import ( - SoftwareProductVersionForm, - SoftwareProductVersionFilterForm, - SoftwareProductVersionImportForm, - SoftwareProductVersionBulkEditForm, -) +from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm +from .software_product import SoftwareProductForm, SoftwareProductFilterForm +from .software_product_installation import SoftwareProductInstallationForm, SoftwareProductInstallationFilterForm +from .software_product_version import SoftwareProductVersionForm, SoftwareProductVersionFilterForm diff --git a/netbox_slm/forms/software_license.py b/netbox_slm/forms/software_license.py index 1f50082..c0dbc67 100644 --- a/netbox_slm/forms/software_license.py +++ b/netbox_slm/forms/software_license.py @@ -1,7 +1,7 @@ from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField from utilities.forms.rendering import FieldSet @@ -65,25 +65,3 @@ class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm): model = SoftwareLicense fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) - - -class SoftwareLicenseImportForm(NetBoxModelImportForm): - class Meta: - model = SoftwareLicense - fields = ( - "name", - "description", - "type", - "stored_location", - "stored_location_url", - "start_date", - "expiration_date", - ) - - -class SoftwareLicenseBulkEditForm(NetBoxModelBulkEditForm): - software_product = DynamicModelChoiceField(queryset=SoftwareProduct.objects.all(), required=False) - version = DynamicModelChoiceField(queryset=SoftwareProductVersion.objects.all(), required=False) - installation = DynamicModelChoiceField(queryset=SoftwareProductInstallation.objects.all(), required=False) - model = SoftwareLicense - fieldsets = (FieldSet(None, ("software_product", "version", "installation")),) diff --git a/netbox_slm/forms/software_product.py b/netbox_slm/forms/software_product.py index 7a7afe1..5e920d5 100644 --- a/netbox_slm/forms/software_product.py +++ b/netbox_slm/forms/software_product.py @@ -1,7 +1,5 @@ -from django import forms - from dcim.models import Manufacturer -from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm from netbox_slm.models import SoftwareProduct from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -32,24 +30,3 @@ class SoftwareProductFilterForm(NetBoxModelFilterSetForm): model = SoftwareProduct fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) - - -class SoftwareProductImportForm(NetBoxModelImportForm): - class Meta: - model = SoftwareProduct - fields = ( - "name", - "description", - "manufacturer", - ) - - -class SoftwareProductBulkEditForm(NetBoxModelBulkEditForm): - pk = forms.ModelMultipleChoiceField( - queryset=SoftwareProduct.objects.all(), - widget=forms.MultipleHiddenInput(), - ) - - class Meta: - model = SoftwareProduct - nullable_fields = [] diff --git a/netbox_slm/forms/software_product_installation.py b/netbox_slm/forms/software_product_installation.py index 9643041..f3d036e 100644 --- a/netbox_slm/forms/software_product_installation.py +++ b/netbox_slm/forms/software_product_installation.py @@ -1,8 +1,8 @@ -from django import forms +from django.forms import ValidationError from django.urls import reverse_lazy from dcim.models import Device -from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -48,7 +48,7 @@ def clean_version(self): version = self.cleaned_data["version"] software_product = self.cleaned_data["software_product"] if version not in software_product.softwareproductversion_set.all(): - raise forms.ValidationError( + raise ValidationError( f"Version '{version}' doesn't exist on {software_product}, make sure you've " f"selected a compatible version or first select the software product." ) @@ -59,16 +59,3 @@ class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductInstallation fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) - - -class SoftwareProductInstallationImportForm(NetBoxModelImportForm): - class Meta: - model = SoftwareProductInstallation - fields = tuple() - - -class SoftwareProductInstallationBulkEditForm(NetBoxModelBulkEditForm): - software_product = DynamicModelChoiceField(queryset=SoftwareProduct.objects.all(), required=False) - version = DynamicModelChoiceField(queryset=SoftwareProductVersion.objects.all(), required=False) - model = SoftwareProductInstallation - fieldsets = (FieldSet(None, ("software_product", "version")),) diff --git a/netbox_slm/forms/software_product_version.py b/netbox_slm/forms/software_product_version.py index e385b11..fd2c74f 100644 --- a/netbox_slm/forms/software_product_version.py +++ b/netbox_slm/forms/software_product_version.py @@ -1,7 +1,7 @@ -from django import forms +from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -13,8 +13,8 @@ class SoftwareProductVersionForm(NetBoxModelForm): comments = CommentField() - release_date = forms.DateField(required=False, widget=DatePicker()) - end_of_support = forms.DateField(required=False, widget=DatePicker()) + release_date = DateField(required=False, widget=DatePicker()) + end_of_support = DateField(required=False, widget=DatePicker()) software_product = DynamicModelChoiceField( queryset=SoftwareProduct.objects.all(), @@ -42,20 +42,3 @@ class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductVersion fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) - - -class SoftwareProductVersionImportForm(NetBoxModelImportForm): - class Meta: - model = SoftwareProductVersion - fields = ("name",) - - -class SoftwareProductVersionBulkEditForm(NetBoxModelBulkEditForm): - pk = forms.ModelMultipleChoiceField( - queryset=SoftwareProduct.objects.all(), - widget=forms.MultipleHiddenInput(), - ) - - class Meta: - model = SoftwareProductVersion - nullable_fields = [] diff --git a/netbox_slm/navigation.py b/netbox_slm/navigation.py index 07ccccc..ae53bec 100644 --- a/netbox_slm/navigation.py +++ b/netbox_slm/navigation.py @@ -4,6 +4,7 @@ PluginMenuItem( link="plugins:netbox_slm:softwareproduct_list", link_text="Software Products", + permissions=["netbox_slm.add_softwareproduct"], buttons=( PluginMenuButton( "plugins:netbox_slm:softwareproduct_add", @@ -11,17 +12,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproduct"], ), - PluginMenuButton( - "plugins:netbox_slm:softwareproduct_import", - "Import", - "mdi mdi-upload", - permissions=["netbox_slm.add_softwareproduct"], - ), ), ), PluginMenuItem( link="plugins:netbox_slm:softwareproductversion_list", link_text="Versions", + permissions=["netbox_slm.add_softwareproductversion"], buttons=( PluginMenuButton( "plugins:netbox_slm:softwareproductversion_add", @@ -29,17 +25,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductversion"], ), - PluginMenuButton( - "plugins:netbox_slm:softwareproductversion_import", - "Import", - "mdi mdi-upload", - permissions=["netbox_slm.add_softwareproductversion"], - ), ), ), PluginMenuItem( link="plugins:netbox_slm:softwareproductinstallation_list", link_text="Installations", + permissions=["netbox_slm.add_softwareproductinstallation"], buttons=( PluginMenuButton( "plugins:netbox_slm:softwareproductinstallation_add", @@ -47,17 +38,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductinstallation"], ), - PluginMenuButton( - "plugins:netbox_slm:softwareproductinstallation_import", - "Import", - "mdi mdi-upload", - permissions=["netbox_slm.add_softwareproductinstallation"], - ), ), ), PluginMenuItem( link="plugins:netbox_slm:softwarelicense_list", link_text="Licenses", + permissions=["netbox_slm.add_softwarelicense"], buttons=( PluginMenuButton( "plugins:netbox_slm:softwarelicense_add", @@ -65,12 +51,6 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwarelicense"], ), - PluginMenuButton( - "plugins:netbox_slm:softwarelicense_import", - "Import", - "mdi mdi-upload", - permissions=["netbox_slm.add_softwarelicense"], - ), ), ), ) diff --git a/netbox_slm/urls.py b/netbox_slm/urls.py index 43ba8b0..4856d47 100644 --- a/netbox_slm/urls.py +++ b/netbox_slm/urls.py @@ -8,8 +8,6 @@ # SoftwareProduct path("software-products/", views.SoftwareProductListView.as_view(), name="softwareproduct_list"), path("software-products/add/", views.SoftwareProductEditView.as_view(), name="softwareproduct_add"), - path("software-products/import/", views.SoftwareProductBulkImportView.as_view(), name="softwareproduct_import"), - path("software-products/edit/", views.SoftwareProductBulkEditView.as_view(), name="softwareproduct_bulk_edit"), path( "software-products/delete/", views.SoftwareProductBulkDeleteView.as_view(), name="softwareproduct_bulk_delete" ), @@ -27,10 +25,6 @@ # SoftwareProductVersion path("versions/", views.SoftwareProductVersionListView.as_view(), name="softwareproductversion_list"), path("versions/add/", views.SoftwareProductVersionEditView.as_view(), name="softwareproductversion_add"), - path( - "versions/import/", views.SoftwareProductVersionBulkImportView.as_view(), name="softwareproductversion_import" - ), - path("versions/edit/", views.SoftwareProductVersionBulkEditView.as_view(), name="softwareproductversion_bulk_edit"), path( "versions/delete/", views.SoftwareProductVersionBulkDeleteView.as_view(), @@ -60,16 +54,6 @@ views.SoftwareProductInstallationEditView.as_view(), name="softwareproductinstallation_add", ), - path( - "installations/import/", - views.SoftwareProductInstallationBulkImportView.as_view(), - name="softwareproductinstallation_import", - ), - path( - "installations/edit/", - views.SoftwareProductInstallationBulkEditView.as_view(), - name="softwareproductinstallation_bulk_edit", - ), path( "installations/delete/", views.SoftwareProductInstallationBulkDeleteView.as_view(), @@ -99,8 +83,6 @@ # SoftwareLicense path("licenses/", views.SoftwareLicenseListView.as_view(), name="softwarelicense_list"), path("licenses/add/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_add"), - path("licenses/import/", views.SoftwareLicenseBulkImportView.as_view(), name="softwarelicense_import"), - path("licenses/edit/", views.SoftwareLicenseBulkEditView.as_view(), name="softwarelicense_bulk_edit"), path("licenses/delete/", views.SoftwareLicenseBulkDeleteView.as_view(), name="softwarelicense_bulk_delete"), path("licenses//", views.SoftwareLicenseView.as_view(), name="softwarelicense"), path("licenses//delete/", views.SoftwareLicenseDeleteView.as_view(), name="softwarelicense_delete"), diff --git a/netbox_slm/views/__init__.py b/netbox_slm/views/__init__.py index 4a76efa..6a54180 100644 --- a/netbox_slm/views/__init__.py +++ b/netbox_slm/views/__init__.py @@ -3,8 +3,6 @@ SoftwareLicenseView, SoftwareLicenseEditView, SoftwareLicenseDeleteView, - SoftwareLicenseBulkImportView, - SoftwareLicenseBulkEditView, SoftwareLicenseBulkDeleteView, ) from .software_product import ( @@ -12,8 +10,6 @@ SoftwareProductView, SoftwareProductEditView, SoftwareProductDeleteView, - SoftwareProductBulkImportView, - SoftwareProductBulkEditView, SoftwareProductBulkDeleteView, ) from .software_product_installation import ( @@ -21,8 +17,6 @@ SoftwareProductInstallationView, SoftwareProductInstallationEditView, SoftwareProductInstallationDeleteView, - SoftwareProductInstallationBulkImportView, - SoftwareProductInstallationBulkEditView, SoftwareProductInstallationBulkDeleteView, ) from .software_product_version import ( @@ -30,7 +24,5 @@ SoftwareProductVersionView, SoftwareProductVersionEditView, SoftwareProductVersionDeleteView, - SoftwareProductVersionBulkImportView, - SoftwareProductVersionBulkEditView, SoftwareProductVersionBulkDeleteView, ) diff --git a/netbox_slm/views/software_license.py b/netbox_slm/views/software_license.py index b74a4ac..b57e754 100644 --- a/netbox_slm/views/software_license.py +++ b/netbox_slm/views/software_license.py @@ -31,19 +31,6 @@ class SoftwareLicenseDeleteView(generic.ObjectDeleteView): queryset = SoftwareLicense.objects.all() -class SoftwareLicenseBulkImportView(generic.BulkImportView): - queryset = SoftwareLicense.objects.all() - model_form = forms.SoftwareLicenseImportForm - table = tables.SoftwareLicenseTable - - -class SoftwareLicenseBulkEditView(generic.BulkEditView): - queryset = SoftwareLicense.objects.all() - filterset = filtersets.SoftwareLicenseFilterSet - table = tables.SoftwareLicenseTable - form = forms.SoftwareLicenseBulkEditForm - - class SoftwareLicenseBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareLicense.objects.all() table = tables.SoftwareLicenseTable diff --git a/netbox_slm/views/software_product.py b/netbox_slm/views/software_product.py index 6b4954d..2d8e6a8 100644 --- a/netbox_slm/views/software_product.py +++ b/netbox_slm/views/software_product.py @@ -35,20 +35,6 @@ class SoftwareProductDeleteView(generic.ObjectDeleteView): queryset = SoftwareProduct.objects.all() -class SoftwareProductBulkImportView(generic.BulkImportView): - queryset = SoftwareProduct.objects.all() - model_form = forms.SoftwareProductImportForm - table = tables.SoftwareProductTable - - -class SoftwareProductBulkEditView(generic.BulkEditView): - queryset = SoftwareProduct.objects.all() - filterset = filtersets.SoftwareProductFilterSet - filterset_form = forms.SoftwareProductFilterForm - table = tables.SoftwareProductTable - form = forms.SoftwareProductBulkEditForm - - class SoftwareProductBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProduct.objects.all() table = tables.SoftwareProductTable diff --git a/netbox_slm/views/software_product_installation.py b/netbox_slm/views/software_product_installation.py index 673e77e..f0cf444 100644 --- a/netbox_slm/views/software_product_installation.py +++ b/netbox_slm/views/software_product_installation.py @@ -31,19 +31,6 @@ class SoftwareProductInstallationDeleteView(generic.ObjectDeleteView): queryset = SoftwareProductInstallation.objects.all() -class SoftwareProductInstallationBulkImportView(generic.BulkImportView): - queryset = SoftwareProductInstallation.objects.all() - model_form = forms.SoftwareProductInstallationImportForm - table = tables.SoftwareProductInstallationTable - - -class SoftwareProductInstallationBulkEditView(generic.BulkEditView): - queryset = SoftwareProductInstallation.objects.all() - filterset = filtersets.SoftwareProductInstallationFilterSet - table = tables.SoftwareProductInstallationTable - form = forms.SoftwareProductInstallationBulkEditForm - - class SoftwareProductInstallationBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProductInstallation.objects.all() table = tables.SoftwareProductInstallationTable diff --git a/netbox_slm/views/software_product_version.py b/netbox_slm/views/software_product_version.py index 4f02bad..7f89fca 100644 --- a/netbox_slm/views/software_product_version.py +++ b/netbox_slm/views/software_product_version.py @@ -35,19 +35,6 @@ class SoftwareProductVersionDeleteView(generic.ObjectDeleteView): queryset = SoftwareProductVersion.objects.all() -class SoftwareProductVersionBulkImportView(generic.BulkImportView): - queryset = SoftwareProductVersion.objects.all() - model_form = forms.SoftwareProductVersionImportForm - table = tables.SoftwareProductVersionTable - - -class SoftwareProductVersionBulkEditView(generic.BulkEditView): - queryset = SoftwareProductVersion.objects.all() - filterset = filtersets.SoftwareProductVersionFilterSet - table = tables.SoftwareProductVersionTable - form = forms.SoftwareProductVersionBulkEditForm - - class SoftwareProductVersionBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProductVersion.objects.all() table = tables.SoftwareProductVersionTable