diff --git a/admin/tool/capability/renderer.php b/admin/tool/capability/renderer.php index 64f8762b8b5..59e0f660e57 100644 --- a/admin/tool/capability/renderer.php +++ b/admin/tool/capability/renderer.php @@ -94,6 +94,7 @@ class tool_capability_renderer extends plugin_renderer_base { } $table->data = array(); + $childcontextsids = []; foreach ($capabilities as $capability) { if (empty($capabilitycontexts[$capability])) { $capabilitycontexts[$capability] = tool_capability_calculate_role_data($capability, $roles); @@ -122,6 +123,10 @@ class tool_capability_renderer extends plugin_renderer_base { if (!$onlydiff || count($permissiontypes) > 1) { $table->data[] = $row; } + if (!empty($contexts[$contextid]->children)) { + $childcontextsids = array_merge($childcontextsids, $contexts[$contextid]->children); + $childcontextsids = array_unique($childcontextsids); + } } // Start the list item, and print the context name as a link to the place to make changes. @@ -142,8 +147,8 @@ class tool_capability_renderer extends plugin_renderer_base { $html .= html_writer::tag('p', get_string('nodifferences', 'tool_capability')); } // If there are any child contexts, print them recursively. - if (!empty($contexts[$contextid]->children)) { - foreach ($contexts[$contextid]->children as $childcontextid) { + if (!empty($childcontextsids)) { + foreach ($childcontextsids as $childcontextid) { $html .= $this->capability_comparison_table($capabilities, $childcontextid, $roles, $onlydiff); } } diff --git a/admin/tool/capability/tests/behat/show_contexts.feature b/admin/tool/capability/tests/behat/show_contexts.feature new file mode 100644 index 00000000000..f61ca9e1c79 --- /dev/null +++ b/admin/tool/capability/tests/behat/show_contexts.feature @@ -0,0 +1,133 @@ +@tool @tool_capability +Feature: Show capabilities for multiple contexts + In order to check roles capabilities + As an admin + I need to be able to see capability overrides on several contexts + + Background: + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + | Course 2 | C2 | 0 | + And the following "permission overrides" exist: + | capability | permission | role | contextlevel | reference | + | enrol/category:config | Allow | student | Course | C1 | + | enrol/cohort:unenrol | Allow | student | Course | C2 | + And I log in as "admin" + And I navigate to "Users > Permissions > Capability overview" in site administration + + Scenario: Show capabilities table with one capability with overrides + When I set the following fields to these values: + | Capability: | enrol/category:config | + | Roles: | Student | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with one capability without overrides + When I set the following fields to these values: + | Capability: | enrol/cohort:config | + | Roles: | Student | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should not see "Permissions in Category: Miscellaneous" + And I should not see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with two capabilities, 1st without overrides and 2nd with + When I set the following fields to these values: + | Capability: | enrol/category:synchronised, enrol/category:config | + | Roles: | Student | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with two capabilities, 1st with overrides and 2nd without + When I set the following fields to these values: + | Capability: | enrol/category:config, enrol/cohort:config | + | Roles: | Student | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with two capabilities, none with overrides + When I set the following fields to these values: + | Capability: | enrol/category:synchronised, enrol/cohort:config | + | Roles: | Student | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should not see "Permissions in Category: Miscellaneous" + And I should not see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with capability with override and no role selected + When I set the following fields to these values: + | Capability: | enrol/category:config | + | Roles: | | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with capability without override and no role selected + When I set the following fields to these values: + | Capability: | enrol/cohort:config | + | Roles: | | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should not see "Permissions in Category: Miscellaneous" + And I should not see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with capability with two overrides on different contexts + When I set the following fields to these values: + | Capability: | enrol/category:config, enrol/cohort:unenrol | + | Roles: | | + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "Permissions in Course: Course 1" + And I should see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with capability with override and only diff + When I set the following fields to these values: + | Capability: | enrol/category:config | + | Roles: | Student, Teacher | + And I set the field "Show differences only" to "1" + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "There are no differences to show between selected roles in this context" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with capability without override and only diff and same capability + When I set the following fields to these values: + | Capability: | enrol/category:synchronised | + | Roles: | Student, Teacher | + And I set the field "Show differences only" to "1" + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "There are no differences to show between selected roles in this context" + And I should not see "Permissions in Category: Miscellaneous" + And I should not see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2" + + Scenario: Show capabilities table with two capabilities only one override and only diff checked + When I set the following fields to these values: + | Capability: | enrol/category:config, enrol/cohort:config | + | Roles: | Student, Teacher | + And I set the field "Show differences only" to "1" + And I click on "Get the overview" "button" + Then I should see "Permissions in System" + And I should see "Permissions in Category: Miscellaneous" + And I should see "There are no differences to show between selected roles in this context" + And I should see "Permissions in Course: Course 1" + And I should not see "Permissions in Course: Course 2"