Kaynağa Gözat

Clean up resolution of HTTP verbs to permission actions

Jeremy Stretch 5 yıl önce
ebeveyn
işleme
84d4b2db77
1 değiştirilmiş dosya ile 11 ekleme ve 11 silme
  1. 11 11
      netbox/utilities/api.py

+ 11 - 11
netbox/utilities/api.py

@@ -17,6 +17,16 @@ from rest_framework.viewsets import ModelViewSet as _ModelViewSet
 
 from .utils import dict_to_filter_params, dynamic_import
 
+HTTP_ACTIONS = {
+    'GET': 'view',
+    'OPTIONS': None,
+    'HEAD': 'view',
+    'POST': 'add',
+    'PUT': 'change',
+    'PATCH': 'change',
+    'DELETE': 'delete',
+}
+
 
 class ServiceUnavailable(APIException):
     status_code = 503
@@ -321,18 +331,8 @@ class ModelViewSet(_ModelViewSet):
         if not request.user.is_authenticated:
             return
 
-        # TODO: Reconcile this with TokenPermissions.perms_map
-        action = {
-            'GET': 'view',
-            'OPTIONS': None,
-            'HEAD': 'view',
-            'POST': 'add',
-            'PUT': 'change',
-            'PATCH': 'change',
-            'DELETE': 'delete',
-        }[request.method]
-
         # Restrict the view's QuerySet to allow only the permitted objects
+        action = HTTP_ACTIONS[request.method]
         if action:
             self.queryset = self.queryset.restrict(request.user, action)