diff --git a/enrol/self/db/access.php b/enrol/self/db/access.php index 4d3481058cd..df31d2d3d5d 100644 --- a/enrol/self/db/access.php +++ b/enrol/self/db/access.php @@ -73,4 +73,13 @@ $capabilities = array( ) ), + /* Ability to enrol self in courses. */ + 'enrol/self:enrolself' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'user' => CAP_ALLOW, + ) + ), + ); diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index 504b7bafe4d..4479ae1c3c1 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -98,6 +98,7 @@ $string['requirepassword'] = 'Require enrolment key'; $string['requirepassword_desc'] = 'Require enrolment key in new courses and prevent removing of enrolment key from existing courses.'; $string['role'] = 'Default assigned role'; $string['self:config'] = 'Configure self enrol instances'; +$string['self:enrolself'] = 'Self enrol in course'; $string['self:holdkey'] = 'Appear as the self enrolment key holder'; $string['self:manage'] = 'Manage enrolled users'; $string['self:unenrol'] = 'Unenrol users from course'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index f5beff88f19..4807f49e0a7 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -248,6 +248,11 @@ class enrol_self_plugin extends enrol_plugin { return get_string('canntenrol', 'enrol_self'); } + // Check if user has the capability to enrol in this context. + if (!has_capability('enrol/self:enrolself', context_course::instance($instance->courseid))) { + return get_string('canntenrol', 'enrol_self'); + } + if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) { return get_string('canntenrolearly', 'enrol_self', userdate($instance->enrolstartdate)); } diff --git a/enrol/self/version.php b/enrol/self/version.php index 2063b3f29c7..355fc52248a 100644 --- a/enrol/self/version.php +++ b/enrol/self/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020061500; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2020061501; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2020060900; // Requires this Moodle version $plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics) diff --git a/version.php b/version.php index 3d5bc974958..e2526934e6f 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2020071500.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2020071500.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20200711)'; // Human-friendly version name