Skip to content

Commit

Permalink
MDL-79980 mod_survey: remove responses link if user cannot access.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden authored and sarjona committed Dec 7, 2023
1 parent c142ad2 commit 9badb9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion mod/survey/lib.php
Expand Up @@ -808,7 +808,16 @@ function survey_supports($feature) {
function survey_extend_settings_navigation($settings, $surveynode) {
global $PAGE;

if (has_capability('mod/survey:readresponses', $PAGE->cm->context)) {
$cm = get_coursemodule_from_id('survey', $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))) {

$responsesnode = $surveynode->add(get_string("responsereports", "survey"));

$url = new moodle_url('/mod/survey/report.php', array('id' => $PAGE->cm->id, 'action'=>'summary'));
Expand Down
5 changes: 4 additions & 1 deletion mod/survey/view.php
Expand Up @@ -83,7 +83,10 @@
$currentgroup = 0;
}

if (has_capability('mod/survey:readresponses', $context)) {
$currentactivitygroup = groups_get_activity_group($cm, true);
if (has_capability('mod/survey:readresponses', $context) &&
!($currentactivitygroup === 0 && $groupmode == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $context))) {

$numusers = survey_count_responses($survey->id, $currentgroup, $groupingid);
echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\">".
get_string("viewsurveyresponses", "survey", $numusers)."</a></div>";
Expand Down

0 comments on commit 9badb9e

Please sign in to comment.