We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3372375 commit 0aef0fdCopy full SHA for 0aef0fd
1 file changed
codespeed/auth.py
@@ -1,4 +1,5 @@
1
import logging
2
+import types
3
from functools import wraps
4
from django.contrib.auth import authenticate, login
5
from django.http import HttpResponse, HttpResponseForbidden
@@ -9,6 +10,20 @@
9
10
logger = logging.getLogger(__name__)
11
12
13
+def is_authenticated(request):
14
+ # NOTE: We do type check so we also support newer versions of Djando when
15
+ # is_authenticated and some other methods have been properties
16
+ if isinstance(request.user.is_authenticated, (types.FunctionType,
17
+ types.MethodType)):
18
+ return request.user.is_authenticated()
19
+ elif isinstance(request.user.is_authenticated, bool):
20
+ return request.user.is_authenticated
21
+ else:
22
+ logger.info('Got unexpected type for request.user.is_authenticated '
23
+ 'variable')
24
+ return False
25
+
26
27
def basic_auth_required(realm='default'):
28
def _helper(func):
29
@wraps(func)
@@ -18,7 +33,7 @@ def _decorator(request, *args, **kwargs):
33
if settings.ALLOW_ANONYMOUS_POST:
34
logger.debug('allowing anonymous post')
35
allowed = True
- elif hasattr(request, 'user') and request.user.is_authenticated():
36
+ elif hasattr(request, 'user') and is_authenticated(request=request):
37
38
elif 'HTTP_AUTHORIZATION' in request.META:
39
logger.debug('checking for http authorization header')
0 commit comments