MDL-46509 enrol: Require 'enrol/PLUGIN:config' capabilities to show/hide enrollment instances
This commit is contained in:
committed by
Daniel Neis Araujo
parent
0594336d92
commit
b5a289c4e8
@@ -53,6 +53,17 @@ class enrol_category_plugin extends enrol_plugin {
|
||||
return !$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/category:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns link to page which may be used to add new instance of enrolment plugin in course.
|
||||
* @param int $courseid
|
||||
|
||||
@@ -360,6 +360,17 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||
// Nothing to do here, the group members are added in $this->restore_group_restored()
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/cohort:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,6 +54,17 @@ class enrol_database_plugin extends enrol_plugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/database:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this plugin allow manual unenrolment of a specific user?
|
||||
* Yes, but only if user suspended...
|
||||
|
||||
@@ -106,6 +106,17 @@ class enrol_flatfile_plugin extends enrol_plugin {
|
||||
return has_capability('enrol/flatfile:manage', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/flatfile:manage', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of the user enrolment actions.
|
||||
*
|
||||
|
||||
@@ -403,4 +403,14 @@ class enrol_guest_plugin extends enrol_plugin {
|
||||
return has_capability('enrol/guest:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/guest:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,4 +804,15 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/imsenterprise:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/imsenterprise:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
+27
-16
@@ -146,28 +146,39 @@ if ($canconfig and $action and confirm_sesskey()) {
|
||||
} else if ($action === 'disable') {
|
||||
$instance = $instances[$instanceid];
|
||||
$plugin = $plugins[$instance->enrol];
|
||||
if ($instance->status != ENROL_INSTANCE_DISABLED) {
|
||||
if (enrol_accessing_via_instance($instance)) {
|
||||
if (!$confirm2) {
|
||||
$yesurl = new moodle_url('/enrol/instances.php', array('id'=>$course->id, 'action'=>'disable', 'instance'=>$instance->id, 'confirm2'=>1, 'sesskey'=>sesskey()));
|
||||
$displayname = $plugin->get_instance_name($instance);
|
||||
$message = markdown_to_html(get_string('disableinstanceconfirmself', 'enrol', array('name'=>$displayname)));
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
||||
echo $OUTPUT->footer();
|
||||
die();
|
||||
if ($plugin->can_hide_show_instance($instance)) {
|
||||
if ($instance->status != ENROL_INSTANCE_DISABLED) {
|
||||
if (enrol_accessing_via_instance($instance)) {
|
||||
if (!$confirm2) {
|
||||
$yesurl = new moodle_url('/enrol/instances.php',
|
||||
array('id' => $course->id,
|
||||
'action' => 'disable',
|
||||
'instance' => $instance->id,
|
||||
'confirm2' => 1,
|
||||
'sesskey' => sesskey()));
|
||||
$displayname = $plugin->get_instance_name($instance);
|
||||
$message = markdown_to_html(get_string('disableinstanceconfirmself',
|
||||
'enrol',
|
||||
array('name' => $displayname)));
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
||||
echo $OUTPUT->footer();
|
||||
die();
|
||||
}
|
||||
}
|
||||
$plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
$plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
|
||||
} else if ($action === 'enable') {
|
||||
$instance = $instances[$instanceid];
|
||||
$plugin = $plugins[$instance->enrol];
|
||||
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||
$plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
|
||||
redirect($PAGE->url);
|
||||
if ($plugin->can_hide_show_instance($instance)) {
|
||||
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||
$plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +246,7 @@ foreach ($instances as $instance) {
|
||||
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/delete', $strdelete, 'core', array('class' => 'iconsmall')));
|
||||
}
|
||||
|
||||
if (enrol_is_enabled($instance->enrol)) {
|
||||
if (enrol_is_enabled($instance->enrol) && $plugin->can_hide_show_instance($instance)) {
|
||||
if ($instance->status == ENROL_INSTANCE_ENABLED) {
|
||||
$aurl = new moodle_url($url, array('action'=>'disable', 'instance'=>$instance->id));
|
||||
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/hide', $strdisable, 'core', array('class' => 'iconsmall')));
|
||||
|
||||
@@ -124,6 +124,17 @@ class enrol_ldap_plugin extends enrol_plugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/ldap:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces synchronisation of user enrolments with LDAP server.
|
||||
* It creates courses if the plugin is configured to do so.
|
||||
|
||||
@@ -564,4 +564,15 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/manual:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/manual:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -152,12 +152,22 @@ class enrol_meta_plugin extends enrol_plugin {
|
||||
/**
|
||||
* Is it possible to delete enrol instance via standard UI?
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/meta:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/meta:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -92,11 +92,22 @@ class enrol_mnet_plugin extends enrol_plugin {
|
||||
/**
|
||||
* Is it possible to delete enrol instance via standard UI?
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/mnet:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/mnet:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -311,11 +311,22 @@ class enrol_paypal_plugin extends enrol_plugin {
|
||||
/**
|
||||
* Is it possible to delete enrol instance via standard UI?
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/paypal:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/paypal:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -651,11 +651,22 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
/**
|
||||
* Is it possible to delete enrol instance via standard UI?
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/self:config', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
return has_capability('enrol/self:config', $context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ information provided here is intended especially for developers.
|
||||
=== 2.8 ===
|
||||
|
||||
* enrol_plugin::instance_deleteable() is deprecated and has been replaced by enrol_plugin::can_delete_instance()
|
||||
* enrol_plugin::can_hide_show_instance() is a new function to control who can hide/show enrolment instances.
|
||||
Returns true by default but plugins must implement their own logic.
|
||||
|
||||
=== 2.6 ===
|
||||
|
||||
|
||||
+12
-1
@@ -1554,13 +1554,24 @@ abstract class enrol_plugin {
|
||||
/**
|
||||
* Is it possible to delete enrol instance via standard UI?
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete_instance($instance) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is it possible to hide/show enrol instance via standard UI?
|
||||
*
|
||||
* @param stdClass $instance
|
||||
* @return bool
|
||||
*/
|
||||
public function can_hide_show_instance($instance) {
|
||||
debugging("The enrolment plugin '".$this->get_name()."' should override the function can_hide_show_instance().", DEBUG_DEVELOPER);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns link to manual enrol UI if exists.
|
||||
* Does the access control tests automatically.
|
||||
|
||||
Reference in New Issue
Block a user