Commit 801b3308 authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1711485: Throw correct error of group create



When the shortname is uppercase and we upload groups via csv

Also forcing shortname to be lowercase if editing group shortname

behatnotneeded

Change-Id: I85307b974be129dd2f22528cc0ce0802fe3d6080
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 33fd2a04
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -426,8 +426,8 @@ function editgroup_validate(Pieform $form, $values) {
    }

    if (isset($values['shortname']) && $group_data->id) {
        if (!preg_match('/^[a-zA-Z0-9_.-]{2,255}$/', $values['shortname'])) {
            $form->set_error('shortname', get_string('shortnameformat', 'group'));
        if (!preg_match('/^[a-z0-9_.-]{2,255}$/', $values['shortname'])) {
            $form->set_error('shortname', get_string('shortnameformat1', 'group'));
        }

        if ($group_data->shortname != $values['shortname']) {
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ $string['reject'] = 'Reject';
$string['groupalreadyexists'] = 'A group by this name already exists.';
$string['groupshortnamealreadyexists'] = 'A group by this short name already exists.';
$string['invalidshortname'] = 'Invalid group short name.';
$string['shortnameformat'] = 'Group short names can be from 2 to 255 characters in length and contain only alphanumeric characters, ".", "-", and "_".';
$string['shortnameformat1'] = 'Group short names can be from 2 to 255 characters in length and contain only lowercase alphanumeric characters, ".", "-", and "_".';
$string['Created'] = 'Created';
$string['editable'] = 'Editable';
$string['editability'] = 'Editability';
+8 −3
Original line number Diff line number Diff line
@@ -365,10 +365,16 @@ function group_create($data) {
        // If we want to retain the supplied shortname we need to make sure it can be done
        if (!empty($data['retainshortname'])) {
            if ($shortname != $data['shortname']) {
                if ($shortname == strtolower($data['shortname'])) {
                    throw new UserException('group_create: The supplied short name \'' . $data['shortname'] .
                        '\' needs to be lowercase, eg \'' . $shortname . '\'.');
                }
                else {
                    throw new UserException('group_create: The supplied short name \'' . $data['shortname'] .
                        '\' is already taken. This shortname \'' . $shortname . '\' is available.');
                }
            }
        }
        $data['shortname'] = $shortname;
    }
    else {
@@ -2749,9 +2755,8 @@ function group_get_shortname_element($group_data) {
            'maxlength' => 255
        ),
        'disabled' => $disabled,
        'description' => get_string('shortnameformat', 'group'),
        'description' => get_string('shortnameformat1', 'group'),
    );

    if (isset($group_data->id)) {
        $element['type'] = 'text';
        $element['defaultvalue'] = isset($group_data->shortname) ? $group_data->shortname : null;