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
5 changed files with 30 additions and 19 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

@@ -722,10 +722,10 @@ def register_models(*models):
for model in models:
app_label, model_name = model._meta.label_lower.split('.')
# TODO: Remove in NetBox v4.7
# Register public models (access the underlying dict directly to avoid triggering the deprecation warning)
# TODO: Remove in NetBox v4.5
# Register public models
if not getattr(model, '_netbox_private', False):
dict.__getitem__(registry, 'models')[app_label].add(model_name)
registry['models'][app_label].add(model_name)
# Register applicable feature views for the model
if issubclass(model, ContactsMixin):

View File

@@ -9,15 +9,6 @@ class Registry(dict):
removed (though the value of each key is mutable).
"""
def __getitem__(self, key):
# TODO: Remove in NetBox v4.7
if key == 'models':
import warnings
warnings.warn(
'The "models" registry key is deprecated and will be removed in NetBox v4.7. Registered models can be '
'obtained by calling ObjectType.objects.public().',
DeprecationWarning,
stacklevel=2,
)
try:
return super().__getitem__(key)
except KeyError:
@@ -38,7 +29,6 @@ registry = Registry({
'event_types': dict(),
'filtersets': dict(),
'model_features': dict(),
# TODO: Remove in NetBox v4.7
'models': collections.defaultdict(set),
'plugins': dict(),
'request_processors': list(),

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()