diff --git a/cohort/index.php b/cohort/index.php index f0b225c346d..7290f44cd7c 100644 --- a/cohort/index.php +++ b/cohort/index.php @@ -117,9 +117,13 @@ if (!empty($searchquery)) { // Show the report. echo $report->output(); -// Show the delete selected button if there are records. -if ($DB->record_exists('cohort', [])) { +// Show the delete selected button if there are records and user can manage cohorts in current context. +$canmanagecohorts = has_capability('moodle/cohort:manage', $context); +if ($showall) { + $canmanagecohorts = $canmanagecohorts || core_course_category::has_capability_on_any('moodle/cohort:manage'); +} +if ($canmanagecohorts && $DB->record_exists('cohort', [])) { echo $OUTPUT->render(new single_button( new moodle_url('#'), get_string('deleteselected'),