Commit 6d7e583e by zubair-arbi

move the method for updating the context of third party auth to openedx enterprise utils

parent f3318465
......@@ -37,10 +37,10 @@ from openedx.core.djangoapps.user_api.errors import (
UserNotFound,
UserAPIInternalError
)
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib.edx_api_utils import get_edx_api_data
from openedx.core.lib.time_zone_utils import TIME_ZONE_CHOICES
from openedx.features.enterprise_support.api import enterprise_customer_for_request, get_enterprise_learner_data
from openedx.features.enterprise_support.utils import update_third_party_auth_context_for_enterprise
from student.helpers import destroy_oauth_tokens, get_next_url_for_login_page
from student.models import UserProfile
from student.views import register_user as old_register_view
......@@ -381,36 +381,7 @@ def _third_party_auth_context(request, redirect_to, tpa_hint=None):
context['errorMessage'] = _(unicode(msg)) # pylint: disable=translation-of-non-string
break
context = _update_context_for_enterprise_error_message(context, enterprise_customer)
return context
def _update_context_for_enterprise_error_message(context, enterprise_customer=None):
"""
Return updated context with modified `errorMessage` for enterprise.
"""
if enterprise_customer and context['errorMessage']:
context['errorMessage'] = Text(_(
u'We are sorry, you are not authorized to access {platform_name} via this channel. '
u'Please contact your {enterprise} administrator in order to access {platform_name} '
u'or contact {edx_support_link}.{line_break}'
u'{line_break}'
u'Error Details:{line_break}{error_message}')
).format(
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME),
enterprise=enterprise_customer['name'],
error_message=context['errorMessage'],
edx_support_link=HTML(
'<a href="{edx_support_url}">{support_url_name}</a>'
).format(
edx_support_url=configuration_helpers.get_value(
'SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK
),
support_url_name=_('edX Support'),
),
line_break=HTML('<br/>')
)
context = update_third_party_auth_context_for_enterprise(context, enterprise_customer)
return context
......
......@@ -3,6 +3,10 @@ from __future__ import unicode_literals
import hashlib
import six
from django.conf import settings
from django.utils.translation import ugettext as _
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangolib.markup import HTML, Text
def get_cache_key(**kwargs):
......@@ -27,3 +31,40 @@ def get_cache_key(**kwargs):
key = '__'.join(['{}:{}'.format(item, value) for item, value in six.iteritems(kwargs)])
return hashlib.md5(key).hexdigest()
def update_third_party_auth_context_for_enterprise(context, enterprise_customer=None):
"""
Return updated context of third party auth with modified for enterprise.
Arguments:
context (dict): Context for third party auth providers and auth pipeline.
enterprise_customer (dict): data for enterprise customer
Returns:
context (dict): Updated context of third party auth with modified
`errorMessage`.
"""
if enterprise_customer and context['errorMessage']:
context['errorMessage'] = Text(_(
u'We are sorry, you are not authorized to access {platform_name} via this channel. '
u'Please contact your {enterprise} administrator in order to access {platform_name} '
u'or contact {edx_support_link}.{line_break}'
u'{line_break}'
u'Error Details:{line_break}{error_message}')
).format(
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME),
enterprise=enterprise_customer['name'],
error_message=context['errorMessage'],
edx_support_link=HTML(
'<a href="{edx_support_url}">{support_url_name}</a>'
).format(
edx_support_url=configuration_helpers.get_value(
'SUPPORT_SITE_LINK', settings.SUPPORT_SITE_LINK
),
support_url_name=_('edX Support'),
),
line_break=HTML('<br/>')
)
return context
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