From 8c336899a9d4d3a92f8e214100c2a7076e801f9d Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Wed, 24 Nov 2021 10:11:14 +0700 Subject: [PATCH] MDL-72867 Navigations: User menu improvements --- admin/settings/appearance.php | 8 +- admin/tool/admin_presets/db/install.php | 15 +- .../tests/behat/tour_navigation.feature | 6 +- ..._recentlyaccessedcourses_dashboard.feature | 10 +- ...ck_recentlyaccesseditems_dashboard.feature | 2 +- .../behat/configure_tag_youtube_block.feature | 4 +- .../tests/behat/admin_upload_content.feature | 2 +- .../tests/behat/delete_content.feature | 2 +- contentbank/tests/behat/edit_content.feature | 4 +- contentbank/tests/behat/events.feature | 2 +- .../tests/behat/view_preferences.feature | 2 +- lang/en/admin.php | 2 +- lib/classes/navigation/output/primary.php | 4 +- lib/db/upgrade.php | 51 +++++++ lib/tests/behat/userfeedback.feature | 4 +- lib/tests/navigation/output/primary_test.php | 2 +- lib/tests/user_menu_test.php | 32 ++--- my/tests/behat/reset_all_pages.feature | 14 +- my/tests/behat/welcome.feature | 2 +- repository/tests/behat/select_file.feature | 6 +- user/lib.php | 135 +++++++----------- version.php | 2 +- 22 files changed, 164 insertions(+), 147 deletions(-) diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index e39a99a4908..c5c18d0c0af 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -37,10 +37,10 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp 'customusermenuitems', new lang_string('customusermenuitems', 'admin'), new lang_string('configcustomusermenuitems', 'admin'), - 'grades,grades|/grade/report/mygrades.php|t/grades -calendar,core_calendar|/calendar/view.php?view=month|i/calendar -messages,message|/message/index.php|t/message -preferences,moodle|/user/preferences.php|t/preferences', + 'profile,moodle|/user/profile.php +grades,grades|/grade/report/mygrades.php +calendar,core_calendar|/calendar/view.php?view=month +privatefiles,moodle|/user/files.php', PARAM_RAW, '50', '10' diff --git a/admin/tool/admin_presets/db/install.php b/admin/tool/admin_presets/db/install.php index 0e4095c47ef..e05e5119a93 100644 --- a/admin/tool/admin_presets/db/install.php +++ b/admin/tool/admin_presets/db/install.php @@ -51,9 +51,10 @@ function xmldb_tool_admin_presets_install() { helper::add_item($presetid, 'showdataretentionsummary', '0', 'tool_dataprivacy'); helper::add_item($presetid, 'forum_maxattachments', '3'); - helper::add_item($presetid, 'customusermenuitems', 'grades,grades|/grade/report/mygrades.php|t/grades -calendar,core_calendar|/calendar/view.php?view=month|i/calendar -preferences,moodle|/user/preferences.php|t/preferences'); + helper::add_item($presetid, 'customusermenuitems', 'profile,moodle|/user/profile.php +grades,grades|/grade/report/mygrades.php +calendar,core_calendar|/calendar/view.php?view=month +privatefiles,moodle|/user/files.php'); // Modules: Hide chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop. helper::add_plugin($presetid, 'mod', 'chat', false); @@ -160,10 +161,10 @@ preferences,moodle|/user/preferences.php|t/preferences'); helper::add_item($presetid, 'showdataretentionsummary', '1', 'tool_dataprivacy'); helper::add_item($presetid, 'forum_maxattachments', '9'); // In that case, the indentation coding style can't follow the rules to guarantee the setting value is created properly. - helper::add_item($presetid, 'customusermenuitems', 'grades,grades|/grade/report/mygrades.php|t/grades -calendar,core_calendar|/calendar/view.php?view=month|i/calendar -messages,message|/message/index.php|t/message -preferences,moodle|/user/preferences.php|t/preferences' + helper::add_item($presetid, 'customusermenuitems', 'profile,moodle|/user/profile.php +grades,grades|/grade/report/mygrades.php +calendar,core_calendar|/calendar/view.php?view=month +privatefiles,moodle|/user/files.php' ); // Modules: Enable chat, database, external tool (lti), IMS content package (imscp), lesson, SCORM, survey, wiki, workshop. diff --git a/admin/tool/usertours/tests/behat/tour_navigation.feature b/admin/tool/usertours/tests/behat/tour_navigation.feature index 12123d23226..186840aa674 100644 --- a/admin/tool/usertours/tests/behat/tour_navigation.feature +++ b/admin/tool/usertours/tests/behat/tour_navigation.feature @@ -16,7 +16,7 @@ Feature: Steps can be navigated within a tour | targettype | Block | Title | Content | | Block | Calendar | Calendar events | This is the calendar block | And I change window size to "large" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I wait until the page is ready And I should see "This is the calendar block" When I click on ".block_calendar_month .calendar-controls .next" "css_element" @@ -35,7 +35,7 @@ Feature: Steps can be navigated within a tour | targettype | Block | Title | Content | | Block | Calendar | Calendar events | This is the calendar block | And I change window size to "large" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I wait until the page is ready And I should see "This is the calendar block" Then I should see "Got it" @@ -76,7 +76,7 @@ Feature: Steps can be navigated within a tour | targettype | Block | Title | Content | | Block | Calendar | Calendar events | This is the calendar block | And I change window size to "large" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I wait until the page is ready And I should see "This is the calendar block" Then I should see "CustomText" diff --git a/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature b/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature index a31bbe6235c..f351aca7a80 100644 --- a/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature +++ b/blocks/recentlyaccessedcourses/tests/behat/block_recentlyaccessedcourses_dashboard.feature @@ -39,7 +39,7 @@ Feature: The recently accessed courses block allows users to easily access their And I should not see "Course 2" in the "Recently accessed courses" "block" When I am on "Course 1" course homepage And I am on "Course 2" course homepage - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I change window size to "large" Then I should see "Course 1" in the "Recently accessed courses" "block" And I should see "Course 2" in the "Recently accessed courses" "block" @@ -53,7 +53,7 @@ Feature: The recently accessed courses block allows users to easily access their And I log in as "student1" And I am on "Course 1" course homepage And I am on "Course 4" course homepage - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should see "Category 1" in the "Recently accessed courses" "block" And I should see "Category A" in the "Recently accessed courses" "block" @@ -63,7 +63,7 @@ Feature: The recently accessed courses block allows users to easily access their And I log in as "student1" And I am on "Course 1" course homepage And I am on "Course 4" course homepage - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should not see "Category 1" in the "Recently accessed courses" "block" And I should not see "Category A" in the "Recently accessed courses" "block" @@ -73,7 +73,7 @@ Feature: The recently accessed courses block allows users to easily access their And I log in as "student1" And I am on "Course 1" course homepage And I am on "Course 4" course homepage - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should see "C1" in the "Recently accessed courses" "block" And I should see "C4" in the "Recently accessed courses" "block" @@ -83,6 +83,6 @@ Feature: The recently accessed courses block allows users to easily access their And I log in as "student1" And I am on "Course 1" course homepage And I am on "Course 4" course homepage - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should not see "C1" in the "Recently accessed courses" "block" And I should not see "C4" in the "Recently accessed courses" "block" diff --git a/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature b/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature index 5d1f562177e..6af5d32c930 100644 --- a/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature +++ b/blocks/recentlyaccesseditems/tests/behat/block_recentlyaccesseditems_dashboard.feature @@ -31,5 +31,5 @@ Feature: The recently accessed items block allows users to easily access their m Scenario: User has accessed some items Given I change window size to "large" When I am on the "Test forum name" "forum activity" page - And I follow "Dashboard" in the user menu + And I follow "Dashboard" Then I should see "Test forum name" in the "Recently accessed items" "block" diff --git a/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature b/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature index 4da87fe05f2..f1efd5e5be4 100644 --- a/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature +++ b/blocks/tag_youtube/tests/behat/configure_tag_youtube_block.feature @@ -13,7 +13,7 @@ Feature: Adding and configuring YouTube block Scenario: Category options are not available (except default) in the block settings if the YouTube API key is not set. Given the following config values are set as admin: | apikey | | block_tag_youtube | - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I turn editing mode on # TODO MDL-57120 site "Tags" link not accessible without navigation block. And I add the "Navigation" block if not present @@ -33,7 +33,7 @@ Feature: Adding and configuring YouTube block Scenario: Category options are not available (except default) in the block settings when invalid YouTube API key is set. Given the following config values are set as admin: | apikey | invalidapikeyvalue | block_tag_youtube | - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I turn editing mode on And I add the "Navigation" block if not present And I click on "Site pages" "list_item" in the "Navigation" "block" diff --git a/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature b/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature index 917ecb1e098..80bfb717592 100644 --- a/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature +++ b/contentbank/contenttype/h5p/tests/behat/admin_upload_content.feature @@ -74,7 +74,7 @@ Feature: H5P file upload to content bank for admins Scenario: Admins can upload and deployed content types when libraries are not installed Given I navigate to "H5P > Manage H5P content types" in site administration And I should not see "Fill in the Blanks" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I expand "Site pages" node And I click on "Content bank" "link" And I should not see "filltheblanks.h5p" diff --git a/contentbank/tests/behat/delete_content.feature b/contentbank/tests/behat/delete_content.feature index 96f13428356..935be35a5ce 100644 --- a/contentbank/tests/behat/delete_content.feature +++ b/contentbank/tests/behat/delete_content.feature @@ -72,7 +72,7 @@ Feature: Delete H5P file from the content bank And I should see "Delete" Scenario: The number of times a content is used is displayed before removing it - Given I follow "Dashboard" in the user menu + Given I follow "Dashboard" And I follow "Manage private files..." And I click on "Add..." "button" And I select "Content bank" repository in file picker diff --git a/contentbank/tests/behat/edit_content.feature b/contentbank/tests/behat/edit_content.feature index 8e59c8f1109..4600726efc8 100644 --- a/contentbank/tests/behat/edit_content.feature +++ b/contentbank/tests/behat/edit_content.feature @@ -20,7 +20,7 @@ Feature: Content bank use editor feature Then the "[data-action=Add-content]" "css_element" should be disabled Scenario: Users can see the Add button if there is content type available for creation - Given I follow "Dashboard" in the user menu + Given I follow "Dashboard" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" @@ -39,7 +39,7 @@ Feature: Content bank use editor feature And I should see "Fill in the Blanks" Scenario: Users can edit content if they have the required permission - Given I follow "Dashboard" in the user menu + Given I follow "Dashboard" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" diff --git a/contentbank/tests/behat/events.feature b/contentbank/tests/behat/events.feature index 6ed11b0faf0..b89437a601f 100644 --- a/contentbank/tests/behat/events.feature +++ b/contentbank/tests/behat/events.feature @@ -15,7 +15,7 @@ Feature: Confirm content bank events are triggered And the following "contentbank content" exist: | contextlevel | reference | contenttype | user | contentname | filepath | | Course | C1 | contenttype_h5p | admin | Existing | /h5p/tests/fixtures/filltheblanks.h5p | - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" diff --git a/contentbank/tests/behat/view_preferences.feature b/contentbank/tests/behat/view_preferences.feature index 39ee28250bd..31668c510f1 100644 --- a/contentbank/tests/behat/view_preferences.feature +++ b/contentbank/tests/behat/view_preferences.feature @@ -50,7 +50,7 @@ Feature: Store the content bank view preference And I should not see "Last modified" Scenario: Display the number of times a content is used in file details view - Given I follow "Dashboard" in the user menu + Given I follow "Dashboard" And I follow "Manage private files..." And I click on "Add..." "button" And I select "Content bank" repository in file picker diff --git a/lang/en/admin.php b/lang/en/admin.php index cca2cfc8786..86753fd8231 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -203,7 +203,7 @@ Courses -Preguntas más frecuentes|https://someurl.xyz/pmf||es Mobile app|https://someurl.xyz/app|Download our app '; -$string['configcustomusermenuitems'] = 'You can configure the contents of the user menu (with the exception of the log out link, which is automatically added). Each line is separated by pipe characters and consists of 1) a string in "langstringname, componentname" form or as plain text, 2) a URL, and 3) an icon either as a pix icon (in the folder pix with the structure [subfoldername]/[iconname], e.g. i/publish) or as a URL. Dividers can be used by adding a line of one or more # characters where desired.'; +$string['configcustomusermenuitems'] = 'You can configure the contents of the user menu (with the exception of the log out link, which is automatically added). Each line is separated by pipe characters and consists of 1) a string in "langstringname, componentname" form or as plain text, and 2) a URL. Dividers can be used by adding a line of one or more # characters where desired.'; $string['configdbsessions'] = 'If enabled, this setting will use the database to store information about current sessions. Note that changing this setting now will log out all current users (including you). If you are using MySQL please make sure that \'max_allowed_packet\' in my.cnf (or my.ini) is at least 4M. Other session drivers can be configured directly in config.php, see config-dist.php for more information. This option disappears if you specify session driver in config.php file.'; $string['configdebug'] = 'If you turn this on, then PHP\'s error_reporting will be increased so that more warnings are printed. This is only useful for developers.'; $string['configdebugdisplay'] = 'Set to on, the error reporting will go to the HTML page. This is practical, but breaks XHTML, JS, cookies and HTTP headers in general. Set to off, it will send the output to your server logs, allowing better debugging. The PHP setting error_log controls which log this goes to.'; diff --git a/lib/classes/navigation/output/primary.php b/lib/classes/navigation/output/primary.php index f1716ac9115..86e26482ca6 100644 --- a/lib/classes/navigation/output/primary.php +++ b/lib/classes/navigation/output/primary.php @@ -204,7 +204,6 @@ class primary implements renderable, templatable { 'itemtype' => 'submenu-link', 'submenuid' => $langsubmenuid, 'title' => get_string('language'), - 'pixicon' => 'i/language', 'divider' => false, 'submenulink' => true, ]; @@ -226,8 +225,7 @@ class primary implements renderable, templatable { } } - // Add dividers after the first item and before the last item. - $modifiedarray[0]->divider = true; + // Add divider before the last item. $modifiedarray[count($modifiedarray) - 2]->divider = true; $usermenudata['items'] = $modifiedarray; $usermenudata['submenus'] = array_values($submenusdata); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index ca4f9c7998c..3bb952fa1a4 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3189,5 +3189,56 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2021120100.01); } + if ($oldversion < 2021121000.01) { + // Get current configuration data. + $currentcustomusermenuitems = str_replace(["\r\n", "\r"], "\n", $CFG->customusermenuitems); + + // The old default customusermenuitems config for 3.11 and below. + $oldcustomusermenuitems = 'grades,grades|/grade/report/mygrades.php|t/grades +calendar,core_calendar|/calendar/view.php?view=month|i/calendar +messages,message|/message/index.php|t/message +preferences,moodle|/user/preferences.php|t/preferences'; + + // Check if the current customusermenuitems config matches the old customusermenuitems config. + $samecustomusermenuitems = $currentcustomusermenuitems == $oldcustomusermenuitems; + if ($samecustomusermenuitems) { + // If the site is still using the old defaults, upgrade to the new default. + $newcustomusermenuitems = 'profile,moodle|/user/profile.php +grades,grades|/grade/report/mygrades.php +calendar,core_calendar|/calendar/view.php?view=month +privatefiles,moodle|/user/files.php'; + // Set the new configuration back. + set_config('customusermenuitems', $newcustomusermenuitems); + } else { + // If the site is not using the old defaults, only add necessary entries. + $lines = explode("\n", $currentcustomusermenuitems); + $lines = array_map('trim', $lines); + + // Remove the Preference entry from the menu to prevent duplication + // since it will be added again in user_get_user_navigation_info(). + $lines = array_filter($lines, function($value) { + return strpos($value, 'preferences,moodle|/user/preferences.php') === false; + }); + + $matches = preg_grep('/\|\/user\/files.php/i', $lines); + if (!$matches) { + // Add the Private files entry to the menu. + $lines[] = 'privatefiles,moodle|/user/files.php'; + } + + $matches = preg_grep('/\|\/user\/profile.php/i', $lines); + if (!$matches) { + // Add the Profile entry to top of the menu. + array_unshift($lines, 'profile,moodle|/user/profile.php'); + } + + // Set the new configuration back. + set_config('customusermenuitems', implode("\n", $lines)); + } + + // Main savepoint reached. + upgrade_main_savepoint(true, 2021121000.01); + } + return true; } diff --git a/lib/tests/behat/userfeedback.feature b/lib/tests/behat/userfeedback.feature index 6cf33d6a21e..443111c34d7 100644 --- a/lib/tests/behat/userfeedback.feature +++ b/lib/tests/behat/userfeedback.feature @@ -29,7 +29,7 @@ Feature: Gathering user feedback | userfeedback_nextreminder | 2 | | userfeedback_remindafter | 90 | When I log in as "admin" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I click on "Remind me later" "link" And I reload the page Then I should not see "Give feedback" in the "region-main" "region" @@ -42,7 +42,7 @@ Feature: Gathering user feedback | userfeedback_nextreminder | 2 | | userfeedback_remindafter | 90 | When I log in as "admin" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I click on "Give feedback" "link" And I close all opened windows And I reload the page diff --git a/lib/tests/navigation/output/primary_test.php b/lib/tests/navigation/output/primary_test.php index a87a523f3cf..d25e18f513f 100644 --- a/lib/tests/navigation/output/primary_test.php +++ b/lib/tests/navigation/output/primary_test.php @@ -95,7 +95,7 @@ class primary_test extends \advanced_testcase { if (isloggedin() && !isguestuser()) { // Look for a language menu item within the user menu items. $usermenulang = array_filter($data['user']['items'], function($usermenuitem) { - return $usermenuitem->title === get_string('language'); + return $usermenuitem->itemtype !== 'divider' && $usermenuitem->title === get_string('language'); }); if ($withlang) { // If multiple languages are installed. // Assert that the language menu exists within the user menu. diff --git a/lib/tests/user_menu_test.php b/lib/tests/user_menu_test.php index 19bc9c7b92b..dfcc91c1ecb 100644 --- a/lib/tests/user_menu_test.php +++ b/lib/tests/user_menu_test.php @@ -42,30 +42,30 @@ class core_user_menu_testcase extends advanced_testcase { // These are valid but have an invalid string identifiers or components. They will still produce a menu // item, and no exception should be thrown. - array('#my1files,moodle|/user/files.php|download', 1, 0), - array('#my1files,moodleakjladf|/user/files.php|download', 1, 0), - array('#my1files,a/b|/user/files.php|download', 1, 0), - array('#my1files,#b|/user/files.php|download', 1, 0), + array('#my1files,moodle|/user/files.php', 1, 1), + array('#my1files,moodleakjladf|/user/files.php', 1, 1), + array('#my1files,a/b|/user/files.php', 1, 1), + array('#my1files,#b|/user/files.php', 1, 1), // These are unusual, but valid and will generate a menu entry (no filler). - array('-|-|-|-', 1, 0), - array('-|-|-', 1, 0), - array('-|-', 1, 0), - array('#f234|2', 1, 0), + array('-|-|-|-', 1, 1), + array('-|-|-', 1, 1), + array('-|-', 1, 1), + array('#f234|2', 1, 1), // This is a pretty typical entry. - array('messages,message|/message/index.php|message', 1, 0), + array('messages,message|/message/index.php', 1, 1), // And these are combinations containing both valid and invalid. - array('messages,message|/message/index.php|message -privatefiles,moodle|/user/files.php|download + array('messages,message|/message/index.php +privatefiles,moodle|/user/files.php ### -badges,badges|/badges/mybadges.php|award --|-|- +badges,badges|/badges/mybadges.php +-|- test - ##### -#f234|2', 5, 2), +#f234|2', 5, 3), ); } @@ -95,8 +95,8 @@ test // We always add two dividers as standard. $dividercount += 2; - // The basic entry count will additionally include the wrapper menu, Dashboard, Profile, Logout and switch roles link. - $entrycount += 4; + // The basic entry count will additionally include the wrapper menu, Preferences, Logout and switch roles link. + $entrycount += 3; $output = $OUTPUT->user_menu($USER); preg_match_all('/]+role="menuitem"[^>]+>/', $output, $results); diff --git a/my/tests/behat/reset_all_pages.feature b/my/tests/behat/reset_all_pages.feature index ca89da8252b..21fb4974986 100644 --- a/my/tests/behat/reset_all_pages.feature +++ b/my/tests/behat/reset_all_pages.feature @@ -17,7 +17,7 @@ Feature: Reset all personalised pages to default And I log out And I log in as "student1" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I turn editing mode on And I add the "Comments" block And I turn editing mode off @@ -34,7 +34,7 @@ Feature: Reset all personalised pages to default And I log out And I log in as "student3" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should not see "Comments" And I follow "Profile" in the user menu And I should not see "Logged in user" @@ -52,13 +52,13 @@ Feature: Reset all personalised pages to default And I log out And I log in as "student1" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should not see "Latest announcements" And I should see "Latest badges" And I log out And I log in as "student3" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should not see "Latest announcements" And I should see "Latest badges" And I log out @@ -70,14 +70,14 @@ Feature: Reset all personalised pages to default And I log out And I log in as "student1" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" Then I should see "Latest announcements" And I should not see "Comments" And I should not see "Latest badges" And I log out And I log in as "student3" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should see "Latest announcements" And I should not see "Latest badges" And I log out @@ -124,6 +124,6 @@ Feature: Reset all personalised pages to default # Check that this did not affect the customised dashboards. And I log in as "student1" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I should see "Comments" And I should not see "Latest announcements" diff --git a/my/tests/behat/welcome.feature b/my/tests/behat/welcome.feature index c2db287305a..2c7de0b4837 100644 --- a/my/tests/behat/welcome.feature +++ b/my/tests/behat/welcome.feature @@ -18,7 +18,7 @@ Feature: Welcome message And I press "Log in" And I should see "Math 101" in the "page-header" "region" And I should not see "Welcome, Fei!" in the "page-header" "region" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" Then I should see "Welcome, Fei!" in the "page-header" "region" @javascript diff --git a/repository/tests/behat/select_file.feature b/repository/tests/behat/select_file.feature index 43bce52fcf9..fbd095a8746 100644 --- a/repository/tests/behat/select_file.feature +++ b/repository/tests/behat/select_file.feature @@ -19,7 +19,7 @@ Feature: Select file feature | Description | Test folder description | And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager And I click on "Save and display" "button" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I follow "Manage private files" And I click on "Add..." "button" in the "Files" "form_row" And I click on "Recent files" "link" in the ".fp-repo-area" "css_element" @@ -40,7 +40,7 @@ Feature: Select file feature | Description | Test folder description | And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager And I click on "Save and display" "button" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I follow "Manage private files" And I click on "Add..." "button" in the "Files" "form_row" And I click on "Recent files" "link" in the ".fp-repo-area" "css_element" @@ -61,7 +61,7 @@ Feature: Select file feature | Description | Test folder description | And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager And I click on "Save and display" "button" - And I follow "Dashboard" in the user menu + And I follow "Dashboard" And I follow "Manage private files" And I click on "Add..." "button" in the "Files" "form_row" And I click on "Recent files" "link" in the ".fp-repo-area" "css_element" diff --git a/user/lib.php b/user/lib.php index 85e5cf3a679..390d5619f9c 100644 --- a/user/lib.php +++ b/user/lib.php @@ -662,7 +662,7 @@ function user_count_login_failures($user, $reset = true) { /** * Converts a string into a flat array of menu items, where each menu items is a - * stdClass with fields type, url, title, pix, and imgsrc. + * stdClass with fields type, url, title. * * @param string $text the menu items definition * @param moodle_page $page the current page @@ -679,7 +679,7 @@ function user_convert_text_to_menu_items($text, $page) { $children = array(); foreach ($lines as $line) { $line = trim($line); - $bits = explode('|', $line, 3); + $bits = explode('|', $line, 2); $itemtype = 'link'; if (preg_match("/^#+$/", $line)) { $itemtype = 'divider'; @@ -732,34 +732,6 @@ function user_convert_text_to_menu_items($text, $page) { } $child->url = $bits[1]; - // PIX processing. - $pixpath = "t/edit"; - if (!array_key_exists(2, $bits) or empty($bits[2])) { - // Use the default. - $child->pix = $pixpath; - } else { - // Check for the specified image existing. - if (strpos($bits[2], '../') === 0) { - // The string starts with '../'. - // Strip off the first three characters - this should be the pix path. - $pixpath = substr($bits[2], 3); - } else if (strpos($bits[2], '/') === false) { - // There is no / in the path. Prefix it with 't/', which is the default path. - $pixpath = "t/{$bits[2]}"; - } else { - // There is a '/' in the path - this is either a URL, or a standard pix path with no changes required. - $pixpath = $bits[2]; - } - if ($page->theme->resolve_image_location($pixpath, 'moodle', true)) { - // Use the image. - $child->pix = $pixpath; - } else { - // Treat it like a URL. - $child->pix = null; - $child->imgsrc = $bits[2]; - } - } - // Add this child to the list of children. $children[] = $child; } @@ -878,69 +850,34 @@ function user_get_user_navigation_info($user, $page, $options = array()) { } } - // Links: Dashboard. - $myhome = new stdClass(); - $myhome->itemtype = 'link'; - $myhome->url = new moodle_url('/my/'); - $myhome->title = get_string('mymoodle', 'admin'); - $myhome->titleidentifier = 'mymoodle,admin'; - $myhome->pix = "i/dashboard"; - $returnobject->navitems[] = $myhome; - - // Links: My Profile. - $myprofile = new stdClass(); - $myprofile->itemtype = 'link'; - $myprofile->url = new moodle_url('/user/profile.php', array('id' => $user->id)); - $myprofile->title = get_string('profile'); - $myprofile->titleidentifier = 'profile,moodle'; - $myprofile->pix = "i/user"; - $returnobject->navitems[] = $myprofile; - $returnobject->metadata['asotherrole'] = false; // Before we add the last items (usually a logout + switch role link), add any // custom-defined items. $customitems = user_convert_text_to_menu_items($CFG->customusermenuitems, $page); + $custommenucount = 0; foreach ($customitems as $item) { $returnobject->navitems[] = $item; + if ($item->itemtype !== 'divider' && $item->itemtype !== 'invalid') { + $custommenucount++; + } } + if ($custommenucount > 0) { + // Only add a divider if we have customusermenuitems. + $divider = new stdClass(); + $divider->itemtype = 'divider'; + $returnobject->navitems[] = $divider; + } - if ($returnobject->metadata['asotheruser'] = \core\session\manager::is_loggedinas()) { - $realuser = \core\session\manager::get_realuser(); - - // Save values for the real user, as $user will be full of data for the - // user the user is disguised as. - $returnobject->metadata['realuserid'] = $realuser->id; - $returnobject->metadata['realuserfullname'] = fullname($realuser); - $returnobject->metadata['realuserprofileurl'] = new moodle_url('/user/profile.php', array( - 'id' => $realuser->id - )); - $returnobject->metadata['realuseravatar'] = $OUTPUT->user_picture($realuser, $avataroptions); - - // Build a user-revert link. - $userrevert = new stdClass(); - $userrevert->itemtype = 'link'; - $userrevert->url = new moodle_url('/course/loginas.php', array( - 'id' => $course->id, - 'sesskey' => sesskey() - )); - $userrevert->pix = "a/logout"; - $userrevert->title = get_string('logout'); - $userrevert->titleidentifier = 'logout,moodle'; - $returnobject->navitems[] = $userrevert; - - } else { + // Links: Preferences. + $preferences = new stdClass(); + $preferences->itemtype = 'link'; + $preferences->url = new moodle_url('/user/preferences.php'); + $preferences->title = get_string('preferences'); + $preferences->titleidentifier = 'preferences,moodle'; + $returnobject->navitems[] = $preferences; - // Build a logout link. - $logout = new stdClass(); - $logout->itemtype = 'link'; - $logout->url = new moodle_url('/login/logout.php', array('sesskey' => sesskey())); - $logout->pix = "a/logout"; - $logout->title = get_string('logout'); - $logout->titleidentifier = 'logout,moodle'; - $returnobject->navitems[] = $logout; - } if (is_role_switched($course->id)) { if ($role = $DB->get_record('role', array('id' => $user->access['rsw'][$context->path]))) { @@ -953,7 +890,6 @@ function user_get_user_navigation_info($user, $page, $options = array()) { 'switchrole' => 0, 'returnurl' => $page->url->out_as_local_url(false) )); - $rolereturn->pix = "a/logout"; $rolereturn->title = get_string('switchrolereturn'); $rolereturn->titleidentifier = 'switchrolereturn,moodle'; $returnobject->navitems[] = $rolereturn; @@ -973,13 +909,44 @@ function user_get_user_navigation_info($user, $page, $options = array()) { 'switchrole' => -1, 'returnurl' => $page->url->out_as_local_url(false) )); - $switchrole->pix = "i/switchrole"; $switchrole->title = get_string('switchroleto'); $switchrole->titleidentifier = 'switchroleto,moodle'; $returnobject->navitems[] = $switchrole; } } + if ($returnobject->metadata['asotheruser'] = \core\session\manager::is_loggedinas()) { + $realuser = \core\session\manager::get_realuser(); + + // Save values for the real user, as $user will be full of data for the + // user is disguised as. + $returnobject->metadata['realuserid'] = $realuser->id; + $returnobject->metadata['realuserfullname'] = fullname($realuser); + $returnobject->metadata['realuserprofileurl'] = new moodle_url('/user/profile.php', [ + 'id' => $realuser->id + ]); + $returnobject->metadata['realuseravatar'] = $OUTPUT->user_picture($realuser, $avataroptions); + + // Build a user-revert link. + $userrevert = new stdClass(); + $userrevert->itemtype = 'link'; + $userrevert->url = new moodle_url('/course/loginas.php', [ + 'id' => $course->id, + 'sesskey' => sesskey() + ]); + $userrevert->title = get_string('logout'); + $userrevert->titleidentifier = 'logout,moodle'; + $returnobject->navitems[] = $userrevert; + } else { + // Build a logout link. + $logout = new stdClass(); + $logout->itemtype = 'link'; + $logout->url = new moodle_url('/login/logout.php', ['sesskey' => sesskey()]); + $logout->title = get_string('logout'); + $logout->titleidentifier = 'logout,moodle'; + $returnobject->navitems[] = $logout; + } + return $returnobject; } diff --git a/version.php b/version.php index 9bf293d2fbb..42c73d2078d 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021121000.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2021121000.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev+ (Build: 20211210)'; // Human-friendly version name -- 2.43.0