Merge branch 'MDL-45579-master' of git://github.com/FMCorz/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2014-06-10 20:56:14 +02:00
4 changed files with 102 additions and 3 deletions
+16 -3
View File
@@ -111,11 +111,19 @@ class group_form extends moodleform {
}
}
if (!empty($CFG->groupenrolmentkeypolicy) and $data['enrolmentkey'] != '' and $group->enrolmentkey !== $data['enrolmentkey']) {
// enforce password policy only if changing password
if ($data['enrolmentkey'] != '') {
$errmsg = '';
if (!check_password_policy($data['enrolmentkey'], $errmsg)) {
if (!empty($CFG->groupenrolmentkeypolicy) && $group->enrolmentkey !== $data['enrolmentkey']
&& !check_password_policy($data['enrolmentkey'], $errmsg)) {
// Enforce password policy when the password is changed.
$errors['enrolmentkey'] = $errmsg;
} else {
// Prevent twice the same enrolment key in course groups.
$sql = "SELECT id FROM {groups} WHERE id <> :groupid AND courseid = :courseid AND enrolmentkey = :key";
$params = array('groupid' => $data['id'], 'courseid' => $COURSE->id, 'key' => $data['enrolmentkey']);
if ($DB->record_exists_sql($sql, $params)) {
$errors['enrolmentkey'] = get_string('enrolmentkeyalreadyinuse', 'group');
}
}
}
@@ -123,6 +131,11 @@ class group_form extends moodleform {
$errors['name'] = get_string('groupnameexists', 'group', $name);
} else if (!empty($idnumber) && groups_get_group_by_idnumber($COURSE->id, $idnumber)) {
$errors['idnumber']= get_string('idnumbertaken');
} else if ($data['enrolmentkey'] != '') {
// Prevent the same enrolment key from being used multiple times in course groups.
if ($DB->record_exists('groups', array('courseid' => $COURSE->id, 'enrolmentkey' => $data['enrolmentkey']))) {
$errors['enrolmentkey'] = get_string('enrolmentkeyalreadyinuse', 'group');
}
}
return $errors;
+34
View File
@@ -89,3 +89,37 @@ Feature: Organize students into groups
| Grouping name | Not the greatest grouping, but it's ok! |
And I press "Save changes"
And I should see "Not the greatest grouping, but it's ok!"
Scenario: Create groups with enrolment key
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
| Course 2 | C2 | 0 | 1 |
And I log in as "admin"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
When I press "Create group"
And I set the following fields to these values:
| Group name | Group A |
| Enrolment key | Abcdef-1 |
And I press "Save changes"
And I press "Create group"
And I set the following fields to these values:
| Group name | Group B |
| Enrolment key | Abcdef-1 |
And I press "Save changes"
Then I should see "This enrolment key is already used for another group."
And I set the following fields to these values:
| Enrolment key | Abcdef-2 |
And I press "Save changes"
And the "groups" select box should contain "Group B (0)"
And I am on homepage
And I follow "Course 2"
And I expand "Users" node
And I follow "Groups"
And I press "Create group"
And I set the following fields to these values:
| Group name | Group A |
| Enrolment key | Abcdef-1 |
And I should not see "This enrolment key is already used for another group."
+51
View File
@@ -100,3 +100,54 @@ Feature: Automatic updating of groups and groupings
And the "idnumber" "field" should be readonly
And the field "idnumber" matches value "An ID"
@javascript
Scenario: Update groups with enrolment key
Given the following "courses" exist:
| fullname | shortname |
| Course 2 | C2 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C2 | editingteacher |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I expand "Users" node
And I follow "Groups"
And I set the field "groups" to "Group (with ID)"
And I press "Edit group settings"
And I set the following fields to these values:
| Enrolment key | badpasswd |
When I press "Save changes"
Then I should see "Passwords must have at least 1 digit(s)"
And I set the following fields to these values:
| Enrolment key | Abcdef-1 |
And I press "Save changes"
And I set the field "groups" to "Group (with ID)"
And I press "Edit group settings"
And I press "Save changes"
And I should not see "This enrolment key is already used for another group."
And I set the field "groups" to "Group (without ID)"
And I press "Edit group settings"
And I set the following fields to these values:
| Enrolment key | Abcdef-1 |
And I press "Save changes"
And I should see "This enrolment key is already used for another group."
And I set the following fields to these values:
| Enrolment key | Abcdef-2 |
And I press "Save changes"
And I should not see "This enrolment key is already used for another group."
And I am on homepage
And I follow "Course 2"
And I expand "Users" node
And I follow "Groups"
And I press "Create group"
And I set the following fields to these values:
| Group name | Group A |
And I press "Save changes"
And I should not see "This enrolment key is already used for another group."
And I set the field "groups" to "Group A"
And I press "Edit group settings"
And I set the following fields to these values:
| Enrolment key | Abcdef-1 |
And I press "Save changes"
And I should not see "This enrolment key is already used for another group."
+1
View File
@@ -61,6 +61,7 @@ $string['enrolmentkey'] = 'Enrolment key';
$string['enrolmentkey_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key. If a group enrolment key is specified, then not only will entering that key let the user into the course, but it will also automatically make them a member of this group.
Note: Group enrolment keys must be enabled in the self enrolment settings and an enrolment key for the course must also be specified.';
$string['enrolmentkeyalreadyinuse'] = 'This enrolment key is already used for another group.';
$string['erroraddremoveuser'] = 'Error adding/removing user {$a} to group';
$string['erroreditgroup'] = 'Error creating/updating group {$a}';
$string['erroreditgrouping'] = 'Error creating/updating grouping {$a}';