@@ -, +, @@ - Enable the ILL module ("ILLModule" syspref + config in koha-conf.xml) - Install the Dummy backend from here: https://github.com/PTFS-Europe/Dummy - Create a Dummy ILL request - Add comments to the request, checking that the name and borrowernumber of the person that added the comment is displayed ok - Check that the displayed date and time the comment was submitted follows the "dateformat" syspref - On the "List requests" page, check that the correct number of comments is displayed in the "Comments" column - Check that the tests pass: prove t/db_dependent/Illcomments.t --- Koha/Illcomment.pm | 58 +++++++++++++++ Koha/Illcomments.pm | 18 +++++ Koha/Illrequest.pm | 16 +++++ ill/ill-requests.pl | 25 ++++++- .../prog/en/modules/ill/ill-requests.tt | 59 ++++++++++++++- t/db_dependent/Illcomments.t | 84 ++++++++++++++++++++++ 6 files changed, 257 insertions(+), 3 deletions(-) create mode 100644 Koha/Illcomment.pm create mode 100644 Koha/Illcomments.pm create mode 100644 t/db_dependent/Illcomments.t --- a/Koha/Illcomment.pm +++ a/Koha/Illcomment.pm @@ -0,0 +1,58 @@ +package Koha::Illcomment; + +# Copyright Magnus Enger Libriotech 2017 +# +# 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, write to the Free Software Foundation, Inc., 51 Franklin +# Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use Koha::Database; +use base qw(Koha::Object); + +=head1 NAME + +Koha::Illcomment - Koha Illcomment Object class + +=head2 Class methods + +=head3 patron + +=cut + +sub patron { + my ( $self ) = @_; + return Koha::Patron->_new_from_dbic( + scalar $self->_result->borrowernumber + ); +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'Illcomment'; +} + +=head1 AUTHOR + +Magnus Enger + +=cut + +1; --- a/Koha/Illcomments.pm +++ a/Koha/Illcomments.pm @@ -0,0 +1,18 @@ +package Koha::Illcomments; + +# TODO Add POD + +use Modern::Perl; +use Koha::Database; +use Koha::Illcomment; +use base qw(Koha::Objects); + +sub _type { + return 'Illcomments'; +} + +sub object_class { + return 'Koha::Illcomment'; +} + +1; --- a/Koha/Illrequest.pm +++ a/Koha/Illrequest.pm @@ -29,6 +29,7 @@ use Try::Tiny; use Koha::Database; use Koha::Email; use Koha::Exceptions::Ill; +use Koha::Illcomments; use Koha::Illrequestattributes; use Koha::Patron; @@ -119,6 +120,17 @@ sub illrequestattributes { ); } +=head3 illcomments + +=cut + +sub illcomments { + my ( $self ) = @_; + return Koha::Illcomments->_new_from_dbic( + scalar $self->_result->illcomments + ); +} + =head3 patron =cut @@ -1023,6 +1035,10 @@ sub TO_JSON { $self->branchcode )->TO_JSON; } + # Augment the request response with the number of comments if appropriate + if ( $embed->{comments} ) { + $object->{comments} = $self->illcomments->count; + } } return $object; --- a/ill/ill-requests.pl +++ a/ill/ill-requests.pl @@ -24,8 +24,10 @@ use CGI; use C4::Auth; use C4::Output; use Koha::AuthorisedValues; +use Koha::Illcomment; use Koha::Illrequests; use Koha::Libraries; +use Koha::Token; use Try::Tiny; @@ -63,7 +65,10 @@ if ( $backends_available ) { my $request = Koha::Illrequests->find($params->{illrequest_id}); $template->param( - request => $request + request => $request, + csrf_token => Koha::Token->new->generate_csrf({ + session_id => scalar $cgi->cookie('CGISESSID'), + }), ); } elsif ( $op eq 'create' ) { @@ -234,6 +239,24 @@ if ( $backends_available ) { prefilters => $active_filters ); } + + } elsif ( $op eq "save_comment" ) { + die "Wrong CSRF token" unless Koha::Token->new->check_csrf({ + session_id => scalar $cgi->cookie('CGISESSID'), + token => scalar $cgi->param('csrf_token'), + }); + my $comment = Koha::Illcomment->new({ + illrequest_id => scalar $params->{illrequest_id}, + borrowernumber => $patronnumber, + comment => scalar $params->{comment}, + }); + $comment->store(); + # Redirect to view the whole request + print $cgi->redirect("/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=". + scalar $params->{illrequest_id} + ); + exit; + } else { my $request = Koha::Illrequests->find($params->{illrequest_id}); my $backend_result = $request->custom_capability($op, $params); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -51,7 +51,8 @@ 'status', 'updated', 'illrequest_id', - 'action' + 'comments', + 'action' // Action should always be last ]; // Remove any fields we're ignoring @@ -194,6 +195,18 @@ } }; + // Toggle request attributes in Illview + $('#toggle_requestattributes').on('click', function(e) { + e.preventDefault(); + $('#requestattributes').toggleClass('content_hidden'); + }); + + // Toggle new comment form in Illview + $('#toggle_addcomment').on('click', function(e) { + e.preventDefault(); + $('#addcomment').toggleClass('content_hidden'); + }); + // Filter partner list $('#partner_filter').keyup(function() { var needle = $('#partner_filter').val(); @@ -220,7 +233,7 @@ // Get our data from the API and process it prior to passing // it to datatables var ajax = $.ajax( - '/api/v1/illrequests?embed=metadata,patron,capabilities,library' + '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments' ).done(function() { var data = JSON.parse(ajax.responseText); // Make a copy, we'll be removing columns next and need @@ -592,6 +605,47 @@ +
+
+

