Skip to content

Commit

Permalink
fix: update language cookie if langauge cookie is not same as user's …
Browse files Browse the repository at this point in the history
…language preference
  • Loading branch information
muhammad-ammar committed May 8, 2024
1 parent 83f2cff commit dba03f5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Unreleased
----------
* nothing unreleased

[4.17.4]
--------
* fix: update language cookie if langauge cookie is not same as user's language preference

[4.17.3]
--------
* feat: replacing non encrypted fields of blackboard config model with encypted ones
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.17.3"
__version__ = "4.17.4"
10 changes: 10 additions & 0 deletions enterprise/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def process_request(self, request):
# Ignore errors related to user preferences not found.
pass

# This is to handle a bug where a user is logged in multiple tabs/browsers.
# User updates the language preference in one tab. After update, user's language preference
# in the database and language cookie in the browser is set to new language.
# But in the other tab/browser, user still has the old language cookie. So when the user
# refreshes the page, the language cookie is sent to the server and overrides the user's preference.
cookie_lang = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
if user_pref and cookie_lang and cookie_lang != user_pref:
request._anonymous_user_cookie_lang = user_pref
request.COOKIES[settings.LANGUAGE_COOKIE_NAME] = user_pref

Check warning on line 78 in enterprise/middleware.py

View check run for this annotation

Codecov / codecov/patch

enterprise/middleware.py#L77-L78

Added lines #L77 - L78 were not covered by tests

# If user's language preference is not set and enterprise customer has a default language configured
# then set the default language as the learner's language
if not user_pref and not is_request_from_mobile_app(request):
Expand Down

0 comments on commit dba03f5

Please sign in to comment.