Validate action name is not empty and clarify RESERVED_ACTIONS origin

This commit is contained in:
Jason Novinger
2026-03-30 12:32:57 -05:00
parent cf6599d9f8
commit 6ac5afc0e9
2 changed files with 5 additions and 2 deletions

View File

@@ -10,8 +10,9 @@ OBJECTPERMISSION_OBJECT_TYPES = (
CONSTRAINT_TOKEN_USER = '$user'
# Built-in actions that receive special handling (dedicated checkboxes, model properties)
# and should not be registered as custom model actions.
# Django's four default model permissions. These receive special handling
# (dedicated checkboxes, model properties) and should not be registered
# as custom model actions.
RESERVED_ACTIONS = ('view', 'add', 'change', 'delete')
# API tokens

View File

@@ -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 not action.name:
raise ValueError("Action name must not be empty.")
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]: