From 6b81210ba1ed7dacd9f800a94699e17edb6127b6 Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 2 Feb 2016 10:03:18 +0100 Subject: [PATCH] Fix permissions Mixins --- core/views/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/views/__init__.py b/core/views/__init__.py index e893bae8..d3d1495c 100644 --- a/core/views/__init__.py +++ b/core/views/__init__.py @@ -22,7 +22,8 @@ class CanEditPropMixin(View): """ def dispatch(self, request, *arg, **kwargs): res = super(CanEditPropMixin, self).dispatch(request, *arg, **kwargs) - if self.object is None or self.request.user.is_owner(self.object): + if ((hasattr(self, 'object') and (self.object is None or self.request.user.is_owner(self.object))) or + (hasattr(self, 'object_list') and (self.object_list is None or self.object_list is [] or self.request.user.is_owner(self.object_list[0])))): return res try: # Always unlock when 403 self.object.unset_lock() @@ -37,7 +38,8 @@ class CanEditMixin(View): def dispatch(self, request, *arg, **kwargs): # TODO: WIP: fix permissions with exceptions! res = super(CanEditMixin, self).dispatch(request, *arg, **kwargs) - if self.object is None or self.request.user.can_edit(self.object): + if ((hasattr(self, 'object') and (self.object is None or self.request.user.can_edit(self.object))) or + (hasattr(self, 'object_list') and (self.object_list is None or self.object_list is [] or self.request.user.can_edit(self.object_list[0])))): return res try: # Always unlock when 403 self.object.unset_lock() @@ -52,7 +54,8 @@ class CanViewMixin(View): """ def dispatch(self, request, *arg, **kwargs): res = super(CanViewMixin, self).dispatch(request, *arg, **kwargs) - if self.object is None or self.request.user.can_view(self.object): + if ((hasattr(self, 'object') and (self.object is None or self.request.user.can_view(self.object))) or + (hasattr(self, 'object_list') and (self.object_list is None or self.object_list is [] or self.request.user.can_view(self.object_list[0])))): return res try: # Always unlock when 403 self.object.unset_lock()