diff --git a/index.php b/index.php index b2a3d4eec13..626dc504937 100644 --- a/index.php +++ b/index.php @@ -74,6 +74,7 @@ if (get_home_page() != HOMEPAGE_SITE) { if (optional_param('setdefaulthome', false, PARAM_BOOL)) { set_user_preference('user_home_page_preference', HOMEPAGE_SITE); } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) { + // At this point, dashboard is enabled so we don't need to check for it (otherwise, get_home_page() won't return it). redirect($CFG->wwwroot .'/my/'); } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) && $redirect === 1) { redirect($CFG->wwwroot .'/my/courses.php'); diff --git a/lib/classes/user.php b/lib/classes/user.php index fba83aa0f2d..366165ee87a 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -933,6 +933,8 @@ class core_user { * @return void */ protected static function fill_preferences_cache() { + global $CFG; + if (self::$preferencescache !== null) { return; } @@ -966,13 +968,22 @@ class core_user { global $USER; return $USER->id == $user->id && has_capability('moodle/blog:view', context_system::instance()); }); - $preferences['user_home_page_preference'] = array('type' => PARAM_INT, 'null' => NULL_ALLOWED, 'default' => HOMEPAGE_MY, - 'choices' => array(HOMEPAGE_SITE, HOMEPAGE_MY, HOMEPAGE_MYCOURSES), + + $choices = [HOMEPAGE_SITE]; + if (!empty($CFG->enabledashboard)) { + $choices[] = HOMEPAGE_MY; + } + $choices[] = HOMEPAGE_MYCOURSES; + $preferences['user_home_page_preference'] = [ + 'type' => PARAM_INT, + 'null' => NULL_ALLOWED, + 'default' => get_default_home_page(), + 'choices' => $choices, 'permissioncallback' => function ($user, $preferencename) { global $CFG; return (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)); } - ); + ]; // Core components that may want to define their preferences. // List of core components implementing callback is hardcoded here for performance reasons. diff --git a/lib/tests/behat/enabledashboard.feature b/lib/tests/behat/enabledashboard.feature new file mode 100644 index 00000000000..b21d531fb46 --- /dev/null +++ b/lib/tests/behat/enabledashboard.feature @@ -0,0 +1,21 @@ +@core +Feature: Enable dashboard setting + In order to hide/show dashboard in navigation + As an administrator + I can enable or disable it + + Scenario: Hide setting when dashboard is disabled + Given the following config values are set as admin: + | enabledashboard | 0 | +# 2 = User preference. + | defaulthomepage | 2 | + When I log in as "admin" + And I navigate to "Appearance > Navigation" in site administration + Then the field "Enable dashboard" matches value "0" + And I should not see "Allow guest access to Dashboard" + And I should not see "Dashboard" in the "Start page for users" "select" + And I follow "Appearance" + And I should not see "Default Dashboard page" + And I follow "Preferences" in the user menu + And I follow "Start page" + And I should not see "Dashboard" in the "Start page" "select" diff --git a/user/classes/form/defaulthomepage_form.php b/user/classes/form/defaulthomepage_form.php index f3c9f00bffc..ac67614d8db 100644 --- a/user/classes/form/defaulthomepage_form.php +++ b/user/classes/form/defaulthomepage_form.php @@ -42,20 +42,22 @@ class defaulthomepage_form extends \moodleform { * Define the form. */ public function definition () { + global $CFG; + $mform = $this->_form; $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); - $options = [ - HOMEPAGE_SITE => new lang_string('site'), - HOMEPAGE_MY => new lang_string('mymoodle', 'admin'), - HOMEPAGE_MYCOURSES => new lang_string('mycourses', 'admin'), - ]; + $options = [HOMEPAGE_SITE => new lang_string('home')]; + if (!empty($CFG->enabledashboard)) { + $options[HOMEPAGE_MY] = new lang_string('mymoodle', 'admin'); + } + $options[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin'); $mform->addElement('select', 'defaulthomepage', get_string('defaulthomepageuser'), $options); $mform->addHelpButton('defaulthomepage', 'defaulthomepageuser'); - $mform->setDefault('defaulthomepage', HOMEPAGE_MY); + $mform->setDefault('defaulthomepage', get_default_home_page()); $this->add_action_buttons(true, get_string('savechanges')); } diff --git a/user/defaulthomepage.php b/user/defaulthomepage.php index 91bcfe9503c..2cbe953eed9 100644 --- a/user/defaulthomepage.php +++ b/user/defaulthomepage.php @@ -34,7 +34,12 @@ list($user, $course) = useredit_setup_preference_page($userid, SITEID); $form = new core_user\form\defaulthomepage_form(); -$user->defaulthomepage = get_user_preferences('user_home_page_preference', HOMEPAGE_MY, $user); +$defaulthomepage = get_default_home_page(); +$user->defaulthomepage = get_user_preferences('user_home_page_preference', $defaulthomepage, $user); +if (empty($CFG->enabledashboard) && $user->defaulthomepage == HOMEPAGE_MY) { + // If the user was using the dashboard but it's disabled, return the default home page. + $user->defaulthomepage = $defaulthomepage; +} $form->set_data($user); $redirect = new moodle_url('/user/preferences.php', ['userid' => $user->id]); diff --git a/user/tests/behat/set_default_homepage.feature b/user/tests/behat/set_default_homepage.feature index eeb51b72c78..53c2ab4a757 100644 --- a/user/tests/behat/set_default_homepage.feature +++ b/user/tests/behat/set_default_homepage.feature @@ -71,6 +71,6 @@ Feature: Set the site home page and dashboard as the default home page Examples: | preference | breadcrumb | - | Site | Home | + | Home | Home | | Dashboard | Dashboard | | My courses | My courses |