Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PluginMenuItem permissions and disable bulk import/edit #41

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netbox_slm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from netbox.plugins import PluginConfig

__version__ = "1.6.0"
__version__ = "1.7.0"


class SLMConfig(PluginConfig):
Expand Down
28 changes: 4 additions & 24 deletions netbox_slm/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 1 addition & 23 deletions netbox_slm/forms/software_license.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")),)
25 changes: 1 addition & 24 deletions netbox_slm/forms/software_product.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = []
19 changes: 3 additions & 16 deletions netbox_slm/forms/software_product_installation.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."
)
Expand All @@ -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")),)
25 changes: 4 additions & 21 deletions netbox_slm/forms/software_product_version.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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 = []
28 changes: 4 additions & 24 deletions netbox_slm/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,53 @@
PluginMenuItem(
link="plugins:netbox_slm:softwareproduct_list",
link_text="Software Products",
permissions=["netbox_slm.add_softwareproduct"],
buttons=(
PluginMenuButton(
"plugins:netbox_slm:softwareproduct_add",
"Add",
"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",
"Add",
"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",
"Add",
"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",
"Add",
"mdi mdi-plus-thick",
permissions=["netbox_slm.add_softwarelicense"],
),
PluginMenuButton(
"plugins:netbox_slm:softwarelicense_import",
"Import",
"mdi mdi-upload",
permissions=["netbox_slm.add_softwarelicense"],
),
),
),
)
18 changes: 0 additions & 18 deletions netbox_slm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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/<int:pk>/", views.SoftwareLicenseView.as_view(), name="softwarelicense"),
path("licenses/<int:pk>/delete/", views.SoftwareLicenseDeleteView.as_view(), name="softwarelicense_delete"),
Expand Down
8 changes: 0 additions & 8 deletions netbox_slm/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
SoftwareLicenseView,
SoftwareLicenseEditView,
SoftwareLicenseDeleteView,
SoftwareLicenseBulkImportView,
SoftwareLicenseBulkEditView,
SoftwareLicenseBulkDeleteView,
)
from .software_product import (
SoftwareProductListView,
SoftwareProductView,
SoftwareProductEditView,
SoftwareProductDeleteView,
SoftwareProductBulkImportView,
SoftwareProductBulkEditView,
SoftwareProductBulkDeleteView,
)
from .software_product_installation import (
SoftwareProductInstallationListView,
SoftwareProductInstallationView,
SoftwareProductInstallationEditView,
SoftwareProductInstallationDeleteView,
SoftwareProductInstallationBulkImportView,
SoftwareProductInstallationBulkEditView,
SoftwareProductInstallationBulkDeleteView,
)
from .software_product_version import (
SoftwareProductVersionListView,
SoftwareProductVersionView,
SoftwareProductVersionEditView,
SoftwareProductVersionDeleteView,
SoftwareProductVersionBulkImportView,
SoftwareProductVersionBulkEditView,
SoftwareProductVersionBulkDeleteView,
)
13 changes: 0 additions & 13 deletions netbox_slm/views/software_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 0 additions & 14 deletions netbox_slm/views/software_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Loading