Просмотр исходного кода

Validate action name is not empty and clarify RESERVED_ACTIONS origin

Jason Novinger 2 дней назад
Родитель
Сommit
6ac5afc0e9
2 измененных файлов с 5 добавлено и 2 удалено
  1. 3 2
      netbox/users/constants.py
  2. 2 0
      netbox/utilities/permissions.py

+ 3 - 2
netbox/users/constants.py

@@ -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

+ 2 - 0
netbox/utilities/permissions.py

@@ -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]: