Compare commits

...

3 Commits

Author SHA1 Message Date
Jeremy Stretch
cb5ade07f0 Closes #21887: Deprecate support for legacy view actions (#21889) 2026-04-11 00:55:27 +02:00
Jeremy Stretch
71d918636c Remove cancelled TODO 2026-04-10 17:10:11 -04:00
Jeremy Stretch
82cf60091a Closes #21884: Deprecate the DEFAULT_ACTION_PERMISSIONS constant 2026-04-10 17:08:35 -04:00
3 changed files with 27 additions and 6 deletions

View File

@@ -51,7 +51,6 @@ class ObjectTypeManager(models.Manager):
"""
return self.get(app_label=app_label, model=model)
# TODO: Remove in NetBox v4.5
def get_for_id(self, id):
"""
Retrieve an ObjectType by its primary key (numeric ID).

View File

@@ -44,9 +44,9 @@ ADVISORY_LOCK_KEYS = {
'job-schedules': 110100,
}
# TODO: Remove in NetBox v4.5
# TODO: Remove in NetBox v4.7
# Legacy default view action permission mapping
DEFAULT_ACTION_PERMISSIONS = {
_DEFAULT_ACTION_PERMISSIONS = {
'add': {'add'},
'export': {'view'},
'bulk_import': {'add'},
@@ -54,6 +54,20 @@ DEFAULT_ACTION_PERMISSIONS = {
'bulk_delete': {'delete'},
}
def __getattr__(name):
if name == 'DEFAULT_ACTION_PERMISSIONS':
import warnings
warnings.warn(
f"{name} is deprecated and will be removed in NetBox v4.7. "
"Define action permissions via ObjectAction subclasses instead.",
DeprecationWarning,
stacklevel=2,
)
return _DEFAULT_ACTION_PERMISSIONS
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
# General-purpose tokens
CENSOR_TOKEN = '********'
CENSOR_TOKEN_CHANGED = '***CHANGED***'

View File

@@ -9,7 +9,7 @@ __all__ = (
'TableMixin',
)
# TODO: Remove in NetBox v4.5
# TODO: Remove in NetBox v4.7
LEGACY_ACTIONS = {
'add': object_actions.AddObject,
'edit': object_actions.EditObject,
@@ -33,7 +33,7 @@ class ActionsMixin:
"""
actions = tuple()
# TODO: Remove in NetBox v4.5
# 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.
@@ -41,6 +41,14 @@ class ActionsMixin:
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:
@@ -56,7 +64,7 @@ class ActionsMixin:
"""
model = model or self.queryset.model
# TODO: Remove in NetBox v4.5
# TODO: Remove in NetBox v4.7
# Handle legacy action sets
self._convert_legacy_actions()