|
Lines 184-194
sub _validate_body {
Link Here
|
| 184 |
join(', ', @allowed_fields)}, 403); |
184 |
join(', ', @allowed_fields)}, 403); |
| 185 |
} |
185 |
} |
| 186 |
} |
186 |
} |
|
|
187 |
|
| 188 |
# Set user's branchcode if not specified (after validation input, because user does not |
| 189 |
# necessarily have rights to choose a branchcode) |
| 190 |
if ( not $updating and not exists $body->{branchcode} ) { |
| 191 |
$body->{branchcode} = C4::Context->userenv->{branch}; |
| 192 |
} |
| 193 |
|
| 187 |
} |
194 |
} |
| 188 |
|
195 |
|
| 189 |
if (not $updating) { |
196 |
if (not $updating) { |
| 190 |
# Check for missing fields |
197 |
# Check for missing fields |
| 191 |
my @mandatory_fields = split /,/, C4::Context->preference('OPACSuggestionMandatoryFields'); |
198 |
my @mandatory_fields = split /,/, C4::Context->preference('OPACSuggestionMandatoryFields'); |
|
|
199 |
|
| 200 |
# Title is mandatory by default if none specified in settings |
| 201 |
if (not @mandatory_fields) { |
| 202 |
push (@mandatory_fields, 'title'); |
| 203 |
} |
| 204 |
|
| 192 |
my @missing_fields = (); |
205 |
my @missing_fields = (); |
| 193 |
for my $mandatory_field (@mandatory_fields) { |
206 |
for my $mandatory_field (@mandatory_fields) { |
| 194 |
push(@missing_fields, $mandatory_field) if (not exists $body->{$mandatory_field}); |
207 |
push(@missing_fields, $mandatory_field) if (not exists $body->{$mandatory_field}); |
|
Lines 200-211
sub _validate_body {
Link Here
|
| 200 |
} |
213 |
} |
| 201 |
|
214 |
|
| 202 |
# Is suggester anonymous? |
215 |
# Is suggester anonymous? |
| 203 |
my $is_anonymous = not (defined $body->{suggestedby} and |
216 |
my $is_anonymous = not (exists $body->{suggestedby} and |
| 204 |
$body->{suggestedby} ne '' and |
217 |
$body->{suggestedby} ne '' and |
| 205 |
$body->{suggestedby} ne C4::Context->preference('AnonymousPatron')); |
218 |
$body->{suggestedby} ne C4::Context->preference('AnonymousPatron')); |
| 206 |
|
219 |
|
|
|
220 |
# Is updated suggestedby anonymous? (Can be true only if "suggestedby" is defined!) |
| 221 |
my $updated_is_anonymous = ( $updating and |
| 222 |
exists $body->{suggestedby} and ( |
| 223 |
$body->{suggestedby} eq '' or |
| 224 |
$body->{suggestedby} eq C4::Context->preference('AnonymousPatron') |
| 225 |
) |
| 226 |
); |
| 227 |
|
| 207 |
# Refuse if are anonymous suggestions disabled |
228 |
# Refuse if are anonymous suggestions disabled |
| 208 |
if ( $is_anonymous ) { |
229 |
if ( ($is_anonymous and not $updating) or $updated_is_anonymous ) { |
| 209 |
return $c->$cb({error => 'Anonymous suggestions are disabled'}, 403) |
230 |
return $c->$cb({error => 'Anonymous suggestions are disabled'}, 403) |
| 210 |
unless C4::Context->preference('AnonSuggestions'); |
231 |
unless C4::Context->preference('AnonSuggestions'); |
| 211 |
} |
232 |
} |
|
Lines 230-250
sub _validate_body {
Link Here
|
| 230 |
if ( exists $body->{itemtype} ) { |
251 |
if ( exists $body->{itemtype} ) { |
| 231 |
my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search; |
252 |
my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search; |
| 232 |
return $c->$cb({error => 'itemtype must be one of ' . join(', ', @item_types)}, 400) |
253 |
return $c->$cb({error => 'itemtype must be one of ' . join(', ', @item_types)}, 400) |
| 233 |
unless /^$body->{itemtype}$/ ~~ @item_types; |
254 |
unless grep(/^$body->{itemtype}$/, @item_types); |
| 234 |
} |
255 |
} |
| 235 |
|
256 |
|
| 236 |
# Check branchcode is valid |
257 |
# Check branchcode is valid |
| 237 |
if ( exists $body->{branchcode} ) { |
258 |
if ( exists $body->{branchcode} ) { |
| 238 |
my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search; |
259 |
my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search; |
| 239 |
return $c->$cb({error => 'branchcode must be one of ' . join(', ', @branch_codes)}, 400) |
260 |
return $c->$cb({error => 'branchcode must be one of ' . join(', ', @branch_codes)}, 400) |
| 240 |
unless /^$body->{branchcode}$/ ~~ @branch_codes; |
261 |
unless grep(/^$body->{branchcode}$/, @branch_codes); |
| 241 |
} |
262 |
} |
| 242 |
|
263 |
|
| 243 |
# Check patron reason is valid |
264 |
# Check patron reason is valid |
| 244 |
if ( exists $body->{patronreason} ) { |
265 |
if ( exists $body->{patronreason} ) { |
| 245 |
my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') }; |
266 |
my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') }; |
| 246 |
return $c->$cb({error => 'patronreason must be one of ' . join(', ', @authorized_values)}, 400) |
267 |
return $c->$cb({error => 'patronreason must be one of ' . join(', ', @authorized_values)}, 400) |
| 247 |
unless /^$body->{patronreason}$/ ~~ @authorized_values; |
268 |
unless grep(/^$body->{patronreason}$/, @authorized_values); |
| 248 |
} |
269 |
} |
| 249 |
|
270 |
|
| 250 |
# Check suggestedby patron exists |
271 |
# Check suggestedby patron exists |