Skip to content

Commit

Permalink
Merge pull request #53 from Moesif/refactor-user-id
Browse files Browse the repository at this point in the history
Refactor: Prioritize identify user customer hook
  • Loading branch information
dkm199 committed Mar 2, 2021
2 parents a15f5aa + 716e0ae commit 9a25810
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions moesifdjango/logger_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ def parse_authorization_header(self, token, field, debug):
def get_user_id(self, middleware_settings, request, response, request_headers, debug):
user_id = None
try:
if request.user and request.user.is_authenticated and request.user.username:
return request.user.username
else:
identify_user = middleware_settings.get('IDENTIFY_USER', None)
if identify_user is not None:
user_id = identify_user(request, response)
if not user_id:
identify_user = middleware_settings.get('IDENTIFY_USER', None)
if identify_user is not None:
user_id = identify_user(request, response)
if not user_id:
if request.user and request.user.is_authenticated and request.user.username:
return request.user.username
else:
# Transform request headers keys to lower case
request_headers = {k.lower(): v for k, v in request_headers.items()}
# Fetch the auth header name from the config
Expand Down
2 changes: 1 addition & 1 deletion moesifdjango/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, get_response):
# below comment for setting moesif base_uri to a test server.
if self.middleware_settings.get('LOCAL_DEBUG', False):
Configuration.BASE_URI = self.middleware_settings.get('LOCAL_MOESIF_BASEURL', 'https://api.moesif.net')
Configuration.version = 'moesifdjango-python/2.0.0'
Configuration.version = 'moesifdjango-python/2.0.2'
if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False):
try:
if self.DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion moesifdjango/middleware_pre19.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
# below comment for setting moesif base_uri to a test server.
if self.middleware_settings.get('LOCAL_DEBUG', False):
Configuration.BASE_URI = self.middleware_settings.get('LOCAL_MOESIF_BASEURL', 'https://api.moesif.net')
Configuration.version = 'moesifdjango-python/2.0.0'
Configuration.version = 'moesifdjango-python/2.0.2'
if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False):
try:
if self.DEBUG:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='2.0.1',
version='2.0.2',

description='Moesif Middleware for Python Django',
long_description=long_description,
Expand Down

0 comments on commit 9a25810

Please sign in to comment.