Bläddra i källkod

Fix is authenticated

Denis K 7 år sedan
förälder
incheckning
eabb6a74b7
4 ändrade filer med 22 tillägg och 13 borttagningar
  1. 6 5
      jet/dashboard/forms.py
  2. 2 2
      jet/dashboard/views.py
  3. 6 5
      jet/forms.py
  4. 8 1
      jet/utils.py

+ 6 - 5
jet/dashboard/forms.py

@@ -3,6 +3,7 @@ from django import forms
 from django.core.exceptions import ValidationError
 from jet.dashboard.models import UserDashboardModule
 from jet.dashboard.utils import get_current_dashboard
+from jet.utils import user_is_authenticated
 
 
 class UpdateDashboardModulesForm(forms.Form):
@@ -17,7 +18,7 @@ class UpdateDashboardModulesForm(forms.Form):
     def clean(self):
         data = super(UpdateDashboardModulesForm, self).clean()
 
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         try:
@@ -68,7 +69,7 @@ class AddUserDashboardModuleForm(forms.ModelForm):
     def clean(self):
         data = super(AddUserDashboardModuleForm, self).clean()
 
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         if 'app_label' in data:
@@ -110,7 +111,7 @@ class UpdateDashboardModuleCollapseForm(forms.ModelForm):
     def clean(self):
         data = super(UpdateDashboardModuleCollapseForm, self).clean()
 
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         if self.instance.user != self.request.user.pk:
@@ -131,7 +132,7 @@ class RemoveDashboardModuleForm(forms.ModelForm):
     def clean(self):
         cleaned_data = super(RemoveDashboardModuleForm, self).clean()
 
-        if not self.request.user.is_authenticated or self.instance.user != self.request.user.pk:
+        if not user_is_authenticated(self.request.user) or self.instance.user != self.request.user.pk:
             raise ValidationError('error')
 
         return cleaned_data
@@ -156,7 +157,7 @@ class ResetDashboardForm(forms.Form):
         data = super(ResetDashboardForm, self).clean()
         data['app_label'] = data['app_label'] if data['app_label'] else None
 
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         return data

+ 2 - 2
jet/dashboard/views.py

@@ -11,7 +11,7 @@ from django.views.decorators.http import require_POST, require_GET
 from jet.dashboard.forms import UpdateDashboardModulesForm, AddUserDashboardModuleForm, \
     UpdateDashboardModuleCollapseForm, RemoveDashboardModuleForm, ResetDashboardForm
 from jet.dashboard.models import UserDashboardModule
-from jet.utils import JsonResponse, get_app_list, SuccessMessageMixin
+from jet.utils import JsonResponse, get_app_list, SuccessMessageMixin, user_is_authenticated
 from django.views.generic import UpdateView
 from django.utils.translation import ugettext_lazy as _
 
@@ -216,7 +216,7 @@ def load_dashboard_module_view(request, pk):
     result = {'error': False}
 
     try:
-        if not request.user.is_authenticated or not request.user.is_staff:
+        if not user_is_authenticated(request.user) or not request.user.is_staff:
             raise ValidationError('error')
 
         instance = UserDashboardModule.objects.get(pk=pk, user=request.user.pk)

+ 6 - 5
jet/forms.py

@@ -5,8 +5,9 @@ from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import ValidationError
 from django.db.models import Q
 import operator
+
 from jet.models import Bookmark, PinnedApplication
-from jet.utils import get_model_instance_label
+from jet.utils import get_model_instance_label, user_is_authenticated
 from functools import reduce
 
 try:
@@ -27,7 +28,7 @@ class AddBookmarkForm(forms.ModelForm):
 
     def clean(self):
         data = super(AddBookmarkForm, self).clean()
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         if not self.request.user.has_perm('jet.change_bookmark'):
             raise ValidationError('error')
@@ -49,7 +50,7 @@ class RemoveBookmarkForm(forms.ModelForm):
 
     def clean(self):
         data = super(RemoveBookmarkForm, self).clean()
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         if self.instance.user != self.request.user.pk:
             raise ValidationError('error')
@@ -71,7 +72,7 @@ class ToggleApplicationPinForm(forms.ModelForm):
 
     def clean(self):
         data = super(ToggleApplicationPinForm, self).clean()
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         return data
 
@@ -108,7 +109,7 @@ class ModelLookupForm(forms.Form):
     def clean(self):
         data = super(ModelLookupForm, self).clean()
 
-        if not self.request.user.is_authenticated or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         try:

+ 8 - 1
jet/utils.py

@@ -250,7 +250,7 @@ def get_possible_language_codes():
 
 
 def get_original_menu_items(context):
-    if context.get('user') and context['user'].is_authenticated:
+    if context.get('user') and user_is_authenticated(context['user']):
         pinned_apps = PinnedApplication.objects.filter(user=context['user'].pk).values_list('app_label', flat=True)
     else:
         pinned_apps = []
@@ -447,3 +447,10 @@ def context_to_dict(context):
         context = flat
 
     return context
+
+
+def user_is_authenticated(user):
+    if not hasattr(user.is_authenticated, '__call__'):
+        return user.is_authenticated
+    else:
+        return user.is_authenticated()