Reject reserved action names in register_model_actions()
CI / build (20.x, 3.14) (push) Failing after 18s
CI / build (20.x, 3.13) (push) Failing after 20s
CI / build (20.x, 3.12) (push) Failing after 23s

This commit is contained in:
Jason Novinger
2026-03-03 16:56:15 -06:00
parent 7ef77a0ecf
commit 2c1ee47b2e
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -6,7 +6,7 @@ from django.db.models import Model, Q
from django.utils.translation import gettext_lazy as _
from netbox.registry import registry
from users.constants import CONSTRAINT_TOKEN_USER
from users.constants import CONSTRAINT_TOKEN_USER, RESERVED_ACTIONS
__all__ = (
'ModelAction',
@@ -53,6 +53,8 @@ def register_model_actions(model: type[Model], actions: list[ModelAction | str])
for action in actions:
if isinstance(action, str):
action = ModelAction(name=action)
if action.name in RESERVED_ACTIONS:
raise ValueError(f"'{action.name}' is a reserved action and cannot be registered.")
if action not in registry['model_actions'][label]:
registry['model_actions'][label].append(action)
@@ -86,6 +86,11 @@ class RegisterModelActionsTest(TestCase):
actions = registry['model_actions']['dcim.site']
self.assertEqual(len(actions), 1)
def test_reserved_action_rejected(self):
for action_name in ('view', 'add', 'change', 'delete'):
with self.assertRaises(ValueError):
register_model_actions(Site, [ModelAction(action_name)])
class ObjectPermissionFormTest(TestCase):