Commit 5500cc68 by Carlos Andrés Rocha

Use default locale to OpenID profile claims.

If the user has not selected a default locale, then return the default one.
parent e04c6c2a
""" Handlers for OpenID Connect provider. """
from django.conf import settings
import branding
from courseware.access import has_access
from student.models import anonymous_id_for_user
......@@ -51,6 +53,11 @@ class ProfileHandler(object):
"""
language = UserPreference.get_preference(data['user'], LANGUAGE_KEY)
# If the user has no language specified, return the default one.
if not language:
language = getattr(settings, 'LANGUAGE_CODE')
return language
......
# pylint: disable=missing-docstring
from django.conf import settings
from django.test.utils import override_settings
from django.test import TestCase
......@@ -52,12 +53,13 @@ class IDTokenTest(BaseTestMixin, IDTokenTestCase):
self.assertEqual(claim_name, user_name)
@override_settings(LANGUAGE_CODE='en')
def test_user_without_locale_claim(self):
scopes, claims = self.get_new_id_token_values('openid profile')
self.assertIn('profile', scopes)
self.assertNotIn('locale', claims)
self.assertEqual(claims['locale'], 'en')
def test_user_wit_locale_claim(self):
def test_user_with_locale_claim(self):
language = 'en'
UserPreference.set_preference(self.user, LANGUAGE_KEY, language)
scopes, claims = self.get_new_id_token_values('openid profile')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment