Skip to content

Commit

Permalink
Merge branch 'MDL-59369-master' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 26, 2017
2 parents afa752e + 90ffcfa commit 7740e18
Show file tree
Hide file tree
Showing 29 changed files with 1,247 additions and 61 deletions.
4 changes: 3 additions & 1 deletion enrol/cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/cohort:unenrol', $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
return $actions;
}
Expand Down
4 changes: 3 additions & 1 deletion enrol/database/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/database:unenrol', $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
return $actions;
}
Expand Down
2 changes: 1 addition & 1 deletion enrol/editenrolment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);

// The URL of the enrolled users page for the course.
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
$usersurl = new moodle_url('/user/index.php', array('id' => $course->id));

// Do not allow any changes if plugin disabled, not available or not suitable.
if (!$plugin = enrol_get_plugin($instance->enrol)) {
Expand Down
17 changes: 7 additions & 10 deletions enrol/editenrolment_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@

class enrol_user_enrolment_form extends moodleform {
function definition() {
global $CFG, $DB;

$mform = $this->_form;

$user = $this->_customdata['user'];
$course = $this->_customdata['course'];
$ue = $this->_customdata['ue'];

$mform->addElement('header','general', '');
$ue = $this->_customdata['ue'];
$modal = !empty($this->_customdata['modal']);

$options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
Expand All @@ -56,7 +51,10 @@ function definition() {
$mform->addElement('hidden', 'ifilter');
$mform->setType('ifilter', PARAM_ALPHA);

$this->add_action_buttons();
// Show action buttons if this is not being rendered as a fragment.
if (!$modal) {
$this->add_action_buttons();
}

$this->set_data(array(
'ue' => $ue->id,
Expand All @@ -71,8 +69,7 @@ function validation($data, $files) {

if (!empty($data['timestart']) and !empty($data['timeend'])) {
if ($data['timestart'] >= $data['timeend']) {
$errors['timestart'] = get_string('error');
$errors['timeend'] = get_string('error');
$errors['timeend'] = get_string('enroltimeendinvalid', 'enrol');
}
}

Expand Down
101 changes: 101 additions & 0 deletions enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,107 @@ public static function get_course_enrolment_methods_returns() {
)
);
}

/**
* Returns description of edit_user_enrolment() parameters
*
* @return external_function_parameters
*/
public static function edit_user_enrolment_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'User enrolment ID'),
'ueid' => new external_value(PARAM_INT, 'User enrolment ID'),
'status' => new external_value(PARAM_INT, 'Enrolment status'),
'timestart' => new external_value(PARAM_INT, 'Enrolment start timestamp', VALUE_DEFAULT, 0),
'timeend' => new external_value(PARAM_INT, 'Enrolment end timestamp', VALUE_DEFAULT, 0),
)
);
}

/**
* External function that updates a given user enrolment.
*
* @param int $courseid The course ID.
* @param int $ueid The user enrolment ID.
* @param int $status The enrolment status.
* @param int $timestart Enrolment start timestamp.
* @param int $timeend Enrolment end timestamp.
* @return array An array consisting of the processing result, errors and form output, if available.
*/
public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
global $CFG, $DB, $PAGE;

$params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
'courseid' => $courseid,
'ueid' => $ueid,
'status' => $status,
'timestart' => $timestart,
'timeend' => $timeend,
]);

$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);

$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
$userenroldata = [
'status' => $params['status'],
'timestart' => $params['timestart'],
'timeend' => $params['timeend'],
];

$result = false;
$errors = [];

// Validate data against the edit user enrolment form.
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
$customformdata = [
'ue' => $userenrolment,
'modal' => true,
];
$mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
$mform->set_data($userenroldata);
$validationerrors = $mform->validation($userenroldata, null);
if (empty($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}

return [
'result' => $result,
'errors' => $errors,
];
}

/**
* Returns description of edit_user_enrolment() result value
*
* @return external_description
*/
public static function edit_user_enrolment_returns() {
return new external_single_structure(
array(
'result' => new external_value(PARAM_BOOL, 'True if the user\'s enrolment was successfully updated'),
'errors' => new external_multiple_structure(
new external_single_structure(
array(
'key' => new external_value(PARAM_TEXT, 'The data that failed the validation'),
'message' => new external_value(PARAM_TEXT, 'The error message'),
)
), 'List of validation errors'
),
)
);
}
}

