diff --git a/CHANGELOG.md b/CHANGELOG.md index 01d61ed..cd60111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## Unresolved +### Fixed +- Course index disappears for students if there are sections with access restrictions #89 + ## [4.1.0] - 2024-05-22 ### Added - Support for Moodle 4.4, #83 diff --git a/lib.php b/lib.php index 3546a3c..7df904f 100644 --- a/lib.php +++ b/lib.php @@ -196,7 +196,7 @@ public function get_view_url($section, $options = []) { $sectionno = $this->resolve_section_number($section); $section = $this->get_section($sectionno); - if ($sectionno && (!$section->uservisible || !$this->is_section_real_available($section))) { + if ($sectionno && !$this->is_section_visible($section)) { return empty($options['navigation']) ? $url : null; } diff --git a/tests/behat/section_restriction.feature b/tests/behat/section_restriction.feature new file mode 100644 index 0000000..b8d04db --- /dev/null +++ b/tests/behat/section_restriction.feature @@ -0,0 +1,95 @@ +@format @format_flexsections @javascript +Feature: Testing section restrictions in format_flexsections + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Sam | Student | student1@example.com | + | student2 | Mary | Student | student2@example.com | + | teacher1 | Terry | Teacher | teacher1@example.com | + And the following config values are set as admin: + | maxsectiondepth | 4 | format_flexsections | + And the following "courses" exist: + | fullname | shortname | format | numsections | enablecompletion | + | Course 1 | C1 | flexsections | 3 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | student1 | C1 | student | + | student2 | C1 | student | + | teacher1 | C1 | editingteacher | + And the following "activities" exist: + | activity | course | idnumber | intro | name | section | completion | + | assign | C1 | a1 | x | First module | 1 | 1 | + | forum | C1 | a2 | x | Second module | 2 | | + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I open section "2" edit menu + And I click on "Move" "link" in the "#section-2 .action-menu" "css_element" + And I click on "As a subsection of 'Topic 1'" "link" in the "Move section" "dialogue" + And I open section "3" edit menu + And I click on "Add subsection" "link" in the "li#section-3" "css_element" + + Scenario: Restricting section in flexsections format displays this section as not available + And I edit the section "1" + And I expand all fieldsets + And I click on "Add restriction..." "button" in the "root" "core_availability > Availability Button Area" + And I click on "Date" "button" in the "Add restriction..." "dialogue" + And I set the field "year" in the "1" "availability_date > Date Restriction" to "2023" + And I set the field "Direction" in the "1" "availability_date > Date Restriction" to "until" + And I press "Save changes" + And I click on "Open course index" "button" + And I should see "Topic 1" in the "courseindex-content" "region" + And I should see "First module" in the "courseindex-content" "region" + And I should see "Topic 2" in the "courseindex-content" "region" + And I should see "Second module" in the "courseindex-content" "region" + And I should see "Topic 3" in the "courseindex-content" "region" + And I should see "Topic 4" in the "courseindex-content" "region" + And I log out + And I change window size to "large" + And I log in as "student1" + And I am on "Course 1" course homepage + And I should see "Topic 1" in the "courseindex-content" "region" + And I should not see "First module" in the "courseindex-content" "region" + # And I should not see "Topic 2" in the "courseindex-content" "region" + # And I should not see "Second module" in the "courseindex-content" "region" + And I should see "Topic 3" in the "courseindex-content" "region" + And I should see "Topic 4" in the "courseindex-content" "region" + And I should see "Topic 1" in the "region-main" "region" + And I should not see "First module" in the "region-main" "region" + # And I should not see "Topic 2" in the "region-main" "region" + # And I should not see "Second module" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I should see "Topic 4" in the "region-main" "region" + + Scenario: Restricting and hiding section in flexsections format hides this section from students + And I edit the section "1" + And I expand all fieldsets + And I click on "Add restriction..." "button" in the "root" "core_availability > Availability Button Area" + And I click on "Date" "button" in the "Add restriction..." "dialogue" + And I set the field "year" in the "1" "availability_date > Date Restriction" to "2023" + And I set the field "Direction" in the "1" "availability_date > Date Restriction" to "until" + And I click on ".availability-item .availability-eye img" "css_element" + And I press "Save changes" + And I click on "Open course index" "button" + And I should see "Topic 1" in the "courseindex-content" "region" + And I should see "First module" in the "courseindex-content" "region" + And I should see "Topic 2" in the "courseindex-content" "region" + And I should see "Second module" in the "courseindex-content" "region" + And I should see "Topic 3" in the "courseindex-content" "region" + And I should see "Topic 4" in the "courseindex-content" "region" + And I log out + And I change window size to "large" + And I log in as "student1" + And I am on "Course 1" course homepage + And I should not see "Topic 1" in the "courseindex-content" "region" + And I should not see "First module" in the "courseindex-content" "region" + And I should not see "Topic 2" in the "courseindex-content" "region" + And I should not see "Second module" in the "courseindex-content" "region" + And I should see "Topic 3" in the "courseindex-content" "region" + And I should see "Topic 4" in the "courseindex-content" "region" + And I should not see "Topic 1" in the "region-main" "region" + And I should not see "First module" in the "region-main" "region" + And I should not see "Topic 2" in the "region-main" "region" + And I should not see "Second module" in the "region-main" "region" + And I should see "Topic 3" in the "region-main" "region" + And I should see "Topic 4" in the "region-main" "region"