Merge branch 'MDL-73672-311' of https://github.com/BruceGoodGuy/moodle into MOODLE_311_STABLE

This commit is contained in:
Ilya Tregubov
2022-04-25 10:03:11 +06:00
3 changed files with 86 additions and 13 deletions
@@ -0,0 +1,49 @@
@core @core_course
Feature: Report navigation
As a teacher
I will be redirected to the first report page on the navigation if I can't access to other reports.
Background:
Given the following "users" exist:
| username |
| teacher |
And the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
Scenario: The teacher will be redirected to the first report page if they can't access to most recently report
Given I am on the "C1" "Course" page logged in as "teacher"
When I navigate to "Logs" in current page administration
Then I should see "Choose which logs you want to see"
When I click on "Reports" "link"
Then I should see "Choose which logs you want to see"
When the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| report/log:view | Prohibit | editingteacher | System | |
And I click on "Reports" "link"
Then I should see "Competency breakdown"
And I should not see "Sorry, but you do not currently have permissions to do that"
Scenario: If capability Log view is unset, the teacher will be redirected to the first valid report page
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| report/log:view | Prohibit | editingteacher | System | |
When I am on the "C1" "Course" page logged in as "teacher"
And I navigate to "Reports" in current page administration
Then I should see "Competency breakdown"
And I should not see "Sorry, but you do not currently have permissions to do that"
Scenario: A warning message will be shown if the user cannot access any report page
Given the following "permission overrides" exist:
| capability | permission | role | contextlevel | reference |
| report/log:view | Prohibit | editingteacher | System | |
| report/loglive:view | Prohibit | editingteacher | System | |
| report/outline:view | Prohibit | editingteacher | System | |
| report/participation:view | Prohibit | editingteacher | System | |
| moodle/competency:coursecompetencyview | Prohibit | editingteacher | System | |
When I am on the "C1" "Course" page logged in as "teacher"
And I navigate to "Reports" in current page administration
Then I should see "No reports accessible"
@@ -1,9 +1,9 @@
@report @report_log
Feature: In a course administration page, navigate through report page, test for report log page
Feature: In a course administration page, navigate through report page, test for first report page
In order to navigate through report page
As an admin
Go to course administration -> reports
The reports page by default points to logs page
The reports page by default points to first report page
Background:
Given the following "courses" exist:
@@ -24,13 +24,13 @@ Feature: In a course administration page, navigate through report page, test for
| student1 | C3 | student |
@javascript
Scenario: Default page accessed for Report is log page
Scenario: Default page accessed for Report is competency breakdown page
Given I log in as "admin"
And I am on "Course 1" course homepage
When I navigate to "Reports" in current page administration
Then "Report" "field" should exist
And the "Report" select box should contain "Logs"
And the field "Report" matches value "Logs"
And the "Report" select box should contain "Competency breakdown"
And the field "Report" matches value "Competency breakdown"
@javascript
Scenario: Verify the session setting is saved for different courses
@@ -38,15 +38,15 @@ Feature: In a course administration page, navigate through report page, test for
And I am on "Course 1" course homepage
And I navigate to "Reports" in current page administration
And "Report" "field" should exist
And the "Report" select box should contain "Logs"
And the field "Report" matches value "Logs"
And the "Report" select box should contain "Competency breakdown"
And the field "Report" matches value "Competency breakdown"
# Now select the Live logs for Course 2
And I am on "Course 2" course homepage
And I navigate to "Reports > Live logs" in current page administration
# now come back to course 1 and see if the default is logs page or not
And I am on "Course 1" course homepage
And I navigate to "Reports" in current page administration
And the "Report" select box should contain "Logs"
And the "Report" select box should contain "Competency breakdown"
# Now come back again to Course 2
And I am on "Course 2" course homepage
When I navigate to "Reports" in current page administration
+29 -5
View File
@@ -37,10 +37,34 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) {
require_login($course);
// Get the last viewed Page.
if (!isset($USER->course_last_report[$courseid])) {
$lasturl = new moodle_url('/report/log/index.php', ['id' => $courseid]);
} else {
$lasturl = $USER->course_last_report[$courseid];
$lasturl = null;
$reportsnode = $PAGE->settingsnav->find('coursereports', \navigation_node::TYPE_CONTAINER);
$reportchildrennode = $reportsnode->children;
// If there are available course reports to the user.
if ($reportsnode && $reportchildrennode->count() > 0) {
// By default, set the first valid report URL for the redirect URL.
$lasturl = $reportchildrennode->getIterator()[0]->action()->out(false);
// If exist the last viewed report page.
if (isset($USER->course_last_report[$courseid])) {
// Check if the most recently report link is existed on report navigation node.
foreach ($reportchildrennode as $node) {
if ($node->action()->get_path() === $USER->course_last_report[$courseid]->get_path()) {
$lasturl = $USER->course_last_report[$courseid];
break;
}
}
}
}
if ($lasturl) {
redirect($lasturl);
}
// Otherwise, output the page with a notification stating that there are no available course reports.
$PAGE->set_title(get_string('reports'));
$PAGE->set_pagelayout('incourse');
$PAGE->set_heading($course->fullname);
$PAGE->set_pagetype('course-view-' . $course->format);
redirect($lasturl);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('reports'));
echo html_writer::div($OUTPUT->notification(get_string('noreports', 'debug'), 'error'), 'mt-3');
echo $OUTPUT->footer();