Django 1.8 compatibility: extracting the user from a session

django commit 596564e80808 stores the user id in the session as a
string, which broke our code that extracts the user id and compares
it to the id of a UserProfile object.

(imported from commit 99defd7fea96553550fa19e0b2f3e91a1baac123)
This commit is contained in:
Reid Barton
2015-08-19 11:53:55 -07:00
parent 5ea3bf85de
commit 9db521a931
5 changed files with 29 additions and 14 deletions

View File

@@ -20,6 +20,7 @@ from zerver.lib.event_queue import get_client_descriptor
from zerver.middleware import record_request_start_data, record_request_stop_data, \
record_request_restart_data, write_log_line, format_timedelta
from zerver.lib.redis_utils import get_redis_client
from zerver.lib.session_user import get_session_user
logger = logging.getLogger('zulip.socket')
@@ -34,10 +35,8 @@ def get_user_profile(session_id):
except djSession.DoesNotExist:
return None
session_store = djsession_engine.SessionStore(djsession.session_key)
try:
return UserProfile.objects.get(pk=session_store['_auth_user_id'])
return UserProfile.objects.get(pk=get_session_user(djsession))
except (UserProfile.DoesNotExist, KeyError):
return None