Skip to content

Commit 0a8ab74

Browse files
committed
MDL-29807 Control to avoid duplicate shortnames
1 parent b129859 commit 0a8ab74

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

admin/webservice/forms.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function definition() {
6969

7070
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="255" size="20"');
7171
$mform->setType('shortname', PARAM_TEXT);
72+
if (!empty($service->id)) {
73+
$mform->hardFreeze('shortname');
74+
$mform->setConstants('shortname', $service->shortname);
75+
}
7276

7377
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice'));
7478
$mform->setType('enabled', PARAM_BOOL);
@@ -149,7 +153,17 @@ function definition_after_data() {
149153
}
150154

151155
function validation($data, $files) {
156+
global $DB;
157+
152158
$errors = parent::validation($data, $files);
159+
160+
// Add field validation check for duplicate shortname.
161+
if ($service = $DB->get_record('external_services', array('shortname' => $data['shortname']), '*', IGNORE_MULTIPLE)) {
162+
if (empty($data['id']) || $service->id != $data['id']) {
163+
$errors['shortname'] = get_string('shortnametaken', 'webservice', $service->name);
164+
}
165+
}
166+
153167
return $errors;
154168
}
155169

lang/en/webservice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
$string['serviceusersettings'] = 'User settings';
177177
$string['serviceusersmatching'] = 'Authorised users matching';
178178
$string['serviceuserssettings'] = 'Change settings for the authorised users';
179+
$string['shortnametaken'] = 'Short name is already used for another service ({$a})';
179180
$string['simpleauthlog'] = 'Simple authentication login';
180181
$string['step'] = 'Step';
181182
$string['supplyinfo'] = 'More details';

0 commit comments

Comments
 (0)