Skip to content

Commit

Permalink
Fix course index disappearing with restricted sections #89
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Oct 2, 2024
1 parent 37a6f8d commit 98632d6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
95 changes: 95 additions & 0 deletions tests/behat/section_restriction.feature
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 98632d6

Please sign in to comment.