|
|
|
@ -885,29 +885,20 @@ sub update_preferences {
|
|
|
|
|
last SWITCH;
|
|
|
|
|
};
|
|
|
|
|
/^allowed_clis$/ && do {
|
|
|
|
|
if ($replace) {
|
|
|
|
|
#check duplicates in case of PUT
|
|
|
|
|
if ($resource->{$pref}) {
|
|
|
|
|
my %seen;
|
|
|
|
|
foreach my $allowed_cli (@{$resource->{$pref}}) {
|
|
|
|
|
next unless $seen{$allowed_cli}++;
|
|
|
|
|
$c->log->error("Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
&$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
my $old_seen = {};
|
|
|
|
|
unless ($replace) {
|
|
|
|
|
#in case of PATCH, check duplicates only for new values, since there could already be duplicates in some systems
|
|
|
|
|
if ($resource->{$pref} && $old_resource->{$pref}) {
|
|
|
|
|
my @new_clis = @{$resource->{$pref}}[scalar @{$old_resource->{$pref}} .. scalar @{$resource->{$pref}} - 1];
|
|
|
|
|
my %existing_clis = map {$_ => 1} @{$old_resource->{$pref}};
|
|
|
|
|
my ($allowed_cli) = grep { exists $existing_clis{$_} } @new_clis;
|
|
|
|
|
if ( $allowed_cli ) {
|
|
|
|
|
$c->log->error("Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
&$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
($old_seen) = array_to_map($old_resource->{$pref},undef,undef,'first');
|
|
|
|
|
}
|
|
|
|
|
my $seen = {};
|
|
|
|
|
foreach my $allowed_cli (@{$resource->{$pref} // []}) {
|
|
|
|
|
next if exists $old_seen->{$allowed_cli};
|
|
|
|
|
if (exists $seen->{$allowed_cli}) {
|
|
|
|
|
$c->log->error("Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
&$err_code(HTTP_UNPROCESSABLE_ENTITY, "Duplicate $pref value: ".$allowed_cli);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
$seen->{$allowed_cli} = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|