From 1cfefe245749397d0093064fd9197771e40c6ba1 Mon Sep 17 00:00:00 2001
From: Diana Huang <dkh@edx.org>
Date: Wed, 6 Sep 2017 14:31:31 -0400
Subject: [PATCH] Modify the header to show the learner profile.

Remove the profile from the user dropdown.

LEARNER-2318
---
 common/djangoapps/student/views.py            |  1 +
 common/test/acceptance/pages/lms/dashboard.py |  9 +++-
 .../tests/lms/test_learner_profile.py         |  3 +-
 .../courseware/tests/test_masquerade.py       | 18 --------
 lms/djangoapps/learner_dashboard/views.py     |  2 +
 lms/djangoapps/student_account/views.py       |  1 +
 .../bootstrap/navbar-authenticated.html       | 17 ++++++--
 .../navigation/navbar-authenticated.html      | 17 ++++++--
 lms/templates/user_dropdown.html              |  3 --
 .../learner_profile/views/learner_profile.py  |  4 ++
 themes/edx.org/lms/templates/header.html      | 41 +++++++++++++++----
 11 files changed, 77 insertions(+), 39 deletions(-)

diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py
index 634f5ae82f1..97de18b8255 100644
--- a/common/djangoapps/student/views.py
+++ b/common/djangoapps/student/views.py
@@ -864,6 +864,7 @@ def dashboard(request):
         'nav_hidden': True,
         'inverted_programs': inverted_programs,
         'show_program_listing': ProgramsApiConfig.is_enabled(),
+        'show_dashboard_tabs': True,
         'disable_courseware_js': True,
         'display_course_modes_on_dashboard': enable_verified_certificates and display_course_modes_on_dashboard,
         'display_sidebar_on_dashboard': display_sidebar_on_dashboard,
diff --git a/common/test/acceptance/pages/lms/dashboard.py b/common/test/acceptance/pages/lms/dashboard.py
index 24dbb07cafa..a636638f0ef 100644
--- a/common/test/acceptance/pages/lms/dashboard.py
+++ b/common/test/acceptance/pages/lms/dashboard.py
@@ -217,11 +217,18 @@ class DashboardPage(PageObject):
         """
         return self.q(css='.user-dropdown-menu li a').text
 
+    @property
+    def tabs_link_text(self):
+        """
+        Return the text of all the tabs on the dashboard.
+        """
+        return self.q(css='.tab-nav-item a').text
+
     def click_my_profile_link(self):
         """
         Click on `Profile` link.
         """
-        self.q(css='.user-dropdown-menu li a').nth(1).click()
+        self.q(css='.tab-nav-item a').nth(1).click()
 
     def click_account_settings_link(self):
         """
diff --git a/common/test/acceptance/tests/lms/test_learner_profile.py b/common/test/acceptance/tests/lms/test_learner_profile.py
index f896cea2bbb..f50fa567842 100644
--- a/common/test/acceptance/tests/lms/test_learner_profile.py
+++ b/common/test/acceptance/tests/lms/test_learner_profile.py
@@ -278,8 +278,7 @@ class OwnLearnerProfilePageTest(LearnerProfileTestMixin, AcceptanceTest):
         username, __ = self.log_in_as_unique_user()
         dashboard_page = DashboardPage(self.browser)
         dashboard_page.visit()
-        dashboard_page.click_username_dropdown()
-        self.assertIn('Profile', dashboard_page.username_dropdown_link_text)
+        self.assertIn('Profile', dashboard_page.tabs_link_text)
         dashboard_page.click_my_profile_link()
         my_profile_page = LearnerProfilePage(self.browser, username)
         my_profile_page.wait_for_page()
