Merge branch 'MDL-87544-main-v2' of https://github.com/andimendunia/moodle
This commit is contained in:
@@ -155,6 +155,13 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp
|
||||
1
|
||||
));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'enablemycourses',
|
||||
new lang_string('enablemycourses', 'admin'),
|
||||
new lang_string('enablemycourses_help', 'admin'),
|
||||
0
|
||||
));
|
||||
|
||||
$choices = [];
|
||||
if (!isset($CFG->enablemyhome) || $CFG->enablemyhome) {
|
||||
$choices[HOMEPAGE_SITE] = new lang_string('home');
|
||||
@@ -162,7 +169,9 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp
|
||||
if (!isset($CFG->enabledashboard) || $CFG->enabledashboard) {
|
||||
$choices[HOMEPAGE_MY] = new lang_string('mymoodle', 'admin');
|
||||
}
|
||||
$choices[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin');
|
||||
if (!isset($CFG->enablemycourses) || $CFG->enablemycourses) {
|
||||
$choices[HOMEPAGE_MYCOURSES] = new lang_string('mycourses', 'admin');
|
||||
}
|
||||
$choices[HOMEPAGE_USER] = new lang_string('userpreference', 'admin');
|
||||
|
||||
// Allow hook callbacks to extend options.
|
||||
|
||||
@@ -6,7 +6,9 @@ Feature: Confirm that we can open multiple browser tabs
|
||||
|
||||
@javascript @_switch_window
|
||||
Scenario: Open multiple browser tabs
|
||||
Given the following "courses" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Course 1 | C1 |
|
||||
| Course 2 | C2 |
|
||||
|
||||
@@ -381,6 +381,7 @@ class api {
|
||||
if (empty($section) || $section === 'navigation') {
|
||||
$settings->enablemyhome = $CFG->enablemyhome ?? 1;
|
||||
$settings->enabledashboard = $CFG->enabledashboard;
|
||||
$settings->enablemycourses = $CFG->enablemycourses ?? 1;
|
||||
}
|
||||
|
||||
if (empty($section) || ($section === 'themesettings' || $section === 'themesettingsadvanced')) {
|
||||
|
||||
@@ -244,6 +244,7 @@ final class externallib_test extends \core_external\tests\externallib_testcase {
|
||||
|
||||
$expected[] = ['name' => 'enablemyhome', 'value' => $CFG->enablemyhome ?? 1];
|
||||
$expected[] = ['name' => 'enabledashboard', 'value' => $CFG->enabledashboard];
|
||||
$expected[] = ['name' => 'enablemycourses', 'value' => $CFG->enablemycourses ?? 1];
|
||||
$expected[] = ['name' => 'customusermenuitems', 'value' => $CFG->customusermenuitems];
|
||||
$expected[] = ['name' => 'timezone', 'value' => $CFG->timezone];
|
||||
$expected[] = ['name' => 'forcetimezone', 'value' => $CFG->forcetimezone];
|
||||
|
||||
@@ -269,6 +269,11 @@ class core_block_external extends external_api {
|
||||
$context = context_user::instance($userid);;
|
||||
self::validate_context($context);
|
||||
|
||||
// Accessing My courses blocks via the web service is not allowed when it is disabled.
|
||||
if ($params['mypage'] === MY_PAGE_COURSES && empty($CFG->enablemycourses)) {
|
||||
throw new moodle_exception('error:mycoursesisdisabled', 'my');
|
||||
}
|
||||
|
||||
$currentpage = null;
|
||||
if ($params['mypage'] === MY_PAGE_DEFAULT) {
|
||||
$currentpage = my_get_page($userid);
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: The my overview block allows admins to easily configure the students' c
|
||||
I can configure the appearance of the my overview block
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "categories" exist:
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
Feature: The my overview block allows users to group courses by custom fields
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "custom field categories" exist:
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: The my overview block allows users to easily access their courses
|
||||
I can add the my overview block to my dashboard
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "categories" exist:
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: The my overview block allows users to favourite their courses
|
||||
I can add the my overview block to my dashboard
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "courses" exist:
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: The my overview block allows users to hide their courses
|
||||
I can add the my overview block to my dashboard
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "courses" exist:
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
Feature: The my overview block allows users to persistence of their page limits
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "courses" exist:
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
Feature: My overview block pagination
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "courses" exist:
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Course overview block show users their progress on courses
|
||||
I can see the progress percentage of the courses I am enrolled in
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
|
||||
| student1 | Student | 1 | student1@example.com | S1 |
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
Feature: My overview block searching
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
| student2 | Student | Y | student2@example.com | S2 |
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: The my overview block allows users to easily sort their courses
|
||||
I can choose from a selection of sorting options
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| student1 | Student | X | student1@example.com | S1 |
|
||||
And the following "categories" exist:
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Zero state on my overview block
|
||||
I should see the proper information based on my capabilities
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| user | User | X | user@example.com | U1 |
|
||||
| manager | Manager | X | manager@example.com | M1 |
|
||||
|
||||
@@ -15,6 +15,7 @@ Feature: Test that admin can see related nodes in Administration block
|
||||
| Course 1 | c1 | cat1 | 1 |
|
||||
And the following config values are set as admin:
|
||||
| unaddableblocks | | theme_boost |
|
||||
| enablemycourses | 1 | |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I turn editing mode on
|
||||
|
||||
@@ -37,6 +37,7 @@ Feature: Expand the courses nodes within the navigation block
|
||||
And the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| navshowallcourses | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
And I turn editing mode on
|
||||
|
||||
@@ -22,6 +22,7 @@ Feature: Displaying the link to the Participants page
|
||||
And I turn editing mode on
|
||||
And the following config values are set as admin:
|
||||
| unaddableblocks | | theme_boost|
|
||||
| enablemycourses | 1 | |
|
||||
And I add the "Navigation" block if not present
|
||||
And I configure the "Navigation" block
|
||||
And I set the following fields to these values:
|
||||
|
||||
@@ -6,7 +6,8 @@ Feature: View my courses in navigation block
|
||||
|
||||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| enablemyhome | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Starred courses
|
||||
I must be able to add them to the Starred courses block
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "courses" exist:
|
||||
|
||||
@@ -477,9 +477,12 @@ final class externallib_test extends \core_external\tests\externallib_testcase {
|
||||
* Test user get default dashboard blocks for my courses page.
|
||||
*/
|
||||
public function test_get_dashboard_blocks_my_courses(): void {
|
||||
global $PAGE, $DB;
|
||||
global $CFG, $PAGE, $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Ensure My courses is enabled for this test.
|
||||
$CFG->enablemycourses = 1;
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$PAGE->set_url('/my/index.php'); // Need this because some internal API calls require the $PAGE url to be set.
|
||||
|
||||
@@ -522,6 +525,28 @@ final class externallib_test extends \core_external\tests\externallib_testcase {
|
||||
$this->assertEquals(array_values($alldefaultblocksordered), $returnedblocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that requesting My courses blocks when enablemycourses is disabled throws an exception.
|
||||
*
|
||||
* @covers \core_block_external::get_dashboard_blocks
|
||||
*/
|
||||
public function test_get_dashboard_blocks_my_courses_disabled(): void {
|
||||
global $CFG, $PAGE;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$PAGE->set_url('/my/index.php');
|
||||
|
||||
$this->setUser($user);
|
||||
|
||||
// Disable My courses.
|
||||
$CFG->enablemycourses = 0;
|
||||
|
||||
$this->expectException('moodle_exception');
|
||||
$this->expectExceptionMessage(get_string('error:mycoursesisdisabled', 'my'));
|
||||
core_block_external::get_dashboard_blocks($user->id, false, MY_PAGE_COURSES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user passing the wrong page type and getting an exception.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Course completion state should match completion criteria
|
||||
I need to see the appropriate completion information on course and dashboard pages
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email | idnumber |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
|
||||
| student1 | Student | 1 | student1@example.com | S1 |
|
||||
|
||||
@@ -6,7 +6,8 @@ Feature: Site home displays items in different modes
|
||||
|
||||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| enablemyhome | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And the following "categories" exist:
|
||||
| name | category | idnumber |
|
||||
| Category A | 0 | CATA |
|
||||
|
||||
@@ -614,6 +614,8 @@ $string['enableglobalsearch_desc'] = 'If enabled, data will be indexed and synch
|
||||
$string['enablegravatar'] = 'Enable Gravatar';
|
||||
$string['enablegravatar_help'] = 'When enabled Moodle will attempt to fetch a user profile picture from Gravatar if the user has not uploaded an image.';
|
||||
$string['enablemobilewebservice'] = 'Enable web services for mobile devices';
|
||||
$string['enablemycourses'] = 'Enable My Courses';
|
||||
$string['enablemycourses_help'] = 'If enabled, the My Courses page and its navigation link are available. If disabled, users are redirected to the configured \'Start page for users\'.';
|
||||
$string['enablemyhome'] = 'Enable Home';
|
||||
$string['enablemyhome_help'] = 'If enabled, the Home page and its navigation link are available. If disabled, users are redirected to the configured \'Start page for users\'.';
|
||||
$string['enablepdfexportfont'] = 'Enable PDF fonts';
|
||||
|
||||
+11
-10
@@ -22,26 +22,27 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addpage'] = 'Add page';
|
||||
$string['alldashboardswerereset'] = 'All Dashboard pages have been reset to default.';
|
||||
$string['allprofileswerereset'] = 'All profile pages have been reset to default.';
|
||||
$string['defaultpage'] = 'Default My Moodle page';
|
||||
$string['defaultprofilepage'] = 'Default profile page';
|
||||
$string['delpage'] = 'Delete page';
|
||||
$string['error:dashboardisdisabled'] = 'The Dashboard has been disabled by an administrator.';
|
||||
$string['error:mycoursesisdisabled'] = 'My courses has been disabled by an administrator.';
|
||||
$string['managepages'] = 'Manage pages';
|
||||
$string['mymoodle'] = 'Dashboard';
|
||||
$string['nocourses'] = 'No course information to show.';
|
||||
$string['noguest'] = 'The Dashboard page is not available to guest users';
|
||||
$string['pinblocks'] = 'Configure pinned blocks for my moodle';
|
||||
$string['pinblocksexplan'] = 'Any block settings you configure here will be visible (and non-editable) for any user of moodle on their \'My Moodle\' overview page.';
|
||||
$string['defaultpage'] = 'Default My Moodle page';
|
||||
$string['defaultprofilepage'] = 'Default profile page';
|
||||
$string['addpage'] = 'Add page';
|
||||
$string['alldashboardswerereset'] = 'All Dashboard pages have been reset to default.';
|
||||
$string['resettingdashboards'] = 'Resetting user dashboards to default...';
|
||||
$string['allprofileswerereset'] = 'All profile pages have been reset to default.';
|
||||
$string['delpage'] = 'Delete page';
|
||||
$string['managepages'] = 'Manage pages';
|
||||
$string['privacy:metadata:core_my:preference:user_home_page_preference'] = 'The user home page preference.';
|
||||
$string['reseterror'] = 'There was an error resetting your page';
|
||||
$string['reseteveryonesdashboard'] = 'Reset Dashboard for all users';
|
||||
$string['reseteveryonesprofile'] = 'Reset profile for all users';
|
||||
$string['resetpage'] = 'Reset page to default';
|
||||
$string['resetpageconfirm'] = 'Are you sure you want to reset the page to default?';
|
||||
$string['reseterror'] = 'There was an error resetting your page';
|
||||
$string['privacy:metadata:core_my:preference:user_home_page_preference'] = 'The user home page preference.';
|
||||
$string['resettingdashboards'] = 'Resetting user dashboards to default...';
|
||||
|
||||
// Deprecated since Moodle 4.5.
|
||||
$string['coursemanagementoptions'] = 'Course management options';
|
||||
|
||||
@@ -228,18 +228,21 @@ class global_navigation extends navigation_node {
|
||||
null,
|
||||
'currentcourse',
|
||||
);
|
||||
$this->rootnodes['mycourses'] = $this->add(
|
||||
get_string('mycourses'),
|
||||
new url('/my/courses.php'),
|
||||
self::TYPE_ROOTNODE,
|
||||
null,
|
||||
'mycourses',
|
||||
new pix_icon('i/course', ''),
|
||||
);
|
||||
// We do not need to show this node in the breadcrumbs if the default homepage is mycourses.
|
||||
// It will be automatically handled by the breadcrumb generator.
|
||||
if ($defaulthomepage == HOMEPAGE_MYCOURSES) {
|
||||
$this->rootnodes['mycourses']->mainnavonly = true;
|
||||
// Only add mycourses node if it's enabled.
|
||||
if (!empty($CFG->enablemycourses)) {
|
||||
$this->rootnodes['mycourses'] = $this->add(
|
||||
get_string('mycourses'),
|
||||
new url('/my/courses.php'),
|
||||
self::TYPE_ROOTNODE,
|
||||
null,
|
||||
'mycourses',
|
||||
new pix_icon('i/course', ''),
|
||||
);
|
||||
// We do not need to show this node in the breadcrumbs if the default homepage is mycourses.
|
||||
// It will be automatically handled by the breadcrumb generator.
|
||||
if ($defaulthomepage == HOMEPAGE_MYCOURSES) {
|
||||
$this->rootnodes['mycourses']->mainnavonly = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->rootnodes['courses'] = $this->add(
|
||||
@@ -269,8 +272,10 @@ class global_navigation extends navigation_node {
|
||||
|
||||
$this->rootnodes['currentcourse']->mainnavonly = true;
|
||||
if ($enrolledinanycourse) {
|
||||
$this->rootnodes['mycourses']->isexpandable = true;
|
||||
$this->rootnodes['mycourses']->showinflatnavigation = true;
|
||||
if (!empty($CFG->enablemycourses)) {
|
||||
$this->rootnodes['mycourses']->isexpandable = true;
|
||||
$this->rootnodes['mycourses']->showinflatnavigation = true;
|
||||
}
|
||||
if ($CFG->navshowallcourses) {
|
||||
// When we show all courses we need to show both the my courses and the regular courses branch.
|
||||
$this->rootnodes['courses']->isexpandable = true;
|
||||
@@ -278,7 +283,9 @@ class global_navigation extends navigation_node {
|
||||
} else {
|
||||
$this->rootnodes['courses']->isexpandable = true;
|
||||
}
|
||||
$this->rootnodes['mycourses']->forceopen = true;
|
||||
if (!empty($CFG->enablemycourses)) {
|
||||
$this->rootnodes['mycourses']->forceopen = true;
|
||||
}
|
||||
|
||||
$canviewcourseprofile = true;
|
||||
|
||||
@@ -1776,7 +1783,10 @@ class global_navigation extends navigation_node {
|
||||
$coursename = empty($CFG->navshowfullcoursenames) ? $shortname : $fullname;
|
||||
|
||||
if ($coursetype == self::COURSE_CURRENT) {
|
||||
if ($coursenode = $this->rootnodes['mycourses']->find($course->id, self::TYPE_COURSE)) {
|
||||
if (
|
||||
!empty($CFG->enablemycourses) &&
|
||||
($coursenode = $this->rootnodes['mycourses']->find($course->id, self::TYPE_COURSE))
|
||||
) {
|
||||
return $coursenode;
|
||||
} else {
|
||||
$coursetype = self::COURSE_OTHER;
|
||||
@@ -1795,7 +1805,7 @@ class global_navigation extends navigation_node {
|
||||
$parent = $this->rootnodes['currentcourse'];
|
||||
$url = new url('/course/view.php', ['id' => $course->id]);
|
||||
$canexpandcourse = $this->can_expand_course($course);
|
||||
} else if ($coursetype == self::COURSE_MY && !$forcegeneric) {
|
||||
} else if ($coursetype == self::COURSE_MY && !$forcegeneric && !empty($CFG->enablemycourses)) {
|
||||
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
|
||||
if (
|
||||
!empty($CFG->navshowmycoursecategories)
|
||||
@@ -2252,6 +2262,11 @@ class global_navigation extends navigation_node {
|
||||
protected function load_courses_enrolled() {
|
||||
global $CFG;
|
||||
|
||||
// Don't load courses if My Courses is disabled.
|
||||
if (empty($CFG->enablemycourses)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limit = (int) $CFG->navcourselimit;
|
||||
|
||||
$courses = enrol_get_my_courses('*');
|
||||
|
||||
@@ -66,8 +66,9 @@ class primary extends view {
|
||||
}
|
||||
|
||||
// Add the mycourses link.
|
||||
$showcoursesnode = empty($this->page->theme->removedprimarynavitems) ||
|
||||
!in_array('courses', $this->page->theme->removedprimarynavitems);
|
||||
$showcoursesnode = !empty($CFG->enablemycourses) &&
|
||||
(empty($this->page->theme->removedprimarynavitems) ||
|
||||
!in_array('courses', $this->page->theme->removedprimarynavitems));
|
||||
if ($showcoursesnode) {
|
||||
$this->add(get_string('mycourses'), new \moodle_url('/my/courses.php'), self::TYPE_ROOTNODE, null, 'mycourses');
|
||||
}
|
||||
|
||||
@@ -1760,5 +1760,16 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2026022700.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2026030600.01) {
|
||||
// For existing sites, enable My Courses by default to maintain current behavior.
|
||||
// New installs will have it disabled (default 0 in settings).
|
||||
$enablemycourses = get_config('core', 'enablemycourses');
|
||||
if ($enablemycourses === false) {
|
||||
set_config('enablemycourses', 1);
|
||||
}
|
||||
|
||||
upgrade_main_savepoint(true, 2026030600.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9919,7 +9919,7 @@ function get_home_page() {
|
||||
$homeenabled = !empty($CFG->enablemyhome);
|
||||
|
||||
if (isloggedin() && isset($CFG->defaulthomepage) && $CFG->defaulthomepage !== '') {
|
||||
// If dashboard is disabled, home will be set to default page.
|
||||
// If dashboard, mycourses or home is disabled, home will be set to default page.
|
||||
$defaultpage = get_default_home_page();
|
||||
if ($CFG->defaulthomepage == HOMEPAGE_SITE) {
|
||||
if ($homeenabled) {
|
||||
@@ -9934,7 +9934,11 @@ function get_home_page() {
|
||||
return $defaultpage;
|
||||
}
|
||||
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES && !isguestuser()) {
|
||||
return HOMEPAGE_MYCOURSES;
|
||||
if (!empty($CFG->enablemycourses)) {
|
||||
return HOMEPAGE_MYCOURSES;
|
||||
} else {
|
||||
return $defaultpage;
|
||||
}
|
||||
} else if ($CFG->defaulthomepage == HOMEPAGE_USER && !isguestuser()) {
|
||||
$userhomepage = get_user_preferences('user_home_page_preference', $defaultpage);
|
||||
if (!$homeenabled && $userhomepage == HOMEPAGE_SITE) {
|
||||
@@ -9943,6 +9947,9 @@ function get_home_page() {
|
||||
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;
|
||||
} else if (empty($CFG->enablemycourses) && $userhomepage == HOMEPAGE_MYCOURSES) {
|
||||
// If the user was using my courses but it's disabled, return the default home page.
|
||||
$userhomepage = $defaultpage;
|
||||
} else if (get_default_home_page_url()) {
|
||||
return HOMEPAGE_URL;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ Feature: Enable dashboard setting
|
||||
Scenario: Hide setting when dashboard is disabled
|
||||
Given the following config values are set as admin:
|
||||
| enabledashboard | 0 |
|
||||
| enablemycourses | 1 |
|
||||
# 2 = User preference.
|
||||
| defaulthomepage | 2 |
|
||||
When I log in as "admin"
|
||||
|
||||
@@ -85,6 +85,8 @@ final class primary_extend_test extends \advanced_testcase {
|
||||
set_config('enablemyhome', 0);
|
||||
set_config('enabledashboard', 1);
|
||||
|
||||
set_config('enablemycourses', 1);
|
||||
|
||||
$PAGE = new \moodle_page();
|
||||
$PAGE->set_url('/');
|
||||
|
||||
|
||||
@@ -5250,6 +5250,7 @@ EOT;
|
||||
* @param int|null $enabledashboard Whether the dashboard should be enabled or not.
|
||||
* @param int|string|null $userpreference User preference for the home page setting.
|
||||
* $param int|null $allowguestmymoodle The $CFG->allowguestmymoodle setting value.
|
||||
* @param int|null $enablemycourses Whether my courses should be enabled or not.
|
||||
* @param int|null $enablemyhome Whether the home page should be enabled or not.
|
||||
* @covers ::get_home_page
|
||||
*/
|
||||
@@ -5260,6 +5261,7 @@ EOT;
|
||||
?int $enabledashboard = null,
|
||||
int|string|null $userpreference = null,
|
||||
?int $allowguestmymoodle = null,
|
||||
?int $enablemycourses = null,
|
||||
?int $enablemyhome = null,
|
||||
): void {
|
||||
global $CFG, $USER;
|
||||
@@ -5281,6 +5283,10 @@ EOT;
|
||||
if (isset($allowguestmymoodle)) {
|
||||
$CFG->allowguestmymoodle = $allowguestmymoodle;
|
||||
}
|
||||
if (!isset($enablemycourses)) {
|
||||
$enablemycourses = 1;
|
||||
}
|
||||
$CFG->enablemycourses = $enablemycourses;
|
||||
if (!isset($enablemyhome)) {
|
||||
$enablemyhome = 1;
|
||||
}
|
||||
@@ -5424,6 +5430,28 @@ EOT;
|
||||
'userpreference' => HOMEPAGE_SITE,
|
||||
'enablemyhome' => 0,
|
||||
],
|
||||
'Logged user. My courses set as default home page with my courses disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 1,
|
||||
'enablemycourses' => 0,
|
||||
],
|
||||
'Logged user. User preference set to my courses with my courses disabled' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_MY,
|
||||
'defaulthomepage' => HOMEPAGE_USER,
|
||||
'enabledashboard' => 1,
|
||||
'userpreference' => HOMEPAGE_MYCOURSES,
|
||||
'enablemycourses' => 0,
|
||||
],
|
||||
'Logged user. My courses disabled and dashboard disabled, fallback to site' => [
|
||||
'user' => 'logged',
|
||||
'expected' => HOMEPAGE_SITE,
|
||||
'defaulthomepage' => HOMEPAGE_MYCOURSES,
|
||||
'enabledashboard' => 0,
|
||||
'enablemycourses' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -5437,13 +5465,40 @@ EOT;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Dashboard enabled takes priority.
|
||||
$CFG->enabledashboard = 1;
|
||||
$CFG->enablemycourses = 1;
|
||||
$CFG->enablemyhome = 1;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MY, $default);
|
||||
|
||||
// Dashboard disabled, my courses enabled.
|
||||
$CFG->enabledashboard = 0;
|
||||
$CFG->enablemycourses = 1;
|
||||
$CFG->enablemyhome = 1;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MYCOURSES, $default);
|
||||
|
||||
// Dashboard and my courses disabled, home enabled.
|
||||
$CFG->enabledashboard = 0;
|
||||
$CFG->enablemycourses = 0;
|
||||
$CFG->enablemyhome = 1;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_SITE, $default);
|
||||
|
||||
// All three disabled, fallback to user preference.
|
||||
$CFG->enabledashboard = 0;
|
||||
$CFG->enablemycourses = 0;
|
||||
$CFG->enablemyhome = 0;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_USER, $default);
|
||||
|
||||
// Dashboard enabled, others disabled.
|
||||
$CFG->enabledashboard = 1;
|
||||
$CFG->enablemycourses = 0;
|
||||
$CFG->enablemyhome = 0;
|
||||
$default = get_default_home_page();
|
||||
$this->assertEquals(HOMEPAGE_MY, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@ final class primary_test extends \advanced_testcase {
|
||||
$this->resetAfterTest();
|
||||
set_config('enablemyhome', 0);
|
||||
set_config('enabledashboard', 1);
|
||||
set_config('enablemycourses', 1);
|
||||
if ($usertype == 'admin') {
|
||||
$this->setAdminUser();
|
||||
} else if ($usertype == 'guest') {
|
||||
|
||||
@@ -35,6 +35,21 @@ redirect_if_major_upgrade_required();
|
||||
|
||||
require_login();
|
||||
|
||||
// Redirect if My Courses is disabled.
|
||||
if (empty($CFG->enablemycourses)) {
|
||||
$defaultpage = get_home_page();
|
||||
if ($defaultpage == HOMEPAGE_URL) {
|
||||
redirect(get_default_home_page_url());
|
||||
} else if ($defaultpage == HOMEPAGE_MY) {
|
||||
redirect(new moodle_url('/my/'));
|
||||
} else if ($defaultpage == HOMEPAGE_USER) {
|
||||
// All homepage options disabled - redirect to user preferences page.
|
||||
redirect(new moodle_url('/user/preferences.php'));
|
||||
} else {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
}
|
||||
|
||||
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
|
||||
if ($hassiteconfig && moodle_needs_upgrading()) {
|
||||
redirect(new moodle_url('/admin/index.php'));
|
||||
|
||||
@@ -58,6 +58,11 @@ if (empty($CFG->enabledashboard)) {
|
||||
if ($defaultpage == HOMEPAGE_MYCOURSES) {
|
||||
// If default page is set to "My courses", redirect to it.
|
||||
redirect(new moodle_url('/my/courses.php'));
|
||||
} else if ($defaultpage == HOMEPAGE_SITE) {
|
||||
redirect(new moodle_url('/'));
|
||||
} else if ($defaultpage == HOMEPAGE_USER) {
|
||||
// All homepage options disabled - redirect to user preferences page.
|
||||
redirect(new moodle_url('/user/preferences.php'));
|
||||
} else {
|
||||
// Otherwise, raise an exception to inform the dashboard is disabled.
|
||||
throw new moodle_exception('error:dashboardisdisabled', 'my');
|
||||
|
||||
@@ -3,7 +3,8 @@ Feature: Run tests over my courses page
|
||||
|
||||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| enablemyhome | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| user1 | User | 1 | user1@example.com |
|
||||
|
||||
@@ -6,7 +6,8 @@ Feature: My courses page block layout in Boost theme
|
||||
|
||||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| enablemyhome | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student@example.com |
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Primary navigation
|
||||
I need to use the primary navigation
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| user1 | User | One | user1@example.com |
|
||||
And the following config values are set as admin:
|
||||
|
||||
@@ -32,6 +32,7 @@ Feature: Welcome message on boost
|
||||
@accessibility
|
||||
Scenario: Login and be welcomed on the my courses page
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
| defaulthomepage | 3 |
|
||||
When I log in as "admin"
|
||||
Then I should see "My courses" in the "page-header" "region"
|
||||
|
||||
@@ -6,7 +6,8 @@ Feature: My courses page block layout in Classic theme
|
||||
|
||||
Background:
|
||||
Given the following config values are set as admin:
|
||||
| enablemyhome | 1 |
|
||||
| enablemyhome | 1 |
|
||||
| enablemycourses | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student@example.com |
|
||||
|
||||
@@ -28,6 +28,7 @@ Feature: Welcome message on classic
|
||||
|
||||
Scenario: Login and be welcomed on the my courses page
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
| defaulthomepage | 3 |
|
||||
When I log in as "admin"
|
||||
Then I should see "My courses" in the "page-header" "region"
|
||||
|
||||
@@ -5,7 +5,9 @@ Feature: Set the site home page and dashboard as the default home page
|
||||
I need to choose which page I want and set it as my home page
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
Given the following config values are set as admin:
|
||||
| enablemycourses | 1 |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category | groupmode |
|
||||
| Course 1 | C1 | 0 | 1 |
|
||||
And the following "users" exist:
|
||||
|
||||
@@ -141,6 +141,9 @@ final class editlib_test extends \advanced_testcase {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// Enable My Courses so HOMEPAGE_MYCOURSES is a valid option.
|
||||
set_config('enablemycourses', 1);
|
||||
|
||||
if ($extraoptions) {
|
||||
// Pretend we have hook callbacks adding extra allowed options.
|
||||
$testcallback = function(\core_user\hook\extend_default_homepage $hook) use ($extraoptions) {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2026030600.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2026030600.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '5.2dev (Build: 20260306)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user