11
11
from django .conf import settings
12
12
from django .core .cache import cache
13
13
from django .core .exceptions import MiddlewareNotUsed
14
- from django .utils .deprecation import MiddlewareMixin
15
14
from django .contrib import auth
16
15
17
16
from tecken .base .utils import requests_retry_session
@@ -73,7 +72,7 @@ def find_users(client_id, client_secret, domain, email, session):
73
72
return response .json ()
74
73
75
74
76
- class NotBlockedInAuth0Middleware ( MiddlewareMixin ) :
75
+ class NotBlockedInAuth0Middleware :
77
76
"""If the user is found in Auth0's User Management API *and*
78
77
is "blocked" make the user inactive. In active users can't have any
79
78
permissions but we don't have to destroy or change any API tokens.
@@ -90,10 +89,17 @@ class NotBlockedInAuth0Middleware(MiddlewareMixin):
90
89
at throttled interval.
91
90
"""
92
91
93
- def __init__ (self ):
92
+ def __init__ (self , get_response = None ):
94
93
if not settings .ENABLE_AUTH0_BLOCKED_CHECK : # pragma: no cover
95
- logger .warn ('Auth0 blocked check disabled' )
94
+ logger .warning ('Auth0 blocked check disabled' )
96
95
raise MiddlewareNotUsed
96
+ self .get_response = get_response
97
+
98
+ def __call__ (self , request ):
99
+ response = self .process_request (request )
100
+ if not response :
101
+ response = self .get_response (request )
102
+ return response
97
103
98
104
def process_request (self , request ):
99
105
if not request .user .is_active or not request .user .email :
@@ -105,7 +111,7 @@ def process_request(self, request):
105
111
# oh my!
106
112
request .user .is_active = False
107
113
request .user .save ()
108
- logger .warn (
114
+ logger .warning (
109
115
f'User { request .user .email } is blocked in Auth0 '
110
116
f'and now made inactive'
111
117
)
0 commit comments