Bugzilla – Attachment 80102 Details for
Bug 18591
Allow an arbitrary number of comments on ILLs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18591: Allow any number of comments on ILLs
Bug-18591-Allow-any-number-of-comments-on-ILLs.patch (text/plain), 14.08 KB, created by
Katrin Fischer
on 2018-10-05 14:20:52 UTC
(
hide
)
Description:
Bug 18591: Allow any number of comments on ILLs
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2018-10-05 14:20:52 UTC
Size:
14.08 KB
patch
obsolete
>From 6c021913a24b190f80be8491cb00f5ed9307baa5 Mon Sep 17 00:00:00 2001 >From: Magnus Enger <magnus@libriotech.no> >Date: Mon, 20 Nov 2017 14:14:30 +0000 >Subject: [PATCH] Bug 18591: Allow any number of comments on ILLs > >This patch makes it possible to add arbitrary comments to ILL >requests. Comments are read only and displayed in chronological >order. Comments can be added by librarians, but also added automatically >based on comments in the different protocols, so that comments from the >lending library can also be added. > >To test: >- 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 > >Signed-off-by: andrew.isherwood@ptfs-europe.com >--- > 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 > >diff --git a/Koha/Illcomment.pm b/Koha/Illcomment.pm >new file mode 100644 >index 0000000..931f235 >--- /dev/null >+++ b/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 <magnus@libriotech.no> >+ >+=cut >+ >+1; >diff --git a/Koha/Illcomments.pm b/Koha/Illcomments.pm >new file mode 100644 >index 0000000..a0f18e3 >--- /dev/null >+++ b/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; >diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm >index 99b97bd..18cdb4c 100644 >--- a/Koha/Illrequest.pm >+++ b/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; >diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl >index 877db4d..a2e898a 100755 >--- a/ill/ill-requests.pl >+++ b/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' ) { >@@ -235,6 +240,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); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >index 78c69da..b9a7f80 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >+++ b/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 >@@ -205,6 +206,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(); >@@ -231,7 +244,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 >@@ -616,6 +629,47 @@ > </div> > </div> > >+ <div id="ill-view-panel" class="panel panel-default"> >+ <div class="panel-heading"> >+ <h3>[% request.illcomments.count %] comments</h3> >+ </div> >+ <div class="panel-body"> >+ [% IF request.illcomments.count && request.illcomments.count > 0 %] >+ [% FOREACH comment IN request.illcomments %] >+ <div class="rows comment_[% comment.patron.categorycode %]"> >+ <h5>Comment by: >+ <a href="[% borrowerlink %]" title="View borrower details"> >+ [% comment.patron.firstname _ " " _ comment.patron.surname _ " [" _ comment.patron.cardnumber _ "]" | html %]</a> >+ [% comment.timestamp | $KohaDates with_hours => 1 %]</h5> >+ <p>[% comment.comment | html %]</p> >+ </div> >+ [% END %] >+ [% END %] >+ <div class="rows"> >+ <h3><a id="toggle_addcomment" href="#">Add comment</a></h3> >+ <div id="addcomment" class="content_hidden"> >+ <form class="validated" method="post" action="/cgi-bin/koha/ill/ill-requests.pl"> >+ <input type="hidden" value="save_comment" name="method"> >+ <input type="hidden" value="[% csrf_token %]" name="csrf_token"> >+ <input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id"> >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <label class="required" for="comment">Comment: </label> >+ <textarea type="text" class="required" required="required" value="" cols="80" rows="10" id="comment" name="comment"></textarea> >+ <span class="required">Required</span> >+ </li> >+ </ol> >+ </fieldset> >+ <fieldset class="action"> >+ <input type="submit" value="Submit"> >+ </fieldset> >+ </form> >+ </div> >+ </div> >+ </div> >+ </div> >+ > [% ELSIF query_type == 'illlist' %] > <!-- illlist --> > <h1>View ILL requests</h1> >@@ -633,6 +687,7 @@ > <th>Status</th> > <th>Updated on</th> > <th>Request number</th> >+ <th>Comments</th> > <th class="actions"></th> > </tr> > </thead> >diff --git a/t/db_dependent/Illcomments.t b/t/db_dependent/Illcomments.t >new file mode 100644 >index 0000000..85cc630 >--- /dev/null >+++ b/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 <http://www.gnu.org/licenses>. >+ >+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; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18591
:
69234
|
69272
|
69273
|
69274
|
69275
|
74964
|
74965
|
74966
|
79518
|
79519
|
80077
|
80078
|
80079
|
80081
|
80084
|
80101
|
80102
|
80103
|
80104
|
80105
|
80227
|
80228
|
80229
|
80230