Add deprecation warnings

This commit is contained in:
Jeremy Stretch 2023-10-19 17:24:11 -04:00
parent 9db6921e90
commit 10324bfe6e

View File

@ -1,3 +1,5 @@
import warnings
from utilities.permissions import get_permission_for_model
__all__ = (
@ -24,12 +26,16 @@ class ActionsMixin:
# TODO: Remove backward compatibility in Netbox v4.0
# Determine how permissions are being mapped to actions for the view
if type(self.actions) is dict:
# New actions format (3.7+)
permissions_map = self.actions
elif hasattr(self, 'action_perms'):
if hasattr(self, 'action_perms'):
# Backward compatibility for <3.7
permissions_map = self.action_perms
warnings.warn(
"Setting action_perms on views is deprecated and will be removed in NetBox v4.0. Use actions instead.",
DeprecationWarning
)
elif type(self.actions) is dict:
# New actions format (3.7+)
permissions_map = self.actions
else:
# actions is still defined as a list or tuple (<3.7) but no custom mapping is defined; use the old
# default mapping
@ -39,6 +45,11 @@ class ActionsMixin:
'bulk_edit': {'change'},
'bulk_delete': {'delete'},
}
warnings.warn(
"View actions should be defined as a dictionary mapping. Support for the legacy list format will be "
"removed in NetBox v4.0.",
DeprecationWarning
)
# Resolve required permissions for each action
permitted_actions = []