Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
9ada9d61
Commit
9ada9d61
authored
9 years ago
by
Sarina Canelake
Browse files
Options
Downloads
Plain Diff
Merge pull request #8732 from edx/sarina/fix-log-messages
Dark lang middleware: Check if user is authenticated
parents
f4bee50e
28a23438
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/djangoapps/dark_lang/middleware.py
+23
-15
23 additions, 15 deletions
common/djangoapps/dark_lang/middleware.py
with
23 additions
and
15 deletions
common/djangoapps/dark_lang/middleware.py
+
23
−
15
View file @
9ada9d61
...
...
@@ -17,7 +17,6 @@ from dark_lang.models import DarkLangConfig
from
openedx.core.djangoapps.user_api.preferences.api
import
(
delete_user_preference
,
get_user_preference
,
set_user_preference
)
from
openedx.core.djangoapps.user_api.errors
import
UserNotFound
from
lang_pref
import
LANGUAGE_KEY
# TODO re-import this once we're on Django 1.5 or greater. [PLAT-671]
...
...
@@ -133,27 +132,36 @@ class DarkLangMiddleware(object):
and that language doesn
'
t appear in ``self.released_langs``,
then set the session LANGUAGE_SESSION_KEY to that language.
"""
auth_user
=
request
.
user
.
is_authenticated
()
if
'
clear-lang
'
in
request
.
GET
:
# Reset dark lang
delete_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
)
# Reset user's language to their language preference, if they have one
user_pref
=
get_user_preference
(
request
.
user
,
LANGUAGE_KEY
)
if
user_pref
:
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
user_pref
elif
LANGUAGE_SESSION_KEY
in
request
.
session
:
# delete the session language key (if one is set)
if
LANGUAGE_SESSION_KEY
in
request
.
session
:
del
request
.
session
[
LANGUAGE_SESSION_KEY
]
if
auth_user
:
# Reset user's dark lang preference to null
delete_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
)
# Get & set user's preferred language
user_pref
=
get_user_preference
(
request
.
user
,
LANGUAGE_KEY
)
if
user_pref
:
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
user_pref
return
# Get the user's preview lang - this is either going to be set from a query
# param `?preview-lang=xx`, or we may have one already set as a dark lang preference.
preview_lang
=
request
.
GET
.
get
(
'
preview-lang
'
,
None
)
if
not
preview_lang
:
try
:
# Try to get the request user's preference (might not have a user, though)
preview_lang
=
get_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
)
except
UserNotFound
:
return
if
not
preview_lang
and
auth_user
:
# Get the request user's dark lang preference
preview_lang
=
get_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
)
# User doesn't have a dark lang preference, so just return
if
not
preview_lang
:
return
# Set the session key to the requested preview lang
request
.
session
[
LANGUAGE_SESSION_KEY
]
=
preview_lang
set_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
,
preview_lang
)
# Make sure that we set the requested preview lang as the dark lang preference for the
# user, so that the lang_pref middleware doesn't clobber away the dark lang preview.
if
auth_user
:
set_user_preference
(
request
.
user
,
DARK_LANGUAGE_KEY
,
preview_lang
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment