Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify request_started_handler to use SESSION_ENGINE #271

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions easyaudit/signals/request_signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from django.contrib.auth import get_user_model
from importlib import import_module

from django.contrib.auth import get_user_model, SESSION_KEY as AUTH_SESSION_KEY
from django.contrib.sessions.models import Session
from django.core.signals import request_started
from django.http.cookie import SimpleCookie
from django.utils import timezone
from django.conf import settings
from django.utils.module_loading import import_string

session_engine = import_module(settings.SESSION_ENGINE)

jheld marked this conversation as resolved.
Show resolved Hide resolved
# try and get the user from the request; commented for now, may have a bug in this flow.
# from easyaudit.middleware.easyaudit import get_current_user
from easyaudit.settings import REMOTE_ADDR_HEADER, UNREGISTERED_URLS, REGISTERED_URLS, WATCH_REQUEST_EVENTS, \
Expand Down Expand Up @@ -70,12 +74,12 @@ def request_started_handler(sender, **kwargs):
session_id = cookie[session_cookie_name].value

try:
session = Session.objects.get(session_key=session_id)
session = session_engine.SessionStore(session_key=session_id).load()
except Session.DoesNotExist:
session = None

if session:
user_id = session.get_decoded().get('_auth_user_id')
if session and AUTH_SESSION_KEY in session:
user_id = session.get(AUTH_SESSION_KEY)
try:
user = get_user_model().objects.get(id=user_id)
except:
Expand Down
Loading