MDL-60590 enrol_manual: only show cohorts with necessary capabilities

This commit is contained in:
Mark Nelson 2017-10-31 17:23:17 +08:00
parent 159b4e5d8c
commit 1bd70073c5

View File

@ -102,8 +102,11 @@ class enrol_manual_enrol_users_form extends moodleform {
);
$mform->addElement('autocomplete', 'userlist', get_string('selectusers', 'enrol_manual'), array(), $options);
$options = ['contextid' => $context->id, 'multiple' => true];
$mform->addElement('cohort', 'cohortlist', get_string('selectcohorts', 'enrol_manual'), $options);
// Confirm the user can search for cohorts before displaying select.
if (has_capability('moodle/cohort:manage', $context) || has_capability('moodle/cohort:view', $context)) {
$options = ['contextid' => $context->id, 'multiple' => true];
$mform->addElement('cohort', 'cohortlist', get_string('selectcohorts', 'enrol_manual'), $options);
}
$roles = get_assignable_roles($context);
$mform->addElement('select', 'roletoassign', get_string('assignrole', 'enrol_manual'), $roles);