[% request.illcomments.count %] comments

+
+
+ [% IF request.illcomments.count && request.illcomments.count > 0 %] + [% FOREACH comment IN request.illcomments %] +
+
Comment by: + + [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %] + [% comment.timestamp | $KohaDates with_hours => 1 %]
+

[% comment.comment | html %]

+
+ [% END %] + [% END %] +
+

Add comment

+
+
+ + + +
+
    +
  1. + + + Required +
  2. +
+
+
+ +
+
+
+
+
+
+ [% ELSIF query_type == 'illlist' %]

View ILL requests

@@ -609,6 +663,7 @@ Status Updated on Request number + Comments --- a/t/db_dependent/Illcomments.t +++ a/t/db_dependent/Illcomments.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +# 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 . + +use Modern::Perl; + +use File::Basename qw/basename/; +use Koha::Database; +use Koha::Illrequests; +use Koha::Illrequestattributes; +use Koha::Illrequest::Config; +use Koha::Patrons; +use t::lib::Mocks; +use t::lib::TestBuilder; +use Test::MockObject; +use Test::MockModule; + +use Test::More tests => 9; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; +use_ok('Koha::Illcomment'); +use_ok('Koha::Illcomments'); + +$schema->storage->txn_begin; + +Koha::Illrequests->search->delete; + +# Create a patron +my $patron = $builder->build({ source => 'Borrower' }); + +# Create an ILL request +my $illrq = $builder->build({ + source => 'Illrequest', + value => { borrowernumber => $patron->{borrowernumber} } +}); +my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id}); +isa_ok( $illrq_obj, 'Koha::Illrequest' ); + +# Create a librarian +my $librarian = $builder->build({ source => 'Borrower' }); + +# Create a comment and tie it to the request and the librarian +my $comment_text = 'xyz'; +my $illcomment = $builder->build({ + source => 'Illcomment', + value => { + illrequest_id => $illrq_obj->illrequest_id, + borrowernumber => $librarian->{borrowernumber}, + comment => $comment_text, + } +}); + +# Get all the comments +my $comments = $illrq_obj->illcomments; +isa_ok( $comments, 'Koha::Illcomments', "Illcomments" ); +my @comments_list = $comments->as_list(); +is( scalar @comments_list, 1, "We have 1 comment" ); + +# Get the first (and only) comment +my $comment = $comments->next(); +isa_ok( $comment, 'Koha::Illcomment', "Illcomment" ); + +# Check the different data in the comment +is( $comment->illrequest_id, $illrq_obj->illrequest_id, 'illrequest_id getter works' ); +is( $comment->borrowernumber, $librarian->{borrowernumber}, 'borrowernumber getter works'); +is( $comment->comment, $comment_text, 'comment getter works'); + +$illrq_obj->delete; + +$schema->storage->txn_rollback; --