diff --git a/lms/djangoapps/courseware/tests/test_masquerade.py b/lms/djangoapps/courseware/tests/test_masquerade.py
index 072470b9137..fbe1f9733cb 100644
--- a/lms/djangoapps/courseware/tests/test_masquerade.py
+++ b/lms/djangoapps/courseware/tests/test_masquerade.py
@@ -154,20 +154,6 @@ class MasqueradeTestCase(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
         self.assertIn(self.problem_display_name, problem_html)
         self.assertEqual(show_answer_expected, "Show Answer" in problem_html)
 
-    def verify_real_user_profile_link(self):
-        """
-        Verifies that the 'Profile' link in the navigation dropdown is pointing
-        to the real user.
-        """
-        content = self.get_courseware_page().content
-        self.assertIn(
-            '<a href="/u/{}" role="menuitem" class="action dropdown-menuitem">Profile</a>'.format(
-                self.test_user.username
-            ),
-            content,
-            "Profile link should point to real user",
-        )
-
     def ensure_masquerade_as_group_member(self, partition_id, group_id):
         """
         Installs a masquerade for the test_user and test course, to enable the
@@ -376,9 +362,6 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
         self.update_masquerade(role='student', user_name=self.student_user.username)
         self.assertEqual(self.get_progress_detail(), u'2/2')
 
-        # Verify that the user dropdown links have not changed
-        self.verify_real_user_profile_link()
-
         # Temporarily override the student state.
         self.submit_answer('Correct', 'Incorrect')
         self.assertEqual(self.get_progress_detail(), u'1/2')
@@ -461,7 +444,6 @@ class TestStaffMasqueradeAsSpecificStudent(StaffMasqueradeTestCase, ProblemSubmi
         masquerade_progress = self.get_progress_page().content
         self.assertNotIn("1 of 2 possible points", masquerade_progress)
         self.assertIn("2 of 2 possible points", masquerade_progress)
-        self.verify_real_user_profile_link()
 
 
 @attr(shard=1)
diff --git a/lms/djangoapps/learner_dashboard/views.py b/lms/djangoapps/learner_dashboard/views.py
index 4dc2baf7696..afab6be29cf 100644
--- a/lms/djangoapps/learner_dashboard/views.py
+++ b/lms/djangoapps/learner_dashboard/views.py
@@ -35,6 +35,7 @@ def program_listing(request):
         'programs': meter.engaged_programs,
         'progress': meter.progress(),
         'show_program_listing': programs_config.enabled,
+        'show_dashboard_tabs': True,
         'uses_pattern_library': True,
     }
 
@@ -75,6 +76,7 @@ def program_details(request, program_uuid):
     context = {
         'urls': urls,
         'show_program_listing': programs_config.enabled,
+        'show_dashboard_tabs': True,
         'nav_hidden': True,
         'disable_courseware_js': True,
         'uses_pattern_library': True,
diff --git a/lms/djangoapps/student_account/views.py b/lms/djangoapps/student_account/views.py
index 206a565754e..49b90e2b9d6 100644
--- a/lms/djangoapps/student_account/views.py
+++ b/lms/djangoapps/student_account/views.py
@@ -555,6 +555,7 @@ def account_settings_context(request):
         'user_preferences_api_url': reverse('preferences_api', kwargs={'username': user.username}),
         'disable_courseware_js': True,
         'show_program_listing': ProgramsApiConfig.is_enabled(),
+        'show_dashboard_tabs': True,
         'order_history': user_orders
     }
 
diff --git a/lms/templates/navigation/bootstrap/navbar-authenticated.html b/lms/templates/navigation/bootstrap/navbar-authenticated.html
index 6aa709ddc36..bde233fd526 100644
--- a/lms/templates/navigation/bootstrap/navbar-authenticated.html
+++ b/lms/templates/navigation/bootstrap/navbar-authenticated.html
@@ -33,15 +33,26 @@ from django.utils.translation import ugettext as _
       </li>
     % endif
 
-    % if show_program_listing:
+    % if show_dashboard_tabs:
       <li class="nav-item mt-2 nav-item-open-collapsed">
         <a class="nav-link ${'active' if reverse('dashboard') == request.path else ''}" href="${reverse('dashboard')}">
           ${_("Courses")}
         </a>
       </li>
+      % if show_program_listing:
+        <li class="nav-item mt-2 nav-item-open-collapsed">
+          <a class="nav-link ${'active' if reverse('program_listing_view') in request.path else ''}" href="${reverse('program_listing_view')}">
+            ${_("Programs")}
+          </a>
+        </li>
+      % endif
+      <%
+        self.real_user = getattr(user, 'real_user', user)
+        is_on_profile_page = data and data.get('profile_user_id') is not None
+      %>
       <li class="nav-item mt-2 nav-item-open-collapsed">
-        <a class="nav-link ${'active' if reverse('program_listing_view') in request.path else ''}" href="${reverse('program_listing_view')}">
-          ${_("Programs")}
+        <a class="${'active ' if is_on_profile_page else ''}tab-nav-link" href="${reverse('learner_profile', args=[self.real_user.username])}">
+          ${_("Profile")}
         </a>
       </li>
     % endif
diff --git a/lms/templates/navigation/navbar-authenticated.html b/lms/templates/navigation/navbar-authenticated.html
index 20d236cb13f..b62b36d7d3c 100644
--- a/lms/templates/navigation/navbar-authenticated.html
+++ b/lms/templates/navigation/navbar-authenticated.html
@@ -16,15 +16,26 @@ from django.utils.translation import ugettext as _
         <a class="btn" href="${marketing_link('COURSES')}">${_('Explore courses')}</a>
       </li>
     % endif
-    % if show_program_listing:
+    % if show_dashboard_tabs:
       <li class="tab-nav-item">
         <a class="${'active ' if reverse('dashboard') == request.path else ''}tab-nav-link" href="${reverse('dashboard')}">
           ${_("Courses")}
         </a>
       </li>
+      % if show_program_listing:
+        <li class="tab-nav-item">
+          <a class="${'active ' if reverse('program_listing_view') in request.path else ''}tab-nav-link" href="${reverse('program_listing_view')}">
+            ${_("Programs")}
+          </a>
+        </li>
+      % endif
+      <%
+        self.real_user = getattr(user, 'real_user', user)
+        is_on_profile_page = data and data.get('profile_user_id') is not None
+      %>
       <li class="tab-nav-item">
-        <a class="${'active ' if reverse('program_listing_view') in request.path else ''}tab-nav-link" href="${reverse('program_listing_view')}">
-          ${_("Programs")}
+        <a class="${'active ' if is_on_profile_page else ''}tab-nav-link" href="${reverse('learner_profile', args=[self.real_user.username])}">
+          ${_("Profile")}
         </a>
       </li>
     % endif
diff --git a/lms/templates/user_dropdown.html b/lms/templates/user_dropdown.html
index 3ac2099b1ec..80bd8bdea6a 100644
--- a/lms/templates/user_dropdown.html
+++ b/lms/templates/user_dropdown.html
@@ -26,13 +26,11 @@ from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_
         <a class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">${username}</a>
         <ul class="dropdown-menu dropdown-menu-right" id="${_("Usermenu")}" aria-labelledby="dropdownMenuLink" tabindex="-1">
             <a class="dropdown-item" href="${reverse('dashboard')}">${_("Dashboard")}</a>
-            <a class="dropdown-item" href="${reverse('learner_profile', kwargs={'username': self.real_user.username})}">${_("Profile")}</a>
             <a class="dropdown-item" href="${reverse('account_settings')}">${_("Account")}</a>
             <a class="dropdown-item" href="${reverse('logout')}">${_("Sign Out")}</a>
         </ul>
     </li>
     <li class="nav-item nav-item-open-collapsed-only collapse"><a href="${reverse('dashboard')}">${_("Dashboard")}</a></li>
-    <li class="nav-item nav-item-open-collapsed-only"><a href="${reverse('learner_profile', kwargs={'username': self.real_user.username})}">${_("Profile")}</a></li>
     <li class="nav-item nav-item-open-collapsed-only"><a href="${reverse('account_settings')}">${_("Account")}</a></li>
     <li class="nav-item nav-item-open-collapsed-only"><a href="${reverse('logout')}">${_("Sign Out")}</a></li>
 % elif uses_pattern_library:
@@ -54,7 +52,6 @@ from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_
             <ul class="dropdown-menu list-divided is-hidden" id="${_("Usermenu")}" tabindex="-1">
                 <%block name="navigation_dropdown_menu_links" >
                     <li class="dropdown-item item has-block-link"><a href="${reverse('dashboard')}" role="menuitem" class="action dropdown-menuitem">${_("Dashboard")}</a></li>
-                    <li class="dropdown-item item has-block-link"><a href="${reverse('learner_profile', kwargs={'username': self.real_user.username})}" role="menuitem" class="action dropdown-menuitem">${_("Profile")}</a></li>
                     <li class="dropdown-item item has-block-link"><a href="${reverse('account_settings')}" role="menuitem" class="action dropdown-menuitem">${_("Account")}</a></li>
                 </%block>
                 <li class="dropdown-item item has-block-link"><a href="${reverse('logout')}" role="menuitem" class="action dropdown-menuitem">${_("Sign Out")}</a></li>
diff --git a/openedx/features/learner_profile/views/learner_profile.py b/openedx/features/learner_profile/views/learner_profile.py
index 14969d694c7..bb1f077e2b8 100644
--- a/openedx/features/learner_profile/views/learner_profile.py
+++ b/openedx/features/learner_profile/views/learner_profile.py
@@ -12,6 +12,7 @@ from django.utils.translation import ugettext as _
 from django.views.decorators.http import require_http_methods
 from django_countries import countries
 from edxmako.shortcuts import marketing_link
+from openedx.core.djangoapps.programs.models import ProgramsApiConfig
 from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
 from openedx.core.djangoapps.user_api.accounts.api import get_account_settings
 from openedx.core.djangoapps.user_api.errors import UserNotAuthorized, UserNotFound
@@ -137,7 +138,10 @@ def learner_profile_context(request, profile_username, user_is_staff):
             'platform_name': configuration_helpers.get_value('platform_name', settings.PLATFORM_NAME),
             'social_platforms': settings.SOCIAL_PLATFORMS,
         },
+        'show_program_listing': ProgramsApiConfig.is_enabled(),
+        'show_dashboard_tabs': True,
         'disable_courseware_js': True,
+        'nav_hidden': True,
     }
 
     if badges_enabled():
diff --git a/themes/edx.org/lms/templates/header.html b/themes/edx.org/lms/templates/header.html
index 2f2b2873e9d..2e36be97cbe 100644
--- a/themes/edx.org/lms/templates/header.html
+++ b/themes/edx.org/lms/templates/header.html
@@ -74,7 +74,7 @@ site_status_msg = get_site_status_msg(course_id)
     % if user.is_authenticated():
       <div class="collapse navbar-collapse" id="navbarSupportedContent">
         % if not course or disable_courseware_header:
-          % if not nav_hidden or show_program_listing:
+          % if not nav_hidden or show_dashboard_tabs:
             <ul class="navbar-nav mr-auto">
                 % if not nav_hidden:
                   <li class="nav-item mt-2 nav-item-open-collapsed nav-global-01">
@@ -87,18 +87,29 @@ site_status_msg = get_site_status_msg(course_id)
                     <a class="nav-link" href="${marketing_link('SCHOOLS')}">${_("Schools & Partners")}</a>
                   </li>
                 % endif
-                % if show_program_listing:
+                % if show_dashboard_tabs:
                   <li class="nav-item mt-2 nav-item-open-collapsed">
                     <a class="${'active' if reverse('dashboard') == request.path else ''} nav-link" href="${reverse('dashboard')}">
                       ${_("Courses")}
                     </a>
                   </li>
+                  % if show_program_listing:
+                    <li class="nav-item mt-2 nav-item-open-collapsed">
+                      <a class="${'active' if reverse('program_listing_view') in request.path else ''} nav-link" href="${reverse('program_listing_view')}">
+                        ${_("Programs")}
+                      </a>
+                    </li>
+                  % endif
+                  <%
+                    self.real_user = getattr(user, 'real_user', user)
+                    is_on_profile_page = data and data.get('profile_user_id') is not None
+                  %>
                   <li class="nav-item mt-2 nav-item-open-collapsed">
-                    <a class="${'active' if reverse('program_listing_view') in request.path else ''} nav-link" href="${reverse('program_listing_view')}">
-                      ${_("Programs")}
+                    <a class="${'active ' if is_on_profile_page else ''}tab-nav-link" href="${reverse('learner_profile', args=[self.real_user.username])}">
+                      ${_("Profile")}
                     </a>
                   </li>
-                  % endif
+              % endif
                 </ul>
           % endif
         % endif
@@ -166,7 +177,7 @@ site_status_msg = get_site_status_msg(course_id)
 
     % if user.is_authenticated():
       % if not course or disable_courseware_header:
-        % if not nav_hidden or show_program_listing:
+        % if not nav_hidden or show_dashboard_tabs:
           <nav aria-label="${_('Main')}" class="nav-main">
             <ul class="left list-inline nav-global authenticated">
               % if not nav_hidden:
@@ -182,17 +193,29 @@ site_status_msg = get_site_status_msg(course_id)
                   </li>
                 </%block>
               % endif
-              % if show_program_listing:
+              % if show_dashboard_tabs:
                 <li class="tab-nav-item">
                   <a class="${'active ' if reverse('dashboard') == request.path else ''}tab-nav-link" href="${reverse('dashboard')}">
                     ${_("Courses")}
                   </a>
                 </li>
+                % if show_program_listing:
+                  <li class="tab-nav-item">
+                    <a class="${'active ' if reverse('program_listing_view') in request.path else ''}tab-nav-link" href="${reverse('program_listing_view')}">
+                      ${_("Programs")}
+                    </a>
+                  </li>
+                % endif
+                <%
+                  self.real_user = getattr(user, 'real_user', user)
+                  is_on_profile_page = data and data.get('profile_user_id') is not None
+                %>
                 <li class="tab-nav-item">
-                  <a class="${'active ' if reverse('program_listing_view') in request.path else ''}tab-nav-link" href="${reverse('program_listing_view')}">
-                    ${_("Programs")}
+                  <a class="${'active ' if is_on_profile_page else ''}tab-nav-link" href="${reverse('learner_profile', args=[self.real_user.username])}">
+                    ${_("Profile")}
                   </a>
                 </li>
+
               % endif
             </ul>
           </nav>
-- 
GitLab