Lines 98-103
sub add {
Link Here
|
98 |
$body->{'status'} = 'ASKED' |
98 |
$body->{'status'} = 'ASKED' |
99 |
unless defined $body->{'status'}; |
99 |
unless defined $body->{'status'}; |
100 |
|
100 |
|
|
|
101 |
my $overrides = $c->stash('koha.overrides'); |
102 |
|
103 |
unless ( $overrides->{any} ) { |
104 |
|
105 |
unless ( $overrides->{max_total} ) { |
106 |
|
107 |
if ( C4::Context->preference('MaxTotalSuggestions') ne '' |
108 |
&& C4::Context->preference('NumberOfSuggestionDays') ne '' ) |
109 |
{ |
110 |
my $max_total = C4::Context->preference('MaxTotalSuggestions'); |
111 |
my $days_range = C4::Context->preference('NumberOfSuggestionDays'); |
112 |
|
113 |
if ( $max_total and $days_range ) { |
114 |
|
115 |
my $total = Koha::Suggestions->search({ suggestedby => $body->{suggested_by} }) |
116 |
->filter_by_suggested_days_range( $days_range ) |
117 |
->count; |
118 |
|
119 |
if ( $total >= $max_total ) { |
120 |
return $c->render( |
121 |
status => 400, |
122 |
openapi => { |
123 |
error => "Reached the maximum suggestions limit", |
124 |
error_code => 'max_total_reached' |
125 |
} |
126 |
); |
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
unless ( $overrides->{max_pending} ) { |
133 |
if ( C4::Context->preference('MaxOpenSuggestions') ne '' ) { |
134 |
my $total_pending = Koha::Suggestions->search({ suggestedby => $body->{suggested_by} }) |
135 |
->filter_by_pending |
136 |
->count; |
137 |
if ( $total_pending >= C4::Context->preference('MaxOpenSuggestions') ) { |
138 |
return $c->render( |
139 |
status => 400, |
140 |
openapi => { |
141 |
error => "Reached the maximum pending suggestions limit", |
142 |
error_code => 'max_pending_reached' |
143 |
} |
144 |
); |
145 |
} |
146 |
} |
147 |
} |
148 |
} |
149 |
|
101 |
return try { |
150 |
return try { |
102 |
my $suggestion = Koha::Suggestion->new_from_api( $body )->store; |
151 |
my $suggestion = Koha::Suggestion->new_from_api( $body )->store; |
103 |
$suggestion->discard_changes; |
152 |
$suggestion->discard_changes; |
104 |
- |
|
|