Commit 12bdea2e authored by Dan Poltawski's avatar Dan Poltawski
Browse files

Merge branch 'MDL-35864' of https://github.com/danielneis/moodle

parents 02213adf ee9e079d
......@@ -34,6 +34,14 @@ $capabilities = array(
'archetypes' => array(
)
),
'enrol/category:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
......@@ -38,9 +38,14 @@ class enrol_category_plugin extends enrol_plugin {
* @param stdClass $instance
* @return bool
*/
public function instance_deleteable($instance) {
public function can_delete_instance($instance) {
global $DB;
$context = context_course::instance($instance->courseid);
if (!has_capability('enrol/database:config', $context)) {
return false;
}
if (!enrol_is_enabled('category')) {
return true;
}
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014051200; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2014051201; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->component = 'enrol_category'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 60;
......@@ -30,6 +30,18 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enrol_cohort_plugin extends enrol_plugin {
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/cohort:config', $context);
}
/**
* Returns localised name of enrol instance.
*
......
......@@ -34,4 +34,12 @@ $capabilities = array(
'manager' => CAP_ALLOW,
)
),
'enrol/database:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
......@@ -38,7 +38,11 @@ class enrol_database_plugin extends enrol_plugin {
* @param stdClass $instance
* @return bool
*/
public function instance_deleteable($instance) {
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
if (!has_capability('enrol/database:config', $context)) {
return false;
}
if (!enrol_is_enabled('database')) {
return true;
}
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014051200; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2014051201; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->component = 'enrol_database'; // Full name of the plugin (used for diagnostics)
//TODO: should we add cron sync?
......@@ -101,8 +101,9 @@ class enrol_flatfile_plugin extends enrol_plugin {
* @param object $instance
* @return bool
*/
public function instance_deleteable($instance) {
return true;
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/flatfile:manage', $context);
}
/**
......
......@@ -391,4 +391,16 @@ class enrol_guest_plugin extends enrol_plugin {
// No need to set mapping, we do not restore users or roles here.
$step->set_mapping('enrol', $oldid, 0);
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/guest:config', $context);
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capabilities for imsenterprise enrolment plugin.
*
* @package enrol_imsenterprise
* @copyright 2014 Daniel Neis Araujo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'enrol/imsenterprise:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
......@@ -791,4 +791,15 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
return $defaultcategoryid;
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/imsenterprise:config', $context);
}
}
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014051200;
$plugin->version = 2014051201;
$plugin->requires = 2014050800;
$plugin->component = 'enrol_imsenterprise';
$plugin->cron = 60;
......@@ -96,34 +96,52 @@ if ($canconfig and $action and confirm_sesskey()) {
$instance = $instances[$instanceid];
$plugin = $plugins[$instance->enrol];
if ($confirm) {
if (enrol_accessing_via_instance($instance)) {
if (!$confirm2) {
$yesurl = new moodle_url('/enrol/instances.php', array('id'=>$course->id, 'action'=>'delete', 'instance'=>$instance->id, 'confirm'=>1, 'confirm2'=>1, 'sesskey'=>sesskey()));
$displayname = $plugin->get_instance_name($instance);
$message = markdown_to_html(get_string('deleteinstanceconfirmself', 'enrol', array('name'=>$displayname)));
echo $OUTPUT->header();
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
echo $OUTPUT->footer();
die();
if ($plugin->can_delete_instance($instance)) {
if ($confirm) {
if (enrol_accessing_via_instance($instance)) {
if (!$confirm2) {
$yesurl = new moodle_url('/enrol/instances.php',
array('id' => $course->id,
'action' => 'delete',
'instance' => $instance->id,
'confirm' => 1,
'confirm2' => 1,
'sesskey' => sesskey()));
$displayname = $plugin->get_instance_name($instance);
$message = markdown_to_html(get_string('deleteinstanceconfirmself',
'enrol',
array('name' => $displayname)));
echo $OUTPUT->header();
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
echo $OUTPUT->footer();
die();
}
}
$plugin->delete_instance($instance);
redirect($PAGE->url);
}
$plugin->delete_instance($instance);
redirect($PAGE->url);
}
echo $OUTPUT->header();
$yesurl = new moodle_url('/enrol/instances.php', array('id'=>$course->id, 'action'=>'delete', 'instance'=>$instance->id, 'confirm'=>1,'sesskey'=>sesskey()));
$displayname = $plugin->get_instance_name($instance);
$users = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
if ($users) {
$message = markdown_to_html(get_string('deleteinstanceconfirm', 'enrol', array('name'=>$displayname, 'users'=>$users)));
} else {
$message = markdown_to_html(get_string('deleteinstancenousersconfirm', 'enrol', array('name'=>$displayname)));
echo $OUTPUT->header();
$yesurl = new moodle_url('/enrol/instances.php',
array('id' => $course->id,
'action' => 'delete',
'instance' => $instance->id,
'confirm' => 1,
'sesskey' => sesskey()));
$displayname = $plugin->get_instance_name($instance);
$users = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
if ($users) {
$message = markdown_to_html(get_string('deleteinstanceconfirm', 'enrol',
array('name' => $displayname,
'users' => $users)));
} else {
$message = markdown_to_html(get_string('deleteinstancenousersconfirm', 'enrol',
array('name' => $displayname)));
}
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
echo $OUTPUT->footer();
die();
}
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
echo $OUTPUT->footer();
die();
} else if ($action === 'disable') {
$instance = $instances[$instanceid];
......@@ -212,8 +230,7 @@ foreach ($instances as $instance) {
}
++$updowncount;
// edit links
if ($plugin->instance_deleteable($instance)) {
if ($plugin->can_delete_instance($instance)) {
$aurl = new moodle_url($url, array('action'=>'delete', 'instance'=>$instance->id));
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/delete', $strdelete, 'core', array('class' => 'iconsmall')));
}
......@@ -234,7 +251,7 @@ foreach ($instances as $instance) {
}
// link to instance management
if (enrol_is_enabled($instance->enrol)) {
if (enrol_is_enabled($instance->enrol) && $canconfig) {
if ($icons = $plugin->get_action_icons($instance)) {
$edit = array_merge($edit, $icons);
}
......
......@@ -106,7 +106,12 @@ class enrol_ldap_plugin extends enrol_plugin {
* @param object $instance
* @return bool
*/
public function instance_deleteable($instance) {
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
if (!has_capability('enrol/database:config', $context)) {
return false;
}
if (!enrol_is_enabled('ldap')) {
return true;
}
......@@ -1155,4 +1160,3 @@ class enrol_ldap_plugin extends enrol_plugin {
}
}
}
......@@ -553,4 +553,15 @@ class enrol_manual_plugin extends enrol_plugin {
groups_add_member($groupid, $userid);
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/manual:config', $context);
}
}
......@@ -148,5 +148,16 @@ class enrol_meta_plugin extends enrol_plugin {
require_once("$CFG->dirroot/enrol/meta/locallib.php");
enrol_meta_sync();
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/meta:config', $context);
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Capabilities for mnet enrolment plugin.
*
* @package enrol_mnet
* @copyright 2014 Daniel Neis Araujo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'enrol/mnet:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
......@@ -88,4 +88,15 @@ class enrol_mnet_plugin extends enrol_plugin {
return new moodle_url('/enrol/mnet/addinstance.php', array('id'=>$courseid));
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/mnet:config', $context);
}
}
......@@ -24,6 +24,6 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2014051200; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2014051201; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->component = 'enrol_mnet'; // Full name of the plugin (used for diagnostics)
......@@ -307,4 +307,15 @@ class enrol_paypal_plugin extends enrol_plugin {
$this->process_expirations($trace);
return 0;
}
/**
* Is it possible to delete enrol instance via standard UI?
*
* @param object $instance
* @return bool
*/
public function can_delete_instance($instance) {
$context = context_course::instance($instance->courseid);
return has_capability('enrol/paypal:config', $context);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment