Skip to content

Commit

Permalink
Update PluginMenuItem permissions and disable bulk import/edit
Browse files Browse the repository at this point in the history
  • Loading branch information
wkoot committed Jul 9, 2024
1 parent 86215f4 commit 30923ee
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 167 deletions.
16 changes: 8 additions & 8 deletions netbox_slm/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from .software_license import (
SoftwareLicenseForm,
SoftwareLicenseFilterForm,
SoftwareLicenseImportForm,
SoftwareLicenseBulkEditForm,
# SoftwareLicenseImportForm,
# SoftwareLicenseBulkEditForm,
)
from .software_product import (
SoftwareProductForm,
SoftwareProductFilterForm,
SoftwareProductImportForm,
SoftwareProductBulkEditForm,
# SoftwareProductImportForm,
# SoftwareProductBulkEditForm,
)
from .software_product_installation import (
SoftwareProductInstallationForm,
SoftwareProductInstallationFilterForm,
SoftwareProductInstallationImportForm,
SoftwareProductInstallationBulkEditForm,
# SoftwareProductInstallationImportForm,
# SoftwareProductInstallationBulkEditForm,
)
from .software_product_version import (
SoftwareProductVersionForm,
SoftwareProductVersionFilterForm,
SoftwareProductVersionImportForm,
SoftwareProductVersionBulkEditForm,
# SoftwareProductVersionImportForm,
# SoftwareProductVersionBulkEditForm,
)
38 changes: 19 additions & 19 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 @@ -67,23 +67,23 @@ class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm):
tag = TagFilterField(model)


class SoftwareLicenseImportForm(NetBoxModelImportForm):
class Meta:
model = SoftwareLicense
fields = (
"name",
"description",
"type",
"stored_location",
"stored_location_url",
"start_date",
"expiration_date",
)
# 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")),)
# 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")),)
42 changes: 20 additions & 22 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 @@ -34,22 +32,22 @@ class SoftwareProductFilterForm(NetBoxModelFilterSetForm):
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 = []
# 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 = []
24 changes: 12 additions & 12 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 @@ -61,14 +61,14 @@ class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm):
tag = TagFilterField(model)


class SoftwareProductInstallationImportForm(NetBoxModelImportForm):
class Meta:
model = SoftwareProductInstallation
fields = tuple()
# 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")),)
# 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")),)
34 changes: 17 additions & 17 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 @@ -44,18 +44,18 @@ class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm):
tag = TagFilterField(model)


class SoftwareProductVersionImportForm(NetBoxModelImportForm):
class Meta:
model = SoftwareProductVersion
fields = ("name",)
# 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 = []
# class SoftwareProductVersionBulkEditForm(NetBoxModelBulkEditForm):
# pk = forms.ModelMultipleChoiceField(
# queryset=SoftwareProduct.objects.all(),
# widget=forms.MultipleHiddenInput(),
# )
#
# class Meta:
# model = SoftwareProductVersion
# nullable_fields = []
52 changes: 28 additions & 24 deletions netbox_slm/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,77 @@
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"],
),
# 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"],
),
# 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"],
),
# 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"],
),
# PluginMenuButton(
# "plugins:netbox_slm:softwarelicense_import",
# "Import",
# "mdi mdi-upload",
# permissions=["netbox_slm.add_softwarelicense"],
# ),
),
),
)
38 changes: 20 additions & 18 deletions netbox_slm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# 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/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 +27,12 @@
# 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/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 +62,16 @@
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/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 +101,8 @@
# 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/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
Loading

0 comments on commit 30923ee

Please sign in to comment.