Skip to content

Commit

Permalink
MDL-81942 user: guests should respect default site homepage setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jun 12, 2024
1 parent d3ae139 commit f4d4f1c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Feature: Enable the course_list block on the frontpage and view it's contents
And I add the "Courses" block
And I log out
When I log in as "guest"
And I am on site homepage
Then I should see "Category 1" in the "Course categories" "block"
And I should see "Category A" in the "Course categories" "block"
And I should see "Category B" in the "Course categories" "block"
Expand Down
2 changes: 1 addition & 1 deletion blocks/navigation/tests/behat/expand_courses_node.feature
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Feature: Expand the courses nodes within the navigation block
Scenario: As guest I expand the courses and category nodes to see courses.
When I log in as "guest"
And I am on site homepage
And I should see "Home" in the "Navigation" "block"
And I should see "Site home" in the "Navigation" "block"
And I should see "Courses" in the "Navigation" "block"
And I expand "Courses" node
And I should see "cat1" in the "Navigation" "block"
Expand Down
8 changes: 4 additions & 4 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -10081,18 +10081,18 @@ function mnet_get_idp_jump_url($user) {
function get_home_page() {
global $CFG;

if (isloggedin() && !isguestuser() && !empty($CFG->defaulthomepage)) {
if (isloggedin() && !empty($CFG->defaulthomepage)) {
// If dashboard is disabled, home will be set to default page.
$defaultpage = get_default_home_page();
if ($CFG->defaulthomepage == HOMEPAGE_MY) {
if ($CFG->defaulthomepage == HOMEPAGE_MY && (!isguestuser() || !empty($CFG->allowguestmymoodle))) {
if (!empty($CFG->enabledashboard)) {
return HOMEPAGE_MY;
} else {
return $defaultpage;
}
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) {
} else if ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES && !isguestuser()) {
return HOMEPAGE_MYCOURSES;
} else {
} else if ($CFG->defaulthomepage == HOMEPAGE_USER && !isguestuser()) {
$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.
Expand Down
44 changes: 35 additions & 9 deletions lib/tests/moodlelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5164,13 +5164,20 @@ public function get_list_of_plugins_provider(): array {
* @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.
* @param int|null $defaulthomepage The $CFG->defaulthomepage setting value.
* @param int|null $enabledashboard Whether the dashboard should be enabled or not.
* @param int|null $userpreference User preference for the home page setting.
* $param int|null $allowguestmymoodle The $CFG->allowguestmymoodle setting value.
* @covers ::get_home_page
*/
public function test_get_home_page(string $user, int $expected, ?int $defaulthomepage = null, ?int $enabledashboard = null,
?int $userpreference = null) {
public function test_get_home_page(
string $user,
int $expected,
?int $defaulthomepage = null,
?int $enabledashboard = null,
?int $userpreference = null,
?int $allowguestmymoodle = null,
): void {
global $CFG, $USER;

$this->resetAfterTest();
Expand All @@ -5187,6 +5194,9 @@ public function test_get_home_page(string $user, int $expected, ?int $defaulthom
if (isset($enabledashboard)) {
$CFG->enabledashboard = $enabledashboard;
}
if (isset($allowguestmymoodle)) {
$CFG->allowguestmymoodle = $allowguestmymoodle;
}

if ($USER) {
set_user_preferences(['user_home_page_preference' => $userpreference], $USER->id);
Expand All @@ -5201,21 +5211,37 @@ public function test_get_home_page(string $user, int $expected, ?int $defaulthom
*
* @return array
*/
public function get_home_page_provider(): array {
public static function get_home_page_provider(): array {
return [
'No logged user' => [
'user' => 'nologged',
'expected' => HOMEPAGE_SITE,
],
'Guest user' => [
'Guest user. Dashboard set as default home page and enabled for guests' => [
'user' => 'guest',
'expected' => HOMEPAGE_MY,
],
'Guest user. Dashboard set as default home page but disabled for guests' => [
'user' => 'guest',
'expected' => HOMEPAGE_SITE,
'defaulthomepage' => HOMEPAGE_MY,
'enabledashboard' => 1,
'userpreference' => null,
'allowguestmymoodle' => 0,
],
'Guest user. My courses set as default home page' => [
'user' => 'guest',
'expected' => HOMEPAGE_SITE,
'defaulthomepage' => HOMEPAGE_MYCOURSES,
],
'Guest user. User preference set as default page' => [
'user' => 'guest',
'expected' => HOMEPAGE_SITE,
'defaulthomepage' => HOMEPAGE_USER,
],
'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',
Expand Down
2 changes: 0 additions & 2 deletions user/tests/behat/contact_site_support.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ Feature: Contact site support method and availability can be customised
When I am on site homepage
Then I should not see "Contact site support" in the "page-footer" "region"
And I am on the "user > Contact Site Support" page
And I should see "Acceptance test site" in the "page-header" "region"
And I should not see "Contact site support" in the "page-header" "region"
# Confirm someone logged in as guest cannot see the option or directly access the page.
And I log in as "guest"
And I should not see "Contact site support" in the "page-footer" "region"
And I am on the "user > Contact Site Support" page
And I should see "Acceptance test site" in the "page-header" "region"
And I should not see "Contact site support" in the "page-header" "region"
And I log out
# Confirm logged in user has access to the contact form.
Expand Down

0 comments on commit f4d4f1c

Please sign in to comment.