From e417c5f8c2ad47176e2435a93d66af5c52e8b294 Mon Sep 17 00:00:00 2001
From: Jillian Vogel <jill@opencraft.com>
Date: Wed, 21 Mar 2018 14:54:36 +1030
Subject: [PATCH] Adds EMPTY_DASHBOARD_MESSAGE Site Configuration flag

When set, displays the configured text/markup under "You are not enrolled in any courses yet."

Adjusts left/right padding on .empty-dashboard-message to keep our extra message from hitting the sides.
---
 common/djangoapps/student/tests/test_views.py | 18 ++++++++++++++++++
 common/djangoapps/student/views/dashboard.py  |  4 ++++
 lms/static/sass/multicourse/_dashboard.scss   |  9 +++++++--
 lms/templates/dashboard.html                  |  4 +++-
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py
index 186abf0a16a..359556dde41 100644
--- a/common/djangoapps/student/tests/test_views.py
+++ b/common/djangoapps/student/tests/test_views.py
@@ -27,6 +27,7 @@ from milestones.tests.utils import MilestonesTestCaseMixin
 from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory
 from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
 from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
+from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context
 from pyquery import PyQuery as pq
 from student.cookies import get_user_info_cookie_data
 from student.helpers import DISABLE_UNENROLL_CERT_STATES
@@ -633,6 +634,23 @@ class StudentDashboardTests(SharedModuleStoreTestCase, MilestonesTestCaseMixin,
         response = self.client.get(reverse('dashboard'))
         self.assertNotIn('You are not enrolled in any courses yet.', response.content)
 
+    def test_show_empty_dashboard_message(self):
+        """
+        Verify that when the EMPTY_DASHBOARD_MESSAGE feature is set,
+        its text is displayed in an empty courses list.
+        """
+        empty_dashboard_message = "Check out our lovely <i>free</i> courses!"
+        response = self.client.get(reverse('dashboard'))
+        self.assertIn('You are not enrolled in any courses yet.', response.content)
+        self.assertNotIn(empty_dashboard_message, response.content)
+
+        with with_site_configuration_context(configuration={
+            "EMPTY_DASHBOARD_MESSAGE": empty_dashboard_message,
+        }):
+            response = self.client.get(reverse('dashboard'))
+            self.assertIn('You are not enrolled in any courses yet.', response.content)
+            self.assertIn(empty_dashboard_message, response.content)
+
     @staticmethod
     def _remove_whitespace_from_html_string(html):
         return ''.join(html.split())
diff --git a/common/djangoapps/student/views/dashboard.py b/common/djangoapps/student/views/dashboard.py
index fcd144159fb..90ab2598431 100644
--- a/common/djangoapps/student/views/dashboard.py
+++ b/common/djangoapps/student/views/dashboard.py
@@ -563,6 +563,9 @@ def student_dashboard(request):
         'HIDE_DASHBOARD_COURSES_UNTIL_ACTIVATED',
         settings.FEATURES.get('HIDE_DASHBOARD_COURSES_UNTIL_ACTIVATED', False)
     )
+    empty_dashboard_message = configuration_helpers.get_value(
+        'EMPTY_DASHBOARD_MESSAGE', None
+    )
 
     # Get the org whitelist or the org blacklist for the current site
     site_org_whitelist, site_org_blacklist = get_org_black_and_whitelist_for_site()
@@ -811,6 +814,7 @@ def student_dashboard(request):
         'display_course_modes_on_dashboard': enable_verified_certificates and display_course_modes_on_dashboard,
         'display_sidebar_on_dashboard': display_sidebar_on_dashboard,
         'display_dashboard_courses': (user.is_active or not hide_dashboard_courses_until_activated),
+        'empty_dashboard_message': empty_dashboard_message,
     }
 
     if ecommerce_service.is_enabled(request.user):
diff --git a/lms/static/sass/multicourse/_dashboard.scss b/lms/static/sass/multicourse/_dashboard.scss
index 63b75621956..7de3d8b8abb 100644
--- a/lms/static/sass/multicourse/_dashboard.scss
+++ b/lms/static/sass/multicourse/_dashboard.scss
@@ -1098,7 +1098,7 @@
 .empty-dashboard-message {
   border: 3px solid $gray-l4;
   background: $gray-l6;
-  padding: ($baseline*2) 0;
+  padding: ($baseline*2) ($baseline/10);
   text-align: center;
 
   p {
@@ -1109,7 +1109,12 @@
     text-shadow: 0 1px rgba(255,255,255, 0.6);
   }
 
-  a {
+  p.custom-message {
+    @include font-size(14);
+    text-shadow: none;
+  }
+
+  a.btn {
     background-color: theme-color('primary');
     border: 1px solid theme-color('primary');
     box-shadow: 0 1px 8px 0 $shadow-l1;
diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html
index 2c9c4ca9947..52d487ca554 100644
--- a/lms/templates/dashboard.html
+++ b/lms/templates/dashboard.html
@@ -194,7 +194,9 @@ from student.models import CourseEnrollment
           % else:
             <div class="empty-dashboard-message">
               <p>${_("You are not enrolled in any courses yet.")}</p>
-
+              % if empty_dashboard_message:
+                <p class="custom-message">${empty_dashboard_message | n, decode.utf8}</p>
+              %endif
               % if settings.FEATURES.get('COURSES_ARE_BROWSABLE'):
                 <a class="btn btn-primary" href="${marketing_link('COURSES')}">
                   ${_("Explore courses")}
-- 
GitLab