|
|
@@ -1,7 +1,6 @@
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
|
|
from extras.models import TableConfig
|
|
|
-from netbox import object_actions
|
|
|
from utilities.permissions import get_permission_for_model
|
|
|
|
|
|
__all__ = (
|
|
|
@@ -9,18 +8,6 @@ __all__ = (
|
|
|
'TableMixin',
|
|
|
)
|
|
|
|
|
|
-# TODO: Remove in NetBox v4.7
|
|
|
-LEGACY_ACTIONS = {
|
|
|
- 'add': object_actions.AddObject,
|
|
|
- 'edit': object_actions.EditObject,
|
|
|
- 'delete': object_actions.DeleteObject,
|
|
|
- 'export': object_actions.BulkExport,
|
|
|
- 'bulk_import': object_actions.BulkImport,
|
|
|
- 'bulk_edit': object_actions.BulkEdit,
|
|
|
- 'bulk_rename': object_actions.BulkRename,
|
|
|
- 'bulk_delete': object_actions.BulkDelete,
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
class ActionsMixin:
|
|
|
"""
|
|
|
@@ -33,41 +20,12 @@ class ActionsMixin:
|
|
|
"""
|
|
|
actions = tuple()
|
|
|
|
|
|
- # TODO: Remove in NetBox v4.7
|
|
|
- def _convert_legacy_actions(self):
|
|
|
- """
|
|
|
- Convert a legacy dictionary mapping action name to required permissions to a list of ObjectAction subclasses.
|
|
|
- """
|
|
|
- if type(self.actions) is not dict:
|
|
|
- return
|
|
|
-
|
|
|
- import warnings
|
|
|
- warnings.warn(
|
|
|
- f"{self.__class__.__name__}.actions is defined as a dictionary, which is deprecated and will be removed "
|
|
|
- "in NetBox v4.7. Define actions as a list of ObjectAction subclasses instead.",
|
|
|
- DeprecationWarning,
|
|
|
- stacklevel=2,
|
|
|
- )
|
|
|
-
|
|
|
- actions = []
|
|
|
- for name in self.actions.keys():
|
|
|
- try:
|
|
|
- actions.append(LEGACY_ACTIONS[name])
|
|
|
- except KeyError:
|
|
|
- raise ValueError(f"Unsupported legacy action: {name}")
|
|
|
-
|
|
|
- self.actions = actions
|
|
|
-
|
|
|
def get_permitted_actions(self, user, model=None):
|
|
|
"""
|
|
|
Return a tuple of actions for which the given user is permitted to do.
|
|
|
"""
|
|
|
model = model or self.queryset.model
|
|
|
|
|
|
- # TODO: Remove in NetBox v4.7
|
|
|
- # Handle legacy action sets
|
|
|
- self._convert_legacy_actions()
|
|
|
-
|
|
|
# Resolve required permissions for each action
|
|
|
permitted_actions = []
|
|
|
for action in self.actions:
|