Browse Source
This bug adds a cancellation reason authorised values to article requests To test: 1. apply this patch 2. updatedatabase 3. in staff interface go to /cgi-bin/koha/admin/authorised_values.pl CHECK => AR_CANCELLATION category should appears 4. place several article requests 5. in staff interface go to /cgi-bin/koha/circ/article-requests.pl 6. select multiple requests, or just one and cancel them SUCCESS => a modal pops up offering to select a cancellation reason CHECK => message_queue table has messages with cancellation reason included 7. repeat steps 4 to 6 but for /cgi-bin/koha/circ/request-article.pl 8. cancelling article requests from opac interface should work just as before Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>21.11/bug30761
13 changed files with 516 additions and 58 deletions
@ -0,0 +1,17 @@ |
|||
package Koha::Exceptions::ArticleRequests; |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Exception::Class ( |
|||
|
|||
'Koha::Exceptions::ArticleRequests' => { |
|||
description => 'Something went wrong!', |
|||
}, |
|||
'Koha::Exceptions::ArticleRequests::FailedCancel' => { |
|||
isa => 'Koha::Exceptions::ArticleRequests', |
|||
description => 'Failed to cancel article request' |
|||
} |
|||
|
|||
); |
|||
|
|||
1; |
@ -0,0 +1,76 @@ |
|||
package Koha::REST::V1::ArticleRequests; |
|||
|
|||
# This file is part of Koha. |
|||
# |
|||
# Koha is free software; you can redistribute it and/or modify it |
|||
# under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 3 of the License, or |
|||
# (at your option) any later version. |
|||
# |
|||
# Koha is distributed in the hope that it will be useful, but |
|||
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
|||
|
|||
use Modern::Perl; |
|||
|
|||
use Mojo::Base 'Mojolicious::Controller'; |
|||
|
|||
use Koha::Database; |
|||
use Koha::ArticleRequests; |
|||
|
|||
use Scalar::Util qw( blessed ); |
|||
use Try::Tiny qw( catch try ); |
|||
|
|||
=head1 NAME |
|||
|
|||
Koha::REST::V1::ArticleRequests |
|||
|
|||
=head1 API |
|||
|
|||
=head2 Methods |
|||
|
|||
=head3 cancel |
|||
|
|||
Controller function that handles cancelling a Koha::ArticleRequest object |
|||
|
|||
=cut |
|||
|
|||
sub cancel { |
|||
my $c = shift->openapi->valid_input or return; |
|||
|
|||
my $ar = Koha::ArticleRequests->find( $c->validation->param('ar_id') ); |
|||
|
|||
unless ( $ar ) { |
|||
return $c->render( |
|||
status => 404, |
|||
openapi => { error => "Article request not found" } |
|||
); |
|||
} |
|||
|
|||
my $reason = $c->validation->param('cancellation_reason'); |
|||
my $notes = $c->validation->param('notes'); |
|||
|
|||
return try { |
|||
|
|||
$ar->cancel($reason, $notes); |
|||
return $c->render( |
|||
status => 204, |
|||
openapi => q{} |
|||
); |
|||
} catch { |
|||
if ( blessed $_ && $_->isa('Koha::Exceptions::ArticleRequests::FailedCancel') ) { |
|||
return $c->render( |
|||
status => 403, |
|||
openapi => { error => "Article request cannot be canceled" } |
|||
); |
|||
} |
|||
|
|||
$c->unhandled_exception($_); |
|||
}; |
|||
} |
|||
|
|||
1; |
@ -0,0 +1,23 @@ |
|||
{ |
|||
"ar_id_pp": { |
|||
"name": "ar_id", |
|||
"in": "path", |
|||
"description": "Article request identifier", |
|||
"required": true, |
|||
"type": "integer" |
|||
}, |
|||
"ar_reason_qp": { |
|||
"name": "cancellation_reason", |
|||
"in": "query", |
|||
"description": "Article request cancellation reason", |
|||
"required": false, |
|||
"type": "string" |
|||
}, |
|||
"ar_notes_qp": { |
|||
"name": "notes", |
|||
"in": "query", |
|||
"description": "Article request custom cancellation reason", |
|||
"required": false, |
|||
"type": "string" |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
{ |
|||
"/article_requests/{ar_id}": { |
|||
"delete": { |
|||
"x-mojo-to": "ArticleRequests#cancel", |
|||
"operationId": "cancelArticleRequest", |
|||
"tags": [ |
|||
"article_requests" |
|||
], |
|||
"summary": "Cancel article requests", |
|||
"parameters": [ |
|||
{ |
|||
"$ref": "../parameters.json#/ar_id_pp" |
|||
}, |
|||
{ |
|||
"$ref": "../parameters.json#/ar_reason_qp" |
|||
}, |
|||
{ |
|||
"$ref": "../parameters.json#/ar_notes_qp" |
|||
} |
|||
], |
|||
"produces": ["application/json"], |
|||
"responses": { |
|||
"204": { |
|||
"description": "Article request canceled" |
|||
}, |
|||
"400": { |
|||
"description": "Bad request", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
}, |
|||
"401": { |
|||
"description": "Authentication required", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
}, |
|||
"403": { |
|||
"description": "Access forbidden", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
}, |
|||
"404": { |
|||
"description": "Patron not found", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
}, |
|||
"500": { |
|||
"description": "Internal server error", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
}, |
|||
"503": { |
|||
"description": "Under maintenance", |
|||
"schema": { |
|||
"$ref": "../definitions.json#/error" |
|||
} |
|||
} |
|||
}, |
|||
"x-koha-authorization": { |
|||
"permissions": { |
|||
"reserveforothers": "1" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue