From 16e939fe2cc63bb4748748b7c7e8824cb4872737 Mon Sep 17 00:00:00 2001 From: Sujith Haridasan Date: Tue, 24 Aug 2021 20:28:36 +0530 Subject: [PATCH] MDL-72110 core_navigation: home page preference Admin should respect the home page preference set just like any other user. Also when user preference is set to dashboard, the home points to the dashboard and the dashboard should become "Site home" which would point to Site home. --- lib/classes/navigation/views/primary.php | 22 +++++++++++-------- lib/tests/navigation/views/primary_test.php | 4 ++-- login/lib.php | 2 +- user/tests/behat/set_default_homepage.feature | 17 +++++++++----- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/classes/navigation/views/primary.php b/lib/classes/navigation/views/primary.php index c30b6780da1..c6373a47f45 100644 --- a/lib/classes/navigation/views/primary.php +++ b/lib/classes/navigation/views/primary.php @@ -35,15 +35,19 @@ class primary extends view { return; } $this->id = 'primary_navigation'; - if (get_home_page() == HOMEPAGE_SITE && isloggedin() && !isguestuser()) { - $this->add(get_string('home'), new \moodle_url('/'), self::TYPE_SYSTEM, - null, 'home', new \pix_icon('i/home', '')); - } - - // Add the dashboard link. - if (isloggedin() && !isguestuser()) { // Makes no sense if you aren't logged in. - $this->rootnodes['home'] = $this->add(get_string('myhome'), new \moodle_url('/my/'), - self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); + if (isloggedin() && !isguestuser()) { + $homepage = get_home_page(); + if ($homepage === HOMEPAGE_SITE) { + $this->add(get_string('home'), new \moodle_url('/'), self::TYPE_SYSTEM, + null, 'home', new \pix_icon('i/home', '')); + $this->rootnodes['home'] = $this->add(get_string('myhome'), new \moodle_url('/my/'), + self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); + } else if ($homepage === HOMEPAGE_MY) { + $this->add(get_string('myhome'), new \moodle_url('/my/'), self::TYPE_SYSTEM, + null, 'home', new \pix_icon('i/home', '')); + $this->rootnodes['home'] = $this->add(get_string('sitehome'), new \moodle_url('/'), + self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); + } } // Add a dummy mycourse link to a mycourses page. diff --git a/lib/tests/navigation/views/primary_test.php b/lib/tests/navigation/views/primary_test.php index 2da990d8afa..c53d43502ed 100644 --- a/lib/tests/navigation/views/primary_test.php +++ b/lib/tests/navigation/views/primary_test.php @@ -59,8 +59,8 @@ class primary_test extends \advanced_testcase { public function test_setting_initialise_provider() { return [ 'Testing as a guest user' => ['guest', ['courses']], - 'Testing as an admin' => ['admin', ['myhome', 'courses', 'siteadminnode']], - 'Testing as a regular user' => ['user', ['myhome', 'courses']] + 'Testing as an admin' => ['admin', ['home', 'myhome', 'courses', 'siteadminnode']], + 'Testing as a regular user' => ['user', ['home', 'myhome', 'courses']] ]; } } diff --git a/login/lib.php b/login/lib.php index a00d1438da3..2a90aa46d1e 100644 --- a/login/lib.php +++ b/login/lib.php @@ -352,7 +352,7 @@ function core_login_get_return_url() { if ($urltogo == ($CFG->wwwroot . '/')) { $homepage = get_home_page(); // Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my. - if ($homepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) { + if ($homepage === HOMEPAGE_MY && !isguestuser()) { if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') { $urltogo = $CFG->wwwroot.'/my/'; } diff --git a/user/tests/behat/set_default_homepage.feature b/user/tests/behat/set_default_homepage.feature index a82add7237e..917a007810f 100644 --- a/user/tests/behat/set_default_homepage.feature +++ b/user/tests/behat/set_default_homepage.feature @@ -20,6 +20,11 @@ Feature: Set the site home page and dashboard as the default home page Given I log in as "admin" And I am on site homepage And I turn editing mode on + And I add the "Navigation" block if not present + And I configure the "Navigation" block + And I set the following fields to these values: + | Page contexts | Display throughout the entire site | + And I press "Save changes" And I add the "Administration" block if not present And I configure the "Administration" block And I set the following fields to these values: @@ -31,16 +36,16 @@ Feature: Set the site home page and dashboard as the default home page And I am on site homepage And I follow "Make this my home page" And I should not see "Make this my home page" -# The following lines should be changed once MDL-72110 is resolved. -# And I am on "Course 1" course homepage -# And "Home" "text" should exist in the ".breadcrumb" "css_element" + And I am on "Course 1" course homepage + And I should see "Home" in the "Navigation" "block" + And I should not see "Site home" in the "Navigation" "block" And I am on site homepage And I follow "Dashboard" And I follow "Make this my home page" And I should not see "Make this my home page" -# The following lines should be changed once MDL-72110 is resolved. -# And I am on "Course 1" course homepage -# Then "Dashboard" "text" should exist in the ".breadcrumb" "css_element" + And I am on "Course 1" course homepage + Then I should not see "Home" in the "Navigation" "block" + And I should see "Site home" in the "Navigation" "block" Scenario: User cannot configure their preferred default home page unless allowed by admin Given I log in as "user1"