From 5c54b1a6083a9a76bd2876cc159882f794aaaeff Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Mon, 23 Aug 2021 09:05:41 +0200 Subject: [PATCH] MDL-72387 core_course: section navigation visiblity for students --- .../output/local/content/section/header.php | 9 ++- .../local/content/sectionnavigation.php | 2 +- .../output/local/content/sectionselector.php | 3 +- .../classes/output/section_renderer.php | 3 +- course/tests/behat/section_visibility.feature | 65 ++++++++++++++++++- 5 files changed, 72 insertions(+), 10 deletions(-) diff --git a/course/format/classes/output/local/content/section/header.php b/course/format/classes/output/local/content/section/header.php index 595632e9fa5..80704aa5233 100644 --- a/course/format/classes/output/local/content/section/header.php +++ b/course/format/classes/output/local/content/section/header.php @@ -80,9 +80,12 @@ class header implements renderable, templatable { // Regular section title. $data->title = $output->section_title_without_link($section, $course); $data->issinglesection = true; - } else { + } else if ($section->uservisible) { // Regular section title. $data->title = $output->section_title($section, $course); + } else { + // Regular section title without link. + $data->title = $output->section_title_without_link($section, $course); } if (!$section->visible) { @@ -92,7 +95,9 @@ class header implements renderable, templatable { $coursedisplay = $course->coursedisplay ?? COURSE_DISPLAY_SINGLEPAGE; if (!$format->show_editor() && $coursedisplay == COURSE_DISPLAY_MULTIPAGE && empty($data->issinglesection)) { - $data->url = course_get_url($course, $section->section); + if ($section->uservisible) { + $data->url = course_get_url($course, $section->section); + } $data->name = get_section_name($course, $section); } diff --git a/course/format/classes/output/local/content/sectionnavigation.php b/course/format/classes/output/local/content/sectionnavigation.php index 3066c74f957..9b9e150eb6e 100644 --- a/course/format/classes/output/local/content/sectionnavigation.php +++ b/course/format/classes/output/local/content/sectionnavigation.php @@ -80,7 +80,7 @@ class sectionnavigation implements renderable, templatable { $sections = $modinfo->get_section_info_all(); // FIXME: This is really evil and should by using the navigation API. - $canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER) || !$course->hiddensections; + $canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER); $data = (object)[ 'previousurl' => '', diff --git a/course/format/classes/output/local/content/sectionselector.php b/course/format/classes/output/local/content/sectionselector.php index 55234396b91..07a7ec3d5b4 100644 --- a/course/format/classes/output/local/content/sectionselector.php +++ b/course/format/classes/output/local/content/sectionselector.php @@ -82,9 +82,8 @@ class sectionselector implements renderable, templatable { $numsections = $format->get_last_section_number(); while ($section <= $numsections) { $thissection = $modinfo->get_section_info($section); - $showsection = $thissection->uservisible || !$course->hiddensections; $url = course_get_url($course, $section); - if ($showsection && $url && $section != $data->currentsection) { + if ($thissection->uservisible && $url && $section != $data->currentsection) { $sectionmenu[$url->out(false)] = get_section_name($course, $section); } $section++; diff --git a/course/format/classes/output/section_renderer.php b/course/format/classes/output/section_renderer.php index 790cd05d605..a61dc2cd22c 100644 --- a/course/format/classes/output/section_renderer.php +++ b/course/format/classes/output/section_renderer.php @@ -801,8 +801,7 @@ abstract class section_renderer extends core_course_renderer { $numsections = course_get_format($course)->get_last_section_number(); while ($section <= $numsections) { $thissection = $modinfo->get_section_info($section); - $showsection = $thissection->uservisible or !$course->hiddensections; - if (($showsection) && ($section != $displaysection) && ($url = course_get_url($course, $section))) { + if (($thissection->uservisible) && ($section != $displaysection) && ($url = course_get_url($course, $section))) { $sectionmenu[$url->out(false)] = get_section_name($course, $section); } $section++; diff --git a/course/tests/behat/section_visibility.feature b/course/tests/behat/section_visibility.feature index 7bba43f9c3f..49677fc27a2 100644 --- a/course/tests/behat/section_visibility.feature +++ b/course/tests/behat/section_visibility.feature @@ -4,8 +4,7 @@ Feature: Show/hide course sections As a teacher I need to show or hide sections - @javascript - Scenario: Show / hide section icon functions correctly + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | @@ -43,7 +42,10 @@ Feature: Show/hide course sections | Forum name | Test hidden forum 32 name | | Description | Test hidden forum 32 description | | Availability | Show on course page | - And I am on "Course 1" course homepage + + @javascript + Scenario: Show / hide section icon functions correctly + Given I am on "Course 1" course homepage When I hide section "1" Then section "1" should be hidden And section "2" should be visible @@ -70,3 +72,60 @@ Feature: Show/hide course sections And section "2" should be visible And section "3" should be hidden And all activities in section "1" should be hidden + + @javascript + Scenario: Students can not navigate to hidden sections + Given I am on "Course 1" course homepage + And I hide section "2" + Given I navigate to "Settings" in current page administration + And I set the following fields to these values: + | Course layout | Show one section per page | + And I press "Save and display" + When I click on "Topic 1" "link" in the "region-main" "region" + Then I should see "Topic 2" in the "region-main" "region" + And I click on "Topic 2" "link" in the "region-main" "region" + And I should see "Topic 1" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I log out + And I log in as "student1" + And I am on "Course 1" course homepage + And I click on "Topic 1" "link" in the "region-main" "region" + And I should not see "Topic 2" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I click on "Topic 3" "link" in the "region-main" "region" + And I should not see "Topic 2" in the "region-main" "region" + And I should see "Topic 1" in the "region-main" "region" + + @javascript + Scenario: Students can not navigate to restricted sections + Given I am on "Course 1" course homepage + Given I navigate to "Settings" in current page administration + And I set the following fields to these values: + | Course layout | Show one section per page | + | Enable completion tracking | Yes | + And I press "Save and display" + And I add a "Label" to section "1" and I fill the form with: + | Label text | Test label | + | Completion tracking | Students can manually mark the activity as completed | + And I edit the section "2" + And I expand all fieldsets + And I click on "Add restriction..." "button" + And I click on "Activity completion" "button" in the "Add restriction..." "dialogue" + And I set the following fields to these values: + | cm | Test label | + | Required completion status | must be marked complete | + And I press "Save changes" + When I click on "Topic 1" "link" in the "region-main" "region" + Then I should see "Topic 2" in the "region-main" "region" + And I click on "Topic 2" "link" in the "region-main" "region" + And I should see "Topic 1" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I log out + And I log in as "student1" + And I am on "Course 1" course homepage + And I click on "Topic 1" "link" in the "region-main" "region" + And I should not see "Topic 2" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I click on "Topic 3" "link" in the "region-main" "region" + And I should not see "Topic 2" in the "region-main" "region" + And I should see "Topic 1" in the "region-main" "region"