Lines 28-33
use Koha::Suggestions;
Link Here
|
28 |
|
28 |
|
29 |
use Koha::ItemTypes; |
29 |
use Koha::ItemTypes; |
30 |
use Koha::Libraries; |
30 |
use Koha::Libraries; |
|
|
31 |
use List::MoreUtils qw/any/; |
31 |
|
32 |
|
32 |
use Try::Tiny; |
33 |
use Try::Tiny; |
33 |
|
34 |
|
Lines 173-180
sub _validate_body {
Link Here
|
173 |
} |
174 |
} |
174 |
|
175 |
|
175 |
foreach my $param ( keys %{ $body } ) { |
176 |
foreach my $param ( keys %{ $body } ) { |
176 |
unless (/^$param$/ ~~ @allowed_fields) { |
177 |
unless (any { /^$param$/ } @allowed_fields) { |
177 |
# Ouch ! Some mandatory field is missing! |
178 |
# Ouch ! User trying to edit field he has no rights to edit! |
178 |
my $verb = 'specified '; |
179 |
my $verb = 'specified '; |
179 |
return $c->render( status => 403 , openapi => { |
180 |
return $c->render( status => 403 , openapi => { |
180 |
error => 'You ' . $verb . $param . ', but allowed fields are only ' . join(', ', @allowed_fields)} |
181 |
error => 'You ' . $verb . $param . ', but allowed fields are only ' . join(', ', @allowed_fields)} |
Lines 183-191
sub _validate_body {
Link Here
|
183 |
} |
184 |
} |
184 |
} |
185 |
} |
185 |
|
186 |
|
|
|
187 |
# Set user's branchcode if not specified (after validation input, because user does not |
188 |
# necessarily have rights to choose a branchcode) |
189 |
if ( not exists $body->{branchcode} ) { |
190 |
$body->{branchcode} = C4::Context->userenv->{branch}; |
191 |
} |
186 |
|
192 |
|
187 |
# Is suggester anonymous? |
193 |
# Is suggester anonymous? |
188 |
my $is_anonymous = not (defined $body->{suggestedby} and |
194 |
my $is_anonymous = not (exists $body->{suggestedby} and |
189 |
$body->{suggestedby} ne '' and |
195 |
$body->{suggestedby} ne '' and |
190 |
$body->{suggestedby} ne C4::Context->preference('AnonymousPatron')); |
196 |
$body->{suggestedby} ne C4::Context->preference('AnonymousPatron')); |
191 |
|
197 |
|
Lines 215-235
sub _validate_body {
Link Here
|
215 |
if ( exists $body->{itemtype} ) { |
221 |
if ( exists $body->{itemtype} ) { |
216 |
my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search; |
222 |
my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search; |
217 |
return $c->render( status => 400 , openapi => {error => 'itemtype must be one of ' . join(', ', @item_types)} ) |
223 |
return $c->render( status => 400 , openapi => {error => 'itemtype must be one of ' . join(', ', @item_types)} ) |
218 |
unless /^$body->{itemtype}$/ ~~ @item_types; |
224 |
unless grep(/^$body->{itemtype}$/, @item_types); |
219 |
} |
225 |
} |
220 |
|
226 |
|
221 |
# Check branchcode is valid |
227 |
# Check branchcode is valid |
222 |
if ( exists $body->{branchcode} ) { |
228 |
if ( exists $body->{branchcode} ) { |
223 |
my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search; |
229 |
my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search; |
224 |
return $c->render( status => 400 , openapi => {error => 'branchcode must be one of ' . join(', ', @branch_codes)} ) |
230 |
return $c->render( status => 400 , openapi => {error => 'branchcode must be one of ' . join(', ', @branch_codes)} ) |
225 |
unless /^$body->{branchcode}$/ ~~ @branch_codes; |
231 |
unless grep(/^$body->{branchcode}$/, @branch_codes); |
226 |
} |
232 |
} |
227 |
|
233 |
|
228 |
# Check patron reason is valid |
234 |
# Check patron reason is valid |
229 |
if ( exists $body->{patronreason} ) { |
235 |
if ( exists $body->{patronreason} ) { |
230 |
my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') }; |
236 |
my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') }; |
231 |
return $c->render( status => 400, openapi => {error => 'patronreason must be one of ' . join(', ', @authorized_values)} ) |
237 |
return $c->render( status => 400, openapi => {error => 'patronreason must be one of ' . join(', ', @authorized_values)} ) |
232 |
unless /^$body->{patronreason}$/ ~~ @authorized_values; |
238 |
unless grep(/^$body->{patronreason}$/, @authorized_values); |
233 |
} |
239 |
} |
234 |
|
240 |
|
235 |
# Check suggestedby patron exists |
241 |
# Check suggestedby patron exists |