From 2c010bbd7b4fc1a8f0c61b836bb433d5e55dce32 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Wed, 11 May 2022 23:22:04 +0200 Subject: [PATCH 1/2] MDL-74716 course: Add Request a course link to My courses --- my/courses.php | 8 ++++++++ my/templates/dropdown.mustache | 6 +++++- my/tests/behat/my_courses.feature | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/my/courses.php b/my/courses.php index c8e3eb51cc2..60489dc0533 100644 --- a/my/courses.php +++ b/my/courses.php @@ -29,6 +29,7 @@ require_once(__DIR__ . '/../config.php'); require_once($CFG->dirroot . '/my/lib.php'); +require_once($CFG->dirroot . '/course/lib.php'); redirect_if_major_upgrade_required(); @@ -78,6 +79,13 @@ if ($coursecat && ($category = core_course_category::get_nearest_editable_subcat // The user has the capability to manage the course category. $coursemanagemenu['manageurl'] = new moodle_url('/course/management.php', ['categoryid' => $category->id]); } +if ($coursecat) { + $category = core_course_category::get_nearest_editable_subcategory($coursecat, ['moodle/course:request']); + if ($category && $category->can_request_course()) { + $coursemanagemenu['courserequesturl'] = new moodle_url('/course/request.php', ['categoryid' => $category->id]); + + } +} if (!empty($coursemanagemenu)) { // Render the course management menu. $PAGE->add_header_action($OUTPUT->render_from_template('my/dropdown', $coursemanagemenu)); diff --git a/my/templates/dropdown.mustache b/my/templates/dropdown.mustache index ada1243be9c..4a75dba9d12 100644 --- a/my/templates/dropdown.mustache +++ b/my/templates/dropdown.mustache @@ -22,7 +22,8 @@ Example context (json): { "newcourseurl": "https://moodle.test/course/edit.php?category=1", - "manageurl": "https://moodle.test/course/management.php?categoryid=1" + "manageurl": "https://moodle.test/course/management.php?categoryid=1", + "courserequesturl": "https://moodle.test/course/request.php?categoryid=1" } }}
@@ -37,5 +38,8 @@ {{#manageurl}} {{#str}}managecourses, core{{/str}} {{/manageurl}} + {{#courserequesturl}} + {{#str}}requestcourse, core{{/str}} + {{/courserequesturl}}
diff --git a/my/tests/behat/my_courses.feature b/my/tests/behat/my_courses.feature index 9cf37ec2170..1b2c3b79355 100644 --- a/my/tests/behat/my_courses.feature +++ b/my/tests/behat/my_courses.feature @@ -111,3 +111,31 @@ Feature: Run tests over my courses. And "Move Course overview block" "button" should not exist in the "Course overview" "block" And I click on "Actions menu" "icon" in the "Course overview" "block" And I should not see "Delete Course overview block" + + @javascript + Scenario: User with creating a course permission can't see the Request course link + Given the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | moodle/course:request | Allow | user | System | | + When I am on the "My courses" page logged in as "admin" + And I click on "Course management options" "link" + And I should see "New course" + Then I should not see "Request a course" + + @javascript + Scenario: User without creating a course but with course request permission could see the Request course link + Given the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | moodle/course:request | Allow | user | System | | + When I am on the "My courses" page logged in as "user1" + And I click on "Course management options" "link" + And I should not see "New course" + Then I should see "Request a course" + And the following config values are set as admin: + | enablecourserequests | 0 | + And I am on the "My courses" page logged in as "user1" + And "Course management options" "link" should not exist + + Scenario: User without creating nor course request permission shouldn't see any Request course link + Given I am on the "My courses" page logged in as "user1" + Then "Course management options" "link" should not exist From 31b45356959c87996f35e1c1eb3fb438146417bf Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Wed, 15 Jun 2022 12:45:31 +0200 Subject: [PATCH 2/2] MDL-74716 core_my: Fix My course user tour for admins --- admin/tool/usertours/classes/manager.php | 2 +- admin/tool/usertours/db/upgrade.php | 8 ++++++++ .../tool/usertours/tours/40_tour_navigation_mycourse.json | 6 +++--- admin/tool/usertours/version.php | 2 +- my/templates/dropdown.mustache | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index 8867c052bdb..8eec05260d7 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -867,7 +867,7 @@ class manager { // be increased if the tour has been updated. $shippedtours = [ '40_tour_navigation_dashboard.json' => 4, - '40_tour_navigation_mycourse.json' => 4, + '40_tour_navigation_mycourse.json' => 5, '40_tour_navigation_course_teacher.json' => 3, '40_tour_navigation_course_student.json' => 3, ]; diff --git a/admin/tool/usertours/db/upgrade.php b/admin/tool/usertours/db/upgrade.php index e1443c3065a..52362af2b75 100644 --- a/admin/tool/usertours/db/upgrade.php +++ b/admin/tool/usertours/db/upgrade.php @@ -129,6 +129,14 @@ function xmldb_tool_usertours_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2022040602, 'tool', 'usertours'); } + if ($oldversion < 2022061600) { + // Update shipped tours. + // Normally, we just bump the version numbers because we need to call update_shipped_tours only once. + manager::update_shipped_tours(); + + upgrade_plugin_savepoint(true, 2022061600, 'tool', 'usertours'); + } + // Automatically generated Moodle v4.0.0 release upgrade line. // Put any upgrade step following this. diff --git a/admin/tool/usertours/tours/40_tour_navigation_mycourse.json b/admin/tool/usertours/tours/40_tour_navigation_mycourse.json index bf9666cce3c..6e548bdb1c3 100644 --- a/admin/tool/usertours/tours/40_tour_navigation_mycourse.json +++ b/admin/tool/usertours/tours/40_tour_navigation_mycourse.json @@ -5,16 +5,16 @@ "enabled": "1", "sortorder": "1", "endtourlabel": "tour_navigation_mycourses_endtourlabel,tool_usertours", - "configdata": "{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972468,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_mycourse.json\",\"shipped_version\":1}", + "configdata": "{\"placement\":\"bottom\",\"orphan\":\"0\",\"backdrop\":\"1\",\"reflex\":\"0\",\"filtervalues\":{\"accessdate\":{\"filter_accessdate\":\"tool_usertours_accountcreation\",\"filter_accessdate_range\":0,\"filter_accessdate_enabled\":\"0\"},\"category\":[],\"course\":[],\"courseformat\":[],\"role\":[],\"theme\":[\"boost\"],\"cssselector\":[]},\"majorupdatetime\":1641972468,\"shipped_tour\":true,\"shipped_filename\":\"40_tour_navigation_mycourse.json\",\"shipped_version\":5}", "displaystepnumbers": true, - "version": "2021101301", + "version": "2022061600", "steps": [ { "title": "tour_navigation_mycourses_title,tool_usertours", "content": "tour_navigation_mycourses_content,tool_usertours", "contentformat": "1", "targettype": "0", - "targetvalue": ".header-actions-container .btn-group", + "targetvalue": ".header-actions-container .btn-group.course-manage", "sortorder": "0", "configdata": "{}" } diff --git a/admin/tool/usertours/version.php b/admin/tool/usertours/version.php index 4dee18087d8..ed847dd797e 100644 --- a/admin/tool/usertours/version.php +++ b/admin/tool/usertours/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022041900; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2022061600; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2022041200; // Requires this Moodle version. $plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics). diff --git a/my/templates/dropdown.mustache b/my/templates/dropdown.mustache index 4a75dba9d12..6afe6ea8bcd 100644 --- a/my/templates/dropdown.mustache +++ b/my/templates/dropdown.mustache @@ -26,7 +26,7 @@ "courserequesturl": "https://moodle.test/course/request.php?categoryid=1" } }} -
+