From 87f444fd448c8a2a1e36200cfa04d13c98754b85 Mon Sep 17 00:00:00 2001 From: Jeff Chaves <58956521+chavesj@users.noreply.github.com> Date: Wed, 29 Jul 2020 11:55:02 -0400 Subject: [PATCH] ENT-3143: display message banner guiding user to their enterprise LP if enabled (#24625) * display message banner guiding user to their enterprise LP if enabled * adding new sass class name to use same styling as recovery email alert --- common/djangoapps/student/views/dashboard.py | 9 ++++- lms/static/js/views/message_banner.js | 3 +- .../sass/elements/_system-feedback.scss | 3 +- lms/templates/dashboard.html | 7 ++++ .../fields/message_banner.underscore | 2 +- openedx/features/enterprise_support/api.py | 40 +++++++++++++++++++ themes/edx.org/lms/templates/dashboard.html | 7 ++++ 7 files changed, 67 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py index b7e1bd97722..d4b846546fa 100644 --- a/common/djangoapps/student/views/dashboard.py +++ b/common/djangoapps/student/views/dashboard.py @@ -44,7 +44,10 @@ from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_f from openedx.core.djangoapps.util.maintenance_banner import add_maintenance_banner from openedx.core.djangoapps.waffle_utils import WaffleFlag, WaffleFlagNamespace from openedx.core.djangolib.markup import HTML, Text -from openedx.features.enterprise_support.api import get_dashboard_consent_notification +from openedx.features.enterprise_support.api import ( + get_dashboard_consent_notification, + get_enterprise_learner_portal_enabled_message, +) from shoppingcart.models import DonationConfiguration from student.api import COURSE_DASHBOARD_PLUGIN_VIEW_NAME from student.helpers import cert_info, check_verify_status_by_course, get_resume_urls_for_enrollments @@ -623,6 +626,9 @@ def student_dashboard(request): enterprise_message = get_dashboard_consent_notification(request, user, course_enrollments) + # Display a message guiding the user to their Enterprise's Learner Portal if enabled + enterprise_learner_portal_enabled_message = get_enterprise_learner_portal_enabled_message(request) + recovery_email_message = recovery_email_activation_message = None if is_secondary_email_feature_enabled(): try: @@ -833,6 +839,7 @@ def student_dashboard(request): 'empty_dashboard_message': empty_dashboard_message, 'recovery_email_message': recovery_email_message, 'recovery_email_activation_message': recovery_email_activation_message, + 'enterprise_learner_portal_enabled_message': enterprise_learner_portal_enabled_message, 'show_load_all_courses_link': show_load_all_courses_link(user, course_limit, course_enrollments), # TODO START: clean up as part of REVEM-199 (START) 'course_info': get_dashboard_course_info(user, course_enrollments), diff --git a/lms/static/js/views/message_banner.js b/lms/static/js/views/message_banner.js index 17560de5d41..d7d9729fd2b 100644 --- a/lms/static/js/views/message_banner.js +++ b/lms/static/js/views/message_banner.js @@ -27,7 +27,8 @@ urgency: 'high', type: '', hideCloseBtn: true, - isRecoveryEmailMsg: false + isRecoveryEmailMsg: false, + isLearnerPortalEnabled: false }); }, diff --git a/lms/static/sass/elements/_system-feedback.scss b/lms/static/sass/elements/_system-feedback.scss index 27602c9460c..be359388500 100644 --- a/lms/static/sass/elements/_system-feedback.scss +++ b/lms/static/sass/elements/_system-feedback.scss @@ -114,7 +114,8 @@ } } - &.recovery-email-alert { + &.recovery-email-alert, + &.learner-portal-enabled-alert { &#banner-msg { background: $state-info-bg; box-shadow: none; diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index dcc03a6de75..2721a6bd27b 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -99,6 +99,13 @@ from student.models import CourseEnrollment banner.showMessage(${recovery_email_activation_message | n, dump_js_escaped_json}) </%static:require_module> % endif + % if enterprise_learner_portal_enabled_message: + <%static:require_module module_name="js/views/message_banner" class_name="MessageBannerView"> + var banner = new MessageBannerView({urgency: 'low', type: 'warning', isLearnerPortalEnabled: true}); + $('#content').prepend(banner.$el); + banner.showMessage(${enterprise_learner_portal_enabled_message | n, dump_js_escaped_json}) + </%static:require_module> + % endif </%block> <div class="dashboard-notifications" tabindex="-1"> diff --git a/lms/templates/fields/message_banner.underscore b/lms/templates/fields/message_banner.underscore index 23e01bb2d48..dc019c5d030 100644 --- a/lms/templates/fields/message_banner.underscore +++ b/lms/templates/fields/message_banner.underscore @@ -1,4 +1,4 @@ -<div id="banner-msg" class="wrapper-msg urgency-<%- urgency %> <%- type %> <% if (isRecoveryEmailMsg == true) { %> recovery-email-alert <% } %>" role="alert"> +<div id="banner-msg" class="wrapper-msg urgency-<%- urgency %> <%- type %> <% if (isRecoveryEmailMsg == true) { %> recovery-email-alert <% } %> <% if (isLearnerPortalEnabled == true) { %> learner-portal-enabled-alert <% } %>" role="alert"> <i <% if (hideCloseBtn == true) { %> hidden <% } %> id="close" class="fa fa-close close-icon"></i> <div class="msg"> <div class="msg-content"> diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index 6aef2315baa..45b1df59c3f 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -23,6 +23,7 @@ from slumber.exceptions import HttpClientError, HttpNotFoundError, HttpServerErr from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangolib.markup import HTML, Text from openedx.features.enterprise_support.utils import get_data_consent_share_cache_key from third_party_auth.pipeline import get as get_partial_pipeline from third_party_auth.provider import Registry @@ -569,6 +570,45 @@ def get_enterprise_learner_data(user): return enterprise_learner_data['results'] +@enterprise_is_enabled() +def get_enterprise_learner_portal_enabled_message(request): + """ + Returns message to be displayed in dashboard if the user is linked to an Enterprise with the Learner Portal enabled. + + Note: request.session['enterprise_customer'] will be used in case the user is linked to + multiple Enterprises. Otherwise, it won't exist and the Enterprise Learner data + will be used. If that doesn't exist return None. + + Args: + request: request made to the LMS dashboard + """ + if request.session['enterprise_customer']: + enterprise_customer = request.session['enterprise_customer'] + else: + learner_data = get_enterprise_learner_data(request.user) + if learner_data: + enterprise_customer = learner_data[0]['enterprise_customer'] + else: + return None + + if enterprise_customer['enable_learner_portal']: + learner_portal_url = settings.ENTERPRISE_LEARNER_PORTAL_BASE_URL + '/' + enterprise_customer['slug'] + return Text(_( + "Your organization {bold_start}{enterprise_customer_name}{bold_end} uses a custom dashboard for learning. " + "{link_start}Click here{link_end} to continue in that experience." + )).format( + enterprise_customer_name=enterprise_customer['name'], + link_start=HTML("<a href='{learner_portal_url}'>").format( + learner_portal_url=learner_portal_url, + ), + link_end=HTML("</a>"), + bold_start=HTML("<b>"), + bold_end=HTML("</b>"), + ) + else: + return None + + def get_consent_notification_data(enterprise_customer): """ Returns the consent notification data from DataSharingConsentPage modal diff --git a/themes/edx.org/lms/templates/dashboard.html b/themes/edx.org/lms/templates/dashboard.html index 6c17bdc91c1..577c8c8035a 100644 --- a/themes/edx.org/lms/templates/dashboard.html +++ b/themes/edx.org/lms/templates/dashboard.html @@ -104,6 +104,13 @@ from student.models import CourseEnrollment banner.showMessage(${recovery_email_activation_message | n, dump_js_escaped_json}) </%static:require_module> % endif + % if enterprise_learner_portal_enabled_message: + <%static:require_module module_name="js/views/message_banner" class_name="MessageBannerView"> + var banner = new MessageBannerView({urgency: 'low', type: 'warning', isLearnerPortalEnabled: true}); + $('#content').prepend(banner.$el); + banner.showMessage(${enterprise_learner_portal_enabled_message | n, dump_js_escaped_json}) + </%static:require_module> + % endif </%block> <div class="dashboard-notifications" tabindex="-1"> -- GitLab