Skip to content

Commit

Permalink
MDL-45849 enrol_self: Added self enrol capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Peterburnett committed Jul 10, 2020
1 parent 49a9e8b commit 37c99bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions enrol/self/db/access.php
Expand Up @@ -73,4 +73,13 @@
)
),

/* Ability to enrol self in courses. */
'enrol/self:enrolself' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'user' => CAP_ALLOW,
)
),

);
1 change: 1 addition & 0 deletions enrol/self/lang/en/enrol_self.php
Expand Up @@ -98,6 +98,7 @@
$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';
Expand Down
5 changes: 5 additions & 0 deletions enrol/self/lib.php
Expand Up @@ -248,6 +248,11 @@ public function can_self_enrol(stdClass $instance, $checkuserenrolment = true) {
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));
}
Expand Down
2 changes: 1 addition & 1 deletion enrol/self/version.php
Expand Up @@ -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)

0 comments on commit 37c99bd

Please sign in to comment.