MDL-45849 enrol_self: Added self enrol capability

This commit is contained in:
Peter Burnett 2020-07-06 14:36:58 +10:00
parent 49a9e8b07d
commit 37c99bd07e
4 changed files with 16 additions and 1 deletions

View File

@ -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,
)
),
);

View File

@ -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';

View File

@ -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));
}

View File

@ -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)