diff --git a/mod/survey/lib.php b/mod/survey/lib.php index e3cc8f9b004..d0ae2cf5072 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -814,10 +814,19 @@ function survey_supports($feature) { */ function survey_extend_settings_navigation(settings_navigation $settings, navigation_node $surveynode) { global $DB; - if (has_capability('mod/survey:readresponses', $settings->get_page()->cm->context)) { - $cm = get_coursemodule_from_id('survey', $settings->get_page()->cm->id); + + $cm = get_coursemodule_from_id('survey', $settings->get_page()->cm->id); + $context = context_module::instance($cm->id); + + // Check to see if groups are being used in this survey, confirm user can access. + $groupmode = groups_get_activity_groupmode($cm); + $currentgroup = groups_get_activity_group($cm, true); + + if (has_capability('mod/survey:readresponses', $context) && + !($currentgroup === 0 && $groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context))) { + $survey = $DB->get_record("survey", ["id" => $cm->instance]); - $url = new moodle_url('/mod/survey/report.php', ['id' => $settings->get_page()->cm->id]); + $url = new moodle_url('/mod/survey/report.php', ['id' => $cm->id]); if ($survey && ($survey->template != SURVEY_CIQ)) { $url->param('action', 'summary'); } else { diff --git a/mod/survey/tests/behat/survey_groups.feature b/mod/survey/tests/behat/survey_groups.feature index 72a22d19fee..ca129764231 100644 --- a/mod/survey/tests/behat/survey_groups.feature +++ b/mod/survey/tests/behat/survey_groups.feature @@ -76,7 +76,10 @@ Feature: Viewing response reports by group | survey | user | all | G1 | G2 | user1 | user2 | user3 | user4 | | survey1 | teacher1 | should | should | should | should | should | should | should | | survey1 | noneditor1 | should not | should | should not | should | should not | should not | should not | - | survey1 | noneditor2 | should | should not | should not | should | should | should | should | | survey2 | teacher1 | should | should | should | should | should | should | should | | survey2 | noneditor1 | should | should | should | should | should not | should not | should not | | survey2 | noneditor2 | should | should | should | should | should not | should not | should not | + + Scenario: Non-editing teacher without access to any groups should not see survey results in separate groups mode + Given I am on the "survey1" "survey activity" page logged in as "noneditor2" + Then I should not see "Response reports"