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
@@ -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),
|
||||
]
|
||||
Reference in new issue
Block a user