Merge branch 'MDL-73233-master' of https://github.com/sarjona/moodle
This commit is contained in:
@@ -186,15 +186,29 @@ reports,core_reportbuilder|/reportbuilder/index.php',
|
||||
|
||||
// Navigation settings
|
||||
$temp = new admin_settingpage('navigation', new lang_string('navigation'));
|
||||
$choices = array(
|
||||
HOMEPAGE_SITE => new lang_string('site'),
|
||||
HOMEPAGE_MY => new lang_string('mymoodle', 'admin'),
|
||||
HOMEPAGE_MYCOURSES => new lang_string('mycourses', 'admin'),
|
||||
HOMEPAGE_USER => new lang_string('userpreference', 'admin')
|
||||
);
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'enabledashboard',
|
||||
new lang_string('enabledashboard', 'admin'),
|
||||
new lang_string('enabledashboard_help', 'admin'),
|
||||
1
|
||||
));
|
||||
|
||||
$choices = [HOMEPAGE_SITE => new lang_string('home')];
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$choices[HOMEPAGE_MY] = new lang_string('mymoodle', 'admin');
|
||||
}
|
||||
$choices[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin');
|
||||
$choices[HOMEPAGE_USER] = new lang_string('userpreference', 'admin');
|
||||
$temp->add(new admin_setting_configselect('defaulthomepage', new lang_string('defaulthomepage', 'admin'),
|
||||
new lang_string('configdefaulthomepage', 'admin'), HOMEPAGE_MY, $choices));
|
||||
$temp->add(new admin_setting_configcheckbox('allowguestmymoodle', new lang_string('allowguestmymoodle', 'admin'), new lang_string('configallowguestmymoodle', 'admin'), 1));
|
||||
new lang_string('configdefaulthomepage', 'admin'), get_default_home_page(), $choices));
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'allowguestmymoodle',
|
||||
new lang_string('allowguestmymoodle', 'admin'),
|
||||
new lang_string('configallowguestmymoodle', 'admin'),
|
||||
1
|
||||
));
|
||||
}
|
||||
$temp->add(new admin_setting_configcheckbox('navshowfullcoursenames', new lang_string('navshowfullcoursenames', 'admin'), new lang_string('navshowfullcoursenames_help', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowcategories', new lang_string('navshowcategories', 'admin'), new lang_string('confignavshowcategories', 'admin'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0));
|
||||
@@ -237,9 +251,11 @@ reports,core_reportbuilder|/reportbuilder/index.php',
|
||||
$temp->add(new admin_setting_configcheckbox('doctonewwindow', new lang_string('doctonewwindow', 'admin'), new lang_string('configdoctonewwindow', 'admin'), 0));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
$temp = new admin_externalpage('mypage', new lang_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php',
|
||||
'moodle/my:configsyspages');
|
||||
$ADMIN->add('appearance', $temp);
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
$temp = new admin_externalpage('mypage', new lang_string('mypage', 'admin'), $CFG->wwwroot . '/my/indexsys.php',
|
||||
'moodle/my:configsyspages');
|
||||
$ADMIN->add('appearance', $temp);
|
||||
}
|
||||
|
||||
$temp = new admin_externalpage('profilepage', new lang_string('myprofile', 'admin'), $CFG->wwwroot . '/user/profilesys.php',
|
||||
'moodle/my:configsyspages');
|
||||
|
||||
@@ -340,6 +340,10 @@ class api {
|
||||
$settings->coursegraceperiodbefore = $CFG->coursegraceperiodbefore;
|
||||
}
|
||||
|
||||
if (empty($section) || $section === 'navigation') {
|
||||
$settings->enabledashboard = $CFG->enabledashboard;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
|
||||
@@ -233,6 +233,8 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$expected[] = ['name' => 'coursegraceperiodafter', 'value' => $CFG->coursegraceperiodafter];
|
||||
$expected[] = ['name' => 'coursegraceperiodbefore', 'value' => $CFG->coursegraceperiodbefore];
|
||||
|
||||
$expected[] = ['name' => 'enabledashboard', 'value' => $CFG->enabledashboard];
|
||||
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
$this->assertEquals($expected, $result['settings']);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Information provided here is intended especially for developers.
|
||||
|
||||
* The function tool_mobile\api::get_qrlogin_key() now requires as parameter an object with all the mobile plugin settings.
|
||||
* The tool_mobile_external::get_config external function now returns the tool_mobile_autologinmintimebetweenreq setting.
|
||||
* External function tool_mobile::get_config now returns the enabledashboard setting.
|
||||
|
||||
=== 3.7 ===
|
||||
|
||||
@@ -28,4 +29,3 @@ Information provided here is intended especially for developers.
|
||||
|
||||
* External function tool_mobile::get_public_config now returns the mobilecssurl field (Mobile custom CSS theme).
|
||||
* External function tool_mobile::get_public_config now returns the identityproviders field (list of external identity providers).
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class select_page implements \renderable, \templatable {
|
||||
return (object) [
|
||||
'name' => $this->importinfo->get_resource()->get_name(),
|
||||
'type' => $this->importinfo->get_config()->type,
|
||||
'cancellink' => new \moodle_url('/my'),
|
||||
'cancellink' => new \moodle_url('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
if (!has_capability('moodle/site:config',
|
||||
context_system::instance()) and !empty($CFG->defaulthomepage) and !isguestuser()) {
|
||||
if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
|
||||
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
|
||||
if ($CFG->defaulthomepage == HOMEPAGE_MY && !empty($CFG->enabledashboard)) {
|
||||
$urltogo = $CFG->wwwroot.'/my/';
|
||||
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) {
|
||||
$urltogo = $CFG->wwwroot.'/my/courses.php';
|
||||
@@ -99,5 +99,3 @@
|
||||
} else {
|
||||
print_error('shib_not_set_up_error', 'auth_shibboleth', '', $readmeurl);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -104,3 +104,24 @@ Feature: View my courses in navigation block
|
||||
And I should not see "c2" in the "Navigation" "block"
|
||||
And I should see "c31" in the "Navigation" "block"
|
||||
And I should not see "c32" in the "Navigation" "block"
|
||||
|
||||
@javascript
|
||||
Scenario: The course limit setting is applied in the navigation block
|
||||
Given the following config values are set as admin:
|
||||
| navcourselimit | 2 |
|
||||
And I log in as "student1"
|
||||
And I should see "More..." in the "Navigation" "block"
|
||||
When I click on "More..." "link" in the "Navigation" "block"
|
||||
Then I should see "My courses" in the "page-header" "region"
|
||||
|
||||
@javascript
|
||||
Scenario: The dashboard node is not displayed in the navigation block when it is disabled
|
||||
Given the following config values are set as admin:
|
||||
| enabledashboard | 0 |
|
||||
When I log in as "student1"
|
||||
Then I should not see "Dashboard" in the "Navigation" "block"
|
||||
# Re-enable dashboard and check then it's displayed in the navigation block.
|
||||
And the following config values are set as admin:
|
||||
| enabledashboard | 1 |
|
||||
And I reload the page
|
||||
And I should see "Dashboard" in the "Navigation" "block"
|
||||
|
||||
+1
-1
@@ -1988,7 +1988,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
// There are more enrolled courses than we can display, display link to 'My courses'.
|
||||
$courses = array_slice($courses, 0, $CFG->frontpagecourselimit, true);
|
||||
$chelper->set_courses_display_options(array(
|
||||
'viewmoreurl' => new moodle_url('/my/'),
|
||||
'viewmoreurl' => new moodle_url('/my/courses.php'),
|
||||
'viewmoretext' => new lang_string('mycourses')
|
||||
));
|
||||
} else if (core_course_category::top()->is_uservisible()) {
|
||||
|
||||
@@ -60,3 +60,20 @@ Feature: Site home displays items in different modes
|
||||
And I should not see "Category A child" in the "region-main" "region"
|
||||
And I toggle "Category A" category children visibility in frontpage
|
||||
And I should see "Course 11 1" in the "region-main" "region"
|
||||
|
||||
Scenario: Displays Enrolled users in frontpage
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email | profile_field_frog |
|
||||
| user1 | User | One | one@example.com | Kermit |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| admin | COURSE1_1 | student |
|
||||
| admin | COURSE2_1 | student |
|
||||
| admin | COURSE2_2 | student |
|
||||
And I set the following administration settings values:
|
||||
| Site home items when logged in | Enrolled courses |
|
||||
| frontpagecourselimit | 2 |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
When I click on "My courses" "link" in the "frontpage-course-list" "region"
|
||||
Then I should see "My courses" in the "page-header" "region"
|
||||
|
||||
@@ -138,8 +138,6 @@ switch ($mode) {
|
||||
// Change the navigation to point to the my grade node (If we are a student).
|
||||
if ($USER->id == $user->id) {
|
||||
require_once($CFG->dirroot . '/user/lib.php');
|
||||
// Make the dashboard active so that it shows up in the navbar correctly.
|
||||
$gradenode = $PAGE->settingsnav->find('dashboard', null)->make_active();
|
||||
// Get the correct 'Grades' url to point to.
|
||||
$activeurl = user_mygrades_url();
|
||||
$navbar = $PAGE->navbar->add(get_string('grades', 'grades'), $activeurl, navigation_node::TYPE_SETTING);
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -562,6 +562,8 @@ $string['enablecourserelativedates'] = 'Enable course relative dates';
|
||||
$string['enablecourserelativedates_desc'] = 'Allow courses to be set up to display dates relative to the user\'s start date in the course.';
|
||||
$string['enablecourserequests'] = 'Enable course requests';
|
||||
$string['enabled'] = 'Enabled';
|
||||
$string['enabledashboard'] = 'Enable dashboard';
|
||||
$string['enabledashboard_help'] = 'The Dashboard shows Timeline, Calendar and Recently accessed items by default. You can set a different default Dashboard for everyone and allow users to customise their own Dashboard.';
|
||||
$string['enabledevicedetection'] = 'Enable device detection';
|
||||
$string['enableglobalsearch'] = 'Enable global search';
|
||||
$string['enableglobalsearch_desc'] = 'If enabled, data will be indexed and synchronised by a scheduled task.';
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
$string['coursemanagementoptions'] = 'Course management options';
|
||||
$string['error:dashboardisdisabled'] = 'The dashboard has been disabled by the administrator.';
|
||||
$string['mymoodle'] = 'Dashboard';
|
||||
$string['nocourses'] = 'No course information to show.';
|
||||
$string['noguest'] = 'The Dashboard page is not available to guest users';
|
||||
|
||||
@@ -33,6 +33,8 @@ class primary extends view {
|
||||
* Initialise the primary navigation node
|
||||
*/
|
||||
public function initialise(): void {
|
||||
global $CFG;
|
||||
|
||||
if (during_initial_install() || $this->initialised) {
|
||||
return;
|
||||
}
|
||||
@@ -55,8 +57,8 @@ class primary extends view {
|
||||
}
|
||||
|
||||
// Add the dashboard link.
|
||||
$showmyhomenode = empty($this->page->theme->removedprimarynavitems) ||
|
||||
!in_array('myhome', $this->page->theme->removedprimarynavitems);
|
||||
$showmyhomenode = !empty($CFG->enabledashboard) && (empty($this->page->theme->removedprimarynavitems) ||
|
||||
!in_array('myhome', $this->page->theme->removedprimarynavitems));
|
||||
if ($showmyhomenode) {
|
||||
$this->add(get_string('myhome'), new \moodle_url('/my/'),
|
||||
self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', ''));
|
||||
|
||||
+14
-3
@@ -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.
|
||||
|
||||
+25
-2
@@ -10366,17 +10366,40 @@ function get_home_page() {
|
||||
global $CFG;
|
||||
|
||||
if (isloggedin() && !isguestuser() && !empty($CFG->defaulthomepage)) {
|
||||
// If dashboard is disabled, home will be set to default page.
|
||||
$defaultpage = get_default_home_page();
|
||||
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
|
||||
return HOMEPAGE_MY;
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
return HOMEPAGE_MY;
|
||||
} else {
|
||||
return $defaultpage;
|
||||
}
|
||||
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) {
|
||||
return HOMEPAGE_MYCOURSES;
|
||||
} else {
|
||||
return (int)get_user_preferences('user_home_page_preference', HOMEPAGE_MY);
|
||||
$userhomepage = (int) get_user_preferences('user_home_page_preference', $defaultpage);
|
||||
if (empty($CFG->enabledashboard) && $userhomepage == HOMEPAGE_MY) {
|
||||
// If the user was using the dashboard but it's disabled, return the default home page.
|
||||
$userhomepage = $defaultpage;
|
||||
}
|
||||
return $userhomepage;
|
||||
}
|
||||
}
|
||||
return HOMEPAGE_SITE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default home page to display if current one is not defined or can't be applied.
|
||||
* The default behaviour is to return Dashboard if it's enabled or My courses page if it isn't.
|
||||
*
|
||||
* @return int The default home page.
|
||||
*/
|
||||
function get_default_home_page(): int {
|
||||
global $CFG;
|
||||
|
||||
return !empty($CFG->enabledashboard) ? HOMEPAGE_MY : HOMEPAGE_MYCOURSES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of a course to be displayed when showing a list of courses.
|
||||
* By default this is just $course->fullname but user can configure it. The
|
||||
|
||||
+22
-16
@@ -1407,9 +1407,12 @@ class global_navigation extends navigation_node {
|
||||
if ($defaulthomepage == HOMEPAGE_SITE) {
|
||||
// The home element should be my moodle because the root element is the site
|
||||
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', ''));
|
||||
$this->rootnodes['home']->showinflatnavigation = true;
|
||||
if (!empty($CFG->enabledashboard)) {
|
||||
// Only add dashboard to home if it's enabled.
|
||||
$this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'),
|
||||
self::TYPE_SETTING, null, 'myhome', new pix_icon('i/dashboard', ''));
|
||||
$this->rootnodes['home']->showinflatnavigation = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The home element should be the site because the root node is my moodle
|
||||
@@ -3289,7 +3292,7 @@ class global_navigation extends navigation_node {
|
||||
// Show a link to the course page if there are more courses the user is enrolled in.
|
||||
if ($showmorelinkinnav || $showmorelinkinflatnav) {
|
||||
// Adding hash to URL so the link is not highlighted in the navigation when clicked.
|
||||
$url = new moodle_url('/my/');
|
||||
$url = new moodle_url('/my/courses.php');
|
||||
$parent = $this->rootnodes['mycourses'];
|
||||
$coursenode = $parent->add(get_string('morenavigationlinks'), $url, self::TYPE_CUSTOM, null, self::COURSE_INDEX_PAGE);
|
||||
|
||||
@@ -3360,7 +3363,13 @@ class global_navigation_for_ajax extends global_navigation {
|
||||
|
||||
$this->rootnodes = array();
|
||||
$this->rootnodes['site'] = $this->add_course($SITE);
|
||||
$this->rootnodes['mycourses'] = $this->add(get_string('mycourses'), new moodle_url('/my'), self::TYPE_ROOTNODE, null, 'mycourses');
|
||||
$this->rootnodes['mycourses'] = $this->add(
|
||||
get_string('mycourses'),
|
||||
new moodle_url('/my/courses.php'),
|
||||
self::TYPE_ROOTNODE,
|
||||
null,
|
||||
'mycourses'
|
||||
);
|
||||
$this->rootnodes['courses'] = $this->add(get_string('courses'), null, self::TYPE_ROOTNODE, null, 'courses');
|
||||
// The courses branch is always displayed, and is always expandable (although may be empty).
|
||||
// This mimicks what is done during {@link global_navigation::initialise()}.
|
||||
@@ -5015,14 +5024,11 @@ class settings_navigation extends navigation_node {
|
||||
|
||||
// Add a user setting branch.
|
||||
if ($gstitle == 'usercurrentsettings') {
|
||||
$dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
|
||||
$mainpage = $this->add(get_string('home'), new moodle_url('/'), self::TYPE_CONTAINER, null, 'site');
|
||||
|
||||
// This should be set to false as we don't want to show this to the user. It's only for generating the correct
|
||||
// breadcrumb.
|
||||
$dashboard->display = false;
|
||||
$homepage = get_home_page();
|
||||
if (($homepage == HOMEPAGE_MY || $homepage == HOMEPAGE_MYCOURSES)) {
|
||||
$dashboard->mainnavonly = true;
|
||||
}
|
||||
$mainpage->display = false;
|
||||
|
||||
$iscurrentuser = ($user->id == $USER->id);
|
||||
|
||||
@@ -5036,7 +5042,7 @@ class settings_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
// Add the user profile to the dashboard.
|
||||
$profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php',
|
||||
$profilenode = $mainpage->add(get_string('profile'), new moodle_url('/user/profile.php',
|
||||
array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
|
||||
|
||||
if (!empty($CFG->navadduserpostslinks)) {
|
||||
@@ -5081,14 +5087,14 @@ class settings_navigation extends navigation_node {
|
||||
$messageargs['user2'] = $user->id;
|
||||
}
|
||||
$url = new moodle_url('/message/index.php', $messageargs);
|
||||
$dashboard->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
|
||||
$mainpage->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
|
||||
}
|
||||
|
||||
// Add the "My private files" link.
|
||||
// This link doesn't have a unique display for course context so only display it under the user's profile.
|
||||
if ($issitecourse && $iscurrentuser && has_capability('moodle/user:manageownfiles', $usercontext)) {
|
||||
$url = new moodle_url('/user/files.php');
|
||||
$dashboard->add(get_string('privatefiles'), $url, self::TYPE_SETTING, null, 'privatefiles');
|
||||
$mainpage->add(get_string('privatefiles'), $url, self::TYPE_SETTING, null, 'privatefiles');
|
||||
}
|
||||
|
||||
// Add a node to view the users notes if permitted.
|
||||
@@ -5110,7 +5116,7 @@ class settings_navigation extends navigation_node {
|
||||
} else { // Otherwise we are in a course and should redirect to the user grade report (Activity report version).
|
||||
$url = new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $user->id));
|
||||
}
|
||||
$dashboard->add(get_string('grades', 'grades'), $url, self::TYPE_SETTING, null, 'mygrades');
|
||||
$mainpage->add(get_string('grades', 'grades'), $url, self::TYPE_SETTING, null, 'mygrades');
|
||||
}
|
||||
|
||||
// Let plugins hook into user navigation.
|
||||
@@ -5124,7 +5130,7 @@ class settings_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
$usersetting = navigation_node::create(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
|
||||
$dashboard->add_node($usersetting);
|
||||
$mainpage->add_node($usersetting);
|
||||
} else {
|
||||
$usersetting = $this->add(get_string('preferences', 'moodle'), $prefurl, self::TYPE_CONTAINER, null, $key);
|
||||
$usersetting->display = false;
|
||||
|
||||
@@ -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"
|
||||
@@ -5196,4 +5196,143 @@ EOF;
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_home_page() method.
|
||||
*
|
||||
* @dataProvider get_home_page_provider
|
||||
* @param string $user Whether the user is logged, guest or not logged.
|
||||
* @param int $expected Expected value after calling the get_home_page method.
|
||||
* @param int $defaulthomepage The $CFG->defaulthomepage setting value.
|
||||
* @param int $enabledashboard Whether the dashboard should be enabled or not.
|
||||
* @param int $userpreference User preference for the home page setting.
|
||||
* @covers ::get_home_page
|
||||
*/
|
||||
public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
|
||||
?int $userpreference = null) {
|
||||
global $CFG, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
if ($user == 'guest') {
|
||||
$this->setGuestUser();
|
||||
} else if ($user == 'logged') {
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
}
|
||||
|
||||
if (isset($defaulthomepage)) {
|
||||
$CFG->defaulthomepage = $defaulthomepage;
|
||||
}
|
||||
if (isset($enabledashboard)) {
|
||||
$CFG->enabledashboard = $enabledashboard;
|
||||
}
|
||||
|
||||
if ($USER) {
|
||||
set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id);
|
||||
}
|
||||
|
||||
$homepage = get_home_page();
|
||||
$this->assertEquals($expected, $homepage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for get_home_page checks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_home_page_provider(): array {
|
||||
return [
|
||||
'No logged user' => [
|
||||
'user' => 'nologged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
],
|
||||
'Guest user' => [
|
||||
'user' => 'guest',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
],
|
||||
'Logged user. Dashboard set as default home page and enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_MY,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. Dashboard set as default home page but disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MY,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. My courses set as default home page with dashboard enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. My courses set as default home page with dashboard disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. Site set as default home page with dashboard enabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
'defaulthomepage' => HOMEPAGE_SITE,
|
||||
'enabledashboard' => 1,
|
||||
],
|
||||
'Logged user. Site set as default home page with dashboard disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
'defaulthomepage' => HOMEPAGE_SITE,
|
||||
'enabledashboard' => 0,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard enabled and user preference set to dashboard' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 1,
|
||||
'userpreference' => HOMEPAGE_MY,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard disabled and user preference set to dashboard' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 0,
|
||||
'userpreference' => HOMEPAGE_MY,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard enabled and user preference set to my courses' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 1,
|
||||
'userpreference' => HOMEPAGE_MYCOURSES,
|
||||
],
|
||||
'Logged user. User preference set as default page with dashboard disabled and user preference set to my courses' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MYCOURSES,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 0,
|
||||
'userpreference' => HOMEPAGE_MYCOURSES,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_default_home_page() method.
|
||||
*
|
||||
* @covers ::get_default_home_page
|
||||
*/
|
||||
public function test_get_default_home_page() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$CFG->enabledashboard = 1;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MY, $default);
|
||||
|
||||
$CFG->enabledashboard = 0;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MYCOURSES, $default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,6 +249,8 @@ value to get the list of blocks that won't be displayed for a theme.
|
||||
`get_template_name(\renderer_base): string` function which will inform the default render() function with a template
|
||||
name.
|
||||
* The parameter $modinfo of the get_data method in completion_info class has been deprecated and is not used anymore.
|
||||
* A new method, get_default_home_page(), has been added to moodlelib to get the default home page to display if current one is not
|
||||
defined or can't be applied.
|
||||
|
||||
=== 3.11.4 ===
|
||||
* A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function.
|
||||
|
||||
@@ -52,6 +52,18 @@ if ($hassiteconfig && moodle_needs_upgrading()) {
|
||||
|
||||
$strmymoodle = get_string('myhome');
|
||||
|
||||
if (empty($CFG->enabledashboard)) {
|
||||
// Dashboard is disabled, so the /my page shouldn't be displayed.
|
||||
$defaultpage = get_default_home_page();
|
||||
if ($defaultpage == HOMEPAGE_MYCOURSES) {
|
||||
// If default page is set to "My courses", redirect to it.
|
||||
redirect(new moodle_url('/my/courses.php'));
|
||||
} else {
|
||||
// Otherwise, raise an exception to inform the dashboard is disabled.
|
||||
throw new moodle_exception('error:dashboardisdisabled', 'my');
|
||||
}
|
||||
}
|
||||
|
||||
if (isguestuser()) { // Force them to see system default, no editing allowed
|
||||
// If guests are not allowed my moodle, send them to front page.
|
||||
if (empty($CFG->allowguestmymoodle)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ Feature: Primary navigation
|
||||
|
||||
Examples:
|
||||
| userpreference | homepage |
|
||||
| Site | Home |
|
||||
| Home | Home |
|
||||
| Dashboard | Dashboard |
|
||||
| My courses | My courses |
|
||||
|
||||
@@ -63,3 +63,58 @@ Feature: Primary navigation
|
||||
And I should not see "Dashboard" in the ".primary-navigation" "css_element"
|
||||
And I should not see "My courses" in the ".primary-navigation" "css_element"
|
||||
And I should not see "Site administration" in the ".primary-navigation" "css_element"
|
||||
|
||||
Scenario: Dashboard is not displayed in the primary navigation when it is disabled
|
||||
Given the following config values are set as admin:
|
||||
| enabledashboard | 0 |
|
||||
When I am on the "My courses" page logged in as "user1"
|
||||
Then I should not see "Dashboard"
|
||||
And the following config values are set as admin:
|
||||
| enabledashboard | 1 |
|
||||
# We need to reload the page to skip the "Welcome, xxxx!" and display the real page title.
|
||||
And I reload the page
|
||||
And I should see "Dashboard"
|
||||
|
||||
Scenario: Start page when default home is dashboard but dashboard is disabled
|
||||
Given the following config values are set as admin:
|
||||
| enabledashboard | 0 |
|
||||
# 1 = Dashboard.
|
||||
| defaulthomepage | 1 |
|
||||
When I log in as "admin"
|
||||
# We need to reload the page to skip the "Welcome, xxxx!" and display the real page title.
|
||||
And I reload the page
|
||||
Then I should not see "Dashboard" in the "page-header" "region"
|
||||
And I should see "My courses" in the "page-header" "region"
|
||||
And I log out
|
||||
# Check dashboard is displayed when it's re-enabled.
|
||||
And the following config values are set as admin:
|
||||
| enabledashboard | 1 |
|
||||
And I log in as "admin"
|
||||
# We need to reload the page to skip the "Welcome, xxxx!" and display the real page title.
|
||||
And I reload the page
|
||||
And I should see "Dashboard" in the "page-header" "region"
|
||||
And I should not see "My courses" in the "page-header" "region"
|
||||
|
||||
Scenario: Start page when default home is user preference set to dashboard but dashboard is disabled
|
||||
Given the following config values are set as admin:
|
||||
| enabledashboard | 0 |
|
||||
# 2 = User preference.
|
||||
| defaulthomepage | 2 |
|
||||
# 1 = Dashboard.
|
||||
And the following "user preferences" exist:
|
||||
| user | preference | value |
|
||||
| admin | user_home_page_preference | 1 |
|
||||
When I log in as "admin"
|
||||
# We need to reload the page to skip the "Welcome, xxxx!" and display the real page title.
|
||||
And I reload the page
|
||||
Then I should not see "Dashboard"
|
||||
And I should see "My courses" in the "page-header" "region"
|
||||
And I log out
|
||||
# Check dashboard is displayed when it's re-enabled.
|
||||
And the following config values are set as admin:
|
||||
| enabledashboard | 1 |
|
||||
And I log in as "admin"
|
||||
# We need to reload the page to skip the "Welcome, xxxx!" and display the real page title.
|
||||
And I reload the page
|
||||
And I should see "Dashboard" in the "page-header" "region"
|
||||
And I should not see "My courses" in the "page-header" "region"
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -62,6 +62,7 @@ Feature: Set the site home page and dashboard as the default home page
|
||||
And I log out
|
||||
When I log in as "user1"
|
||||
And I follow "Preferences" in the user menu
|
||||
And I should see "Home" in the ".breadcrumb" "css_element"
|
||||
And I follow "Start page"
|
||||
And I set the field "Start page" to "<preference>"
|
||||
And I press "Save changes"
|
||||
@@ -71,6 +72,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 |
|
||||
|
||||
Reference in New Issue
Block a user