1
- import warnings
2
-
3
1
from netbox .constants import DEFAULT_ACTION_PERMISSIONS
4
2
from utilities .permissions import get_permission_for_model
5
3
@@ -26,38 +24,11 @@ def get_permitted_actions(self, user, model=None):
26
24
"""
27
25
model = model or self .queryset .model
28
26
29
- # TODO: Remove backward compatibility in Netbox v4.0
30
- # Determine how permissions are being mapped to actions for the view
31
- if hasattr (self , 'action_perms' ):
32
- # Backward compatibility for <3.7
33
- permissions_map = self .action_perms
34
- warnings .warn (
35
- "Setting action_perms on views is deprecated and will be removed in NetBox v4.0. Use actions instead." ,
36
- DeprecationWarning
37
- )
38
- elif type (self .actions ) is dict :
39
- # New actions format (3.7+)
40
- permissions_map = self .actions
41
- else :
42
- # actions is still defined as a list or tuple (<3.7) but no custom mapping is defined; use the old
43
- # default mapping
44
- permissions_map = {
45
- 'add' : {'add' },
46
- 'import' : {'add' },
47
- 'bulk_edit' : {'change' },
48
- 'bulk_delete' : {'delete' },
49
- }
50
- warnings .warn (
51
- "View actions should be defined as a dictionary mapping. Support for the legacy list format will be "
52
- "removed in NetBox v4.0." ,
53
- DeprecationWarning
54
- )
55
-
56
27
# Resolve required permissions for each action
57
28
permitted_actions = []
58
29
for action in self .actions :
59
30
required_permissions = [
60
- get_permission_for_model (model , name ) for name in permissions_map .get (action , set ())
31
+ get_permission_for_model (model , name ) for name in self . actions .get (action , set ())
61
32
]
62
33
if not required_permissions or user .has_perms (required_permissions ):
63
34
permitted_actions .append (action )
0 commit comments