File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 1
1
from django .core .exceptions import ImproperlyConfigured , PermissionDenied
2
+
2
3
from ..viewsets import BaseAutoPermissionMixin
3
4
5
+
4
6
class AutoPermissionViewSetMixin (BaseAutoPermissionMixin ):
5
7
"""
6
8
Enforces object-level permissions in ``rest_framework.viewsets.ViewSet``,
Original file line number Diff line number Diff line change 1
1
# All auto permission mixins (both for DRF and Django views)
2
2
# inherit from this mixin.
3
3
class BaseAutoPermissionMixin :
4
+ def get_perm (self , model , perm_type ):
5
+ return "%s.%s_%s" % (model ._meta .app_label , perm_type , model ._meta .model_name )
6
+
4
7
def get_permission_for_model (self , model , perm_type ):
5
- return model .get_perm (perm_type )
8
+
9
+ # Attempt to use model mixin. If model mixin is not available,
10
+ # default to standard convetion of this project (or allow
11
+ # overriding `get_perm` through a custom Mixin)
12
+ try :
13
+ use_model_mixin_method = callable (model .get_perm )
14
+ except AttributeError :
15
+ use_model_mixin_method = False
16
+
17
+ if use_model_mixin_method :
18
+ perm = model .get_perm (perm_type )
19
+ else :
20
+ perm = self .get_perm (model , perm_type )
21
+ return perm
You can’t perform that action at this time.
0 commit comments