This commit is contained in:
Huong Nguyen 2024-07-10 09:56:48 +07:00
commit 5f37f860e2
No known key found for this signature in database
GPG Key ID: 40D88AB693A3E72A
2 changed files with 35 additions and 1 deletions

View File

@ -277,8 +277,11 @@ class content_item_service {
return course_allowed_module($course, explode('_', $parents[$contentitem->get_component_name()])[1], $user);
});
$format = course_get_format($course);
$maxsectionsreached = ($format->get_last_section_number() >= $format->get_max_sections());
// Now, check there is no delegated section into a delegated section.
if (is_null($sectioninfo) || $sectioninfo->is_delegated()) {
if (is_null($sectioninfo) || $sectioninfo->is_delegated() || $maxsectionsreached) {
$availablecontentitems = array_filter($availablecontentitems, function($contentitem){
return !sectiondelegate::has_delegate_class($contentitem->get_component_name());
});

View File

@ -0,0 +1,31 @@
@mod @mod_subsection
Feature: Teacher can only add subsection when certain conditions are met
In order to limit subsections
As an teacher
I need to create subsections only when possible
Background:
Given I enable "subsection" "mod" plugin
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | numsections | initsections |
| Course 1 | C1 | 0 | 5 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
@javascript
Scenario: The activity chooser filter subsections when section limit is reached
Given the following config values are set as admin:
| maxsections | 10 | moodlecourse |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I click on "Add an activity or resource" "button" in the "Section 1" "section"
And I should see "Subsection" in the "Add an activity or resource" "dialogue"
When the following config values are set as admin:
| maxsections | 4 | moodlecourse |
And I am on "Course 1" course homepage
Then I click on "Add an activity or resource" "button" in the "Section 1" "section"
And I should not see "Subsection" in the "Add an activity or resource" "dialogue"