fix: shorten email permission codenames to fit NetBox action limit
NetBox ObjectPermission actions are limited to 30 characters, so assigning manage_softwarelicense_email_notifications or manage_certificate_email_notifications to a group failed validation. Rename them to manage_license_emails and manage_certificate_emails and migrate existing auth permissions in place to keep assignments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5dedfc9206
commit
30d748969f
6 files changed
+56
-8
No files matched your search
@@ -149,8 +149,8 @@ on the license, the plugin also sends an e-mail to the address stored in the
|
|||||||
user account; NetBox SMTP must be configured for this.
|
user account; NetBox SMTP must be configured for this.
|
||||||
|
|
||||||
Enabling e-mail delivery can only be changed by administrators or users with
|
Enabling e-mail delivery can only be changed by administrators or users with
|
||||||
the permission `netbox_slm.manage_softwarelicense_email_notifications`
|
the permission `netbox_slm.manage_license_emails`
|
||||||
(licenses) or `netbox_slm.manage_certificate_email_notifications`
|
(licenses) or `netbox_slm.manage_certificate_emails`
|
||||||
(certificates). SMTP
|
(certificates). SMTP
|
||||||
credentials are maintained only in the NetBox server configuration and are not
|
credentials are maintained only in the NetBox server configuration and are not
|
||||||
visible in the plugin.
|
visible in the plugin.
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class SoftwareLicenseSerializer(NetBoxModelSerializer):
|
|||||||
if (
|
if (
|
||||||
"email_notifications" in attrs
|
"email_notifications" in attrs
|
||||||
and request is not None
|
and request is not None
|
||||||
and not request.user.has_perm("netbox_slm.manage_softwarelicense_email_notifications")
|
and not request.user.has_perm("netbox_slm.manage_license_emails")
|
||||||
):
|
):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"email_notifications": _("You do not have permission to change email notifications.")}
|
{"email_notifications": _("You do not have permission to change email notifications.")}
|
||||||
@@ -248,7 +248,7 @@ class CertificateSerializer(NetBoxModelSerializer):
|
|||||||
if (
|
if (
|
||||||
"email_notifications" in attrs
|
"email_notifications" in attrs
|
||||||
and request is not None
|
and request is not None
|
||||||
and not request.user.has_perm("netbox_slm.manage_certificate_email_notifications")
|
and not request.user.has_perm("netbox_slm.manage_certificate_emails")
|
||||||
):
|
):
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError(
|
||||||
{"email_notifications": _("You do not have permission to change email notifications.")}
|
{"email_notifications": _("You do not have permission to change email notifications.")}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
# NetBox ObjectPermission actions are limited to 30 characters.
|
||||||
|
RENAMES = [
|
||||||
|
("softwarelicense", "manage_softwarelicense_email_notifications", "manage_license_emails"),
|
||||||
|
("certificate", "manage_certificate_email_notifications", "manage_certificate_emails"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def rename_permissions(apps, schema_editor, reverse=False):
|
||||||
|
Permission = apps.get_model("auth", "Permission")
|
||||||
|
for model, old, new in RENAMES:
|
||||||
|
if reverse:
|
||||||
|
old, new = new, old
|
||||||
|
Permission.objects.filter(content_type__app_label="netbox_slm", content_type__model=model, codename=old).update(
|
||||||
|
codename=new
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def reverse_rename_permissions(apps, schema_editor):
|
||||||
|
rename_permissions(apps, schema_editor, reverse=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("auth", "0001_initial"),
|
||||||
|
("netbox_slm", "0016_certificate"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="softwarelicense",
|
||||||
|
options={
|
||||||
|
"permissions": [("manage_license_emails", "Can manage license email notifications")],
|
||||||
|
"verbose_name": "software license",
|
||||||
|
"verbose_name_plural": "software licenses",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="certificate",
|
||||||
|
options={
|
||||||
|
"permissions": [("manage_certificate_emails", "Can manage certificate email notifications")],
|
||||||
|
"verbose_name": "certificate",
|
||||||
|
"verbose_name_plural": "certificates",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.RunPython(rename_permissions, reverse_rename_permissions),
|
||||||
|
]
|
||||||
@@ -327,7 +327,7 @@ class SoftwareLicense(NetBoxModel, ExpirationNotificationModel):
|
|||||||
verbose_name = _("software license")
|
verbose_name = _("software license")
|
||||||
verbose_name_plural = _("software licenses")
|
verbose_name_plural = _("software licenses")
|
||||||
permissions = [
|
permissions = [
|
||||||
("manage_softwarelicense_email_notifications", _("Can manage license email notifications")),
|
("manage_license_emails", _("Can manage license email notifications")),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -459,7 +459,7 @@ class Certificate(NetBoxModel, ExpirationNotificationModel):
|
|||||||
verbose_name = _("certificate")
|
verbose_name = _("certificate")
|
||||||
verbose_name_plural = _("certificates")
|
verbose_name_plural = _("certificates")
|
||||||
permissions = [
|
permissions = [
|
||||||
("manage_certificate_email_notifications", _("Can manage certificate email notifications")),
|
("manage_certificate_emails", _("Can manage certificate email notifications")),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from utilities.views import register_model_view
|
|||||||
|
|
||||||
|
|
||||||
class CertificateEmailNotificationPermissionMixin(EmailNotificationPermissionMixin):
|
class CertificateEmailNotificationPermissionMixin(EmailNotificationPermissionMixin):
|
||||||
email_permission = "netbox_slm.manage_certificate_email_notifications"
|
email_permission = "netbox_slm.manage_certificate_emails"
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(Certificate, "list", path="", detail=False)
|
@register_model_view(Certificate, "list", path="", detail=False)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from utilities.views import register_model_view
|
|||||||
class EmailNotificationPermissionMixin:
|
class EmailNotificationPermissionMixin:
|
||||||
"""Prevent users without the dedicated permission from changing SMTP delivery."""
|
"""Prevent users without the dedicated permission from changing SMTP delivery."""
|
||||||
|
|
||||||
email_permission = "netbox_slm.manage_softwarelicense_email_notifications"
|
email_permission = "netbox_slm.manage_license_emails"
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
form_attribute = "model_form" if hasattr(self, "model_form") else "form"
|
form_attribute = "model_form" if hasattr(self, "model_form") else "form"
|
||||||
|
|||||||
Reference in new issue
Block a user