MDL-23232 added support for enrol_plugin->all_enrol() which indicates plugin allows...
authorPetr Skoda <skodak@moodle.org>
Mon, 12 Jul 2010 17:46:48 +0000 (17:46 +0000)
committerPetr Skoda <skodak@moodle.org>
Mon, 12 Jul 2010 17:46:48 +0000 (17:46 +0000)
enrol/locallib.php
enrol/manual/db/access.php
enrol/manual/lang/en/enrol_manual.php
enrol/manual/lib.php
enrol/manual/manage.php
enrol/manual/version.php
lib/enrollib.php

index 7aeb9b6..0ad1c69 100644 (file)
@@ -629,7 +629,7 @@ class course_enrolment_manager {
     public function enrol_cohort_users($cohortid, $roleid) {
         global $DB;
         require_capability('moodle/course:enrolconfig', $this->get_context());
-        require_capability('enrol/manual:manage', $this->get_context());
+        require_capability('enrol/manual:enrol', $this->get_context());
         $instances = $this->get_enrolment_instances();
         $instance = false;
         foreach ($instances as $i) {
@@ -643,7 +643,7 @@ class course_enrolment_manager {
         }
         $plugin = enrol_get_plugin('manual');
 
-        $sql = "SELECT com.userid 
+        $sql = "SELECT com.userid
                 FROM {cohort_members} com
                 LEFT JOIN (
                     SELECT *
index 5c0194b..25a4373 100644 (file)
@@ -34,7 +34,7 @@ $capabilities = array(
         )
     ),
 
-    'enrol/manual:manage' => array(
+    'enrol/manual:enrol' => array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_COURSE,
         'legacy' => array(
@@ -43,6 +43,14 @@ $capabilities = array(
         )
     ),
 
+    'enrol/manual:manage' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'manager' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+        )
+    ),
 
     'enrol/manual:unenrol' => array(
         'captype' => 'write',
index 2ec7e3c..78be2dd 100644 (file)
@@ -29,7 +29,8 @@ $string['defaultperiod_desc'] = 'Default length of the default enrolment period
 $string['enrolledincourserole'] = 'Enrolled in "{$a->course}" as "{$a->role}"';
 $string['enrolusers'] = 'Enrol users';
 $string['manual:config'] = 'Configure manual enrol instances';
-$string['manual:manage'] = 'Manage enrolled users';
+$string['manual:enrol'] = 'Enrol users';
+$string['manual:manage'] = 'Manage user enrolments';
 $string['manual:unenrol'] = 'Unenrol users from the course';
 $string['manual:unenrolself'] = 'Unenrol self from the course';
 $string['pluginname'] = 'Manual enrolments';
index 57c7d57..9dbc89e 100644 (file)
@@ -32,6 +32,11 @@ class enrol_manual_plugin extends enrol_plugin {
         return false;
     }
 
+    public function allow_enrol(stdClass $instance) {
+        // users with enrol cap may unenrol other users manually manually
+        return true;
+    }
+
     public function allow_unenrol(stdClass $instance) {
         // users with unenrol cap may unenrol other users manually manually
         return true;
@@ -65,7 +70,7 @@ class enrol_manual_plugin extends enrol_plugin {
 
         $context = get_context_instance(CONTEXT_COURSE, $instance->courseid, MUST_EXIST);
 
-        if (!has_capability('enrol/manual:manage', $context)) {
+        if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) {
             return NULL;
         }
 
index 3a37aa8..c6f35fc 100644 (file)
@@ -35,7 +35,9 @@ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_
 $context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
 
 require_login($course);
+require_capability('enrol/manual:enrol', $context);
 require_capability('enrol/manual:manage', $context);
+require_capability('enrol/manual:unenrol', $context);
 
 $instance = $DB->get_record('enrol', array('id'=>$enrolid, 'enrol'=>'manual'), '*', MUST_EXIST);
 if ($roleid < 0) {
index fd209b7..cb682a1 100644 (file)
@@ -23,4 +23,4 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-$plugin->version = 2010061500;
+$plugin->version = 2010071200;
index 9f6ac8e..b681ec4 100644 (file)
@@ -749,13 +749,25 @@ abstract class enrol_plugin {
         return true;
     }
 
+    /**
+     * Does this plugin allow manual enrolments?
+     *
+     * @param stdClass $instance course enrol instance
+     * All plugins allowing this must implement 'enrol/xxx:enrol' capability
+     *
+     * @return bool - true means user with 'enrol/xxx:enrol' may enrol others freely, trues means nobody may add more enrolments manually
+     */
+    public function allow_enrol(stdClass $instance) {
+        return false;
+    }
+
     /**
      * Does this plugin allow manual unenrolments?
      *
      * @param stdClass $instance course enrol instance
-     * ALl plugins allowing this must implement 'enrol/xxx:unenrol' capability
+     * All plugins allowing this must implement 'enrol/xxx:unenrol' capability
      *
-     * @return bool - true means anybody may unenrol others freely, trues means nobody may touch user_enrolments
+     * @return bool - true means user with 'enrol/xxx:unenrol' may unenrol others freely, trues means nobody may touch user_enrolments
      */
     public function allow_unenrol(stdClass $instance) {
         return false;
@@ -764,7 +776,7 @@ abstract class enrol_plugin {
     /**
      * Does this plugin allow manual changes in user_enrolments table?
      *
-     * ALl plugins allowing this must implement 'enrol/xxx:manage' capability
+     * All plugins allowing this must implement 'enrol/xxx:manage' capability
      *
      * @param stdClass $instance course enrol instance
      * @return bool - true means it is possible to change enrol period and status in user_enrolments table