mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-02 15:37:18 +02:00
Validate action name is not empty and clarify RESERVED_ACTIONS origin
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user