/**
Expand Down
7 changes: 5 additions & 2 deletions enrol/flatfile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/flatfile:unenrol", $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
if ($this->allow_manage($instance) && has_capability("enrol/flatfile:manage", $context)) {
$url = new moodle_url('/enrol/editenrolment.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams);
}
return $actions;
}
Expand Down
7 changes: 4 additions & 3 deletions enrol/lti/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/lti:unenrol", $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
array('class' => 'unenrollink', 'rel' => $ue->id));
$actionparams);
}
if ($this->allow_manage($instance) && has_capability("enrol/lti:manage", $context)) {
$url = new moodle_url('/enrol/editenrolment.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url,
array('class' => 'editenrollink', 'rel' => $ue->id));
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams);
}
return $actions;
}
Expand Down
7 changes: 5 additions & 2 deletions enrol/manual/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/manual:unenrol", $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
if ($this->allow_manage($instance) && has_capability("enrol/manual:manage", $context)) {
$url = new moodle_url('/enrol/editenrolment.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams);
}
return $actions;
}
Expand Down
4 changes: 3 additions & 1 deletion enrol/meta/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol_user($instance, $ue) && has_capability('enrol/meta:unenrol', $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
return $actions;
}
Expand Down
27 changes: 20 additions & 7 deletions enrol/meta/tests/behat/enrol_meta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ Feature: Enrolments are synchronised with meta courses
| Course 1 | C1C1 |
| Course 2 | C2C2 |
| Course 3 | C3C3 |
| Course 4 | C4C4 |
And the following "groups" exist:
| name | course | idnumber |
| Groupcourse 1 | C3C3 | G1 |
| Groupcourse 2 | C3C3 | G2 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1C1 | student |
| student2 | C1C1 | student |
| student3 | C1C1 | student |
| student4 | C1C1 | student |
| student1 | C2C2 | student |
| student2 | C2C2 | student |
| user | course | role | status |
| student1 | C1C1 | student | 0 |
| student2 | C1C1 | student | 0 |
| student3 | C1C1 | student | 0 |
| student4 | C1C1 | student | 0 |
| student1 | C2C2 | student | 0 |
| student2 | C2C2 | student | 0 |
| student1 | C4C4 | student | 0 |
| student2 | C4C4 | student | 1 |
And I log in as "admin"
And I navigate to "Manage enrol plugins" node in "Site administration > Plugins > Enrolments"
And I click on "Enable" "link" in the "Course meta link" "table_row"
Expand Down Expand Up @@ -105,3 +108,13 @@ Feature: Enrolments are synchronised with meta courses
And I should see "Groupcourse 1" in the "Student 4" "table_row"
And I should see "Course 2" in the "Student 1" "table_row"
And I should not see "Course 2" in the "Student 3" "table_row"

Scenario: Unenrol a user from the course participants page that was enrolled via course meta link.
Given I am on "Course 3" course homepage
And I add "Course meta link" enrolment method with:
| Link course | C4C4 |
And I navigate to course participants
# Suspended users can be unenrolled.
When I click on "//a[@data-action='unenrol']" "xpath_element" in the "student2" "table_row"
And I click on "Yes" "button"
Then I should not see "Student 2" in the "participants" "table"
7 changes: 5 additions & 2 deletions enrol/paypal/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol($instance) && has_capability("enrol/paypal:unenrol", $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
if ($this->allow_manage($instance) && has_capability("enrol/paypal:manage", $context)) {
$url = new moodle_url('/enrol/editenrolment.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams);
}
return $actions;
}
Expand Down
7 changes: 5 additions & 2 deletions enrol/self/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,14 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
$params['ue'] = $ue->id;
if ($this->allow_unenrol($instance) && has_capability("enrol/self:unenrol", $context)) {
$url = new moodle_url('/enrol/unenroluser.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url, array('class'=>'unenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL);
$actions[] = new user_enrolment_action(new pix_icon('t/delete', ''), get_string('unenrol', 'enrol'), $url,
$actionparams);
}
if ($this->allow_manage($instance) && has_capability("enrol/self:manage", $context)) {
$url = new moodle_url('/enrol/editenrolment.php', $params);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, array('class'=>'editenrollink', 'rel'=>$ue->id));
$actionparams = array('class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT);
$actions[] = new user_enrolment_action(new pix_icon('t/edit', ''), get_string('edit'), $url, $actionparams);
}
return $actions;
}
Expand Down
38 changes: 38 additions & 0 deletions enrol/self/tests/behat/self_enrolment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,41 @@ Feature: Users can auto-enrol themself in courses where self enrolment is allowe
Then I should see "Topic 1"
And I should not see "Enrolment options"
And I should not see "Enrol me in this course"

@javascript
Scenario: Edit a self-enrolled user's enrolment from the course participants page
Given I log in as "teacher1"
And I am on "Course 1" course homepage
When I add "Self enrolment" enrolment method with:
| Custom instance name | Test student enrolment |
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I press "Enrol me"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
When I click on "//a[@data-action='editenrolment']" "xpath_element" in the "student1" "table_row"
And I should see "Edit Student 1's enrolment"
And I set the field "Status" to "Suspended"
And I click on "Save changes" "button"
Then I should see "Suspended" in the "student1" "table_row"

@javascript
Scenario: Unenrol a self-enrolled student from the course participants page
Given I log in as "teacher1"
And I am on "Course 1" course homepage
When I add "Self enrolment" enrolment method with:
| Custom instance name | Test student enrolment |
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And I press "Enrol me"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
When I click on "//a[@data-action='unenrol']" "xpath_element" in the "student1" "table_row"
And I click on "Yes" "button"
Then I should not see "Student 1" in the "participants" "table"
Loading

0 comments on commit 7740e18

Please sign in to comment.