Merge branch 'ent-6655-bug-group-creation-existing-name' into 'develop'

Fixed bug allowing updating group with duplicated name

See merge request artica/pandorafms!3593
This commit is contained in:
Daniel Rodriguez 2020-11-23 16:15:02 +01:00
commit ee1c9b6567

View File

@ -419,46 +419,53 @@ if ($update_group) {
$aviable_name = false; $aviable_name = false;
} }
// Check if name field is empty. // Check if group name is unique.
if ($name != '' && $aviable_name === true) { $check = db_get_value_filter(
$sql = sprintf( 'nombre',
'UPDATE tgrupo 'tgrupo',
SET nombre = "%s", [
icon = "%s", 'nombre' => $name,
disabled = %d, 'id_grupo' => $id_group,
parent = %d, ],
custom_id = "%s", 'AND NOT'
propagate = %d,
id_skin = %d,
description = "%s",
contact = "%s",
other = "%s",
password = "%s"
WHERE id_grupo = %d',
$name,
empty($icon) ? '' : substr($icon, 0, -4),
!$alerts_enabled,
$id_parent,
$custom_id,
$propagate,
$skin,
$description,
$contact,
$other,
$group_pass,
$id_group
); );
$result = db_process_sql($sql); // Check if name field is empty.
} else { if ($name != '') {
$result = false; if (!$check) {
if ($aviable_name === true) {
$values = [
'nombre' => $name,
'icon' => empty($icon) ? '' : substr($icon, 0, -4),
'parent' => $id_parent,
'disabled' => !$alerts_enabled,
'custom_id' => $custom_id,
'id_skin' => $skin,
'description' => $description,
'contact' => $contact,
'propagate' => $propagate,
'other' => $other,
'password' => io_safe_input($group_pass),
];
$result = db_process_sql_update(
'tgrupo',
$values,
['id_grupo' => $id_group]
);
} }
if ($result !== false) { if ($result) {
ui_print_success_message(__('Group successfully updated')); ui_print_success_message(__('Group successfully updated'));
} else { } else {
ui_print_error_message(__('There was a problem modifying group')); ui_print_error_message(__('There was a problem modifying group'));
} }
} else {
ui_print_error_message(__('Each group must have a different name'));
}
} else {
ui_print_error_message(__('Group must have a name'));
}
} }
// Delete group. // Delete group.