From 4a3eaf02e2be743536681a0151b86296ff299026 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 1 Dec 2016 00:54:07 +0000 Subject: [PATCH] Bug 17698: Make patron notes show up on staff dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds a user permission for managing issue notes, and a 'noteseen' column to the issues table. To test: 1) Apply Bug 14224 first 2) Apply this patch, update database, rebuild schema. 3) Restart koha-common and memcached 4) Turn on AllowCheckoutNotes syspref if haven't already 5) Issue two items to two different users (one item each) 6) Log into the OPAC as one of the users and add an issue note to their issue 7) Log out and log back into the OPAC as the other user 8) Disable Javascript 9) Refresh opac-user.pl 10) Leave a checkout note on their issue 11) Enable javascript and log into the Staff Client as a superlibrarian user 12) Go to your user's account and edit their permissions to have everything ticked EXCEPT circulate->manage checkout notes. 13) Go to main intranet page. There should be no message saying 'checkout notes pending'. 14) Go to circulation home page. There should be no link to Checkout notes. 15) Go back to user's permissions and tick circulate->manage checkout notes. 16) Go back to main intranet page. There should now be a message at the bottom saying 'Checkout notes pending: 2' 17) Go to circulation home page. There should be a link to Checkout notes with a 2 next to it. Click this link 18) Attempt to mark an checkout note as seen. This should update the status of the checkout note to 'seen' and disable to 'mark as seen' button while enabling the 'mark as not seen' button. 19) Test both buttons with both issues. 20) Test select all and clear all buttons 21) Confirm that buttons at the bottom are only enabled if a checkbox is checked 22) Try selecting both issues and using the buttons at the bottom to mark multiple issue notes at once. 23) Confirm the barcode link to the item works as expected. 24) Confirm the cardnumber link to the user works as expected. 25) Confirm all table details show correctly. Sponsored-by: Catalyst IT Signed-off-by: Josef Moravec Followed test plan, works as expected Signed-off-by: Marc Véron Signed-off-by: Brendan Gallagher Signed-off-by: Jonathan Druart Amended patch: Remove self-checkout permissions Signed-off-by: Nick Clemens --- circ/checkout-notes.pl | 71 ++++++++ circ/circulation-home.pl | 3 + ...g-17698_add-noteseen-column-to-issues.perl | 13 ++ ...dd-permission-to-manage-checkout-notes.sql | 1 + installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/userpermissions.sql | 1 + .../prog/en/includes/permissions.inc | 1 + .../prog/en/modules/circ/checkout-notes.tt | 164 ++++++++++++++++++ .../prog/en/modules/circ/circulation-home.tt | 5 + .../prog/en/modules/intranet-main.tt | 7 + mainpage.pl | 3 + opac/opac-issue-note.pl | 2 +- opac/svc/checkout_notes | 2 +- svc/checkout_notes | 63 +++++++ 14 files changed, 336 insertions(+), 2 deletions(-) create mode 100755 circ/checkout-notes.pl create mode 100644 installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.perl create mode 100644 installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-checkout-notes.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/circ/checkout-notes.tt create mode 100755 svc/checkout_notes diff --git a/circ/checkout-notes.pl b/circ/checkout-notes.pl new file mode 100755 index 0000000000..ceb52c953e --- /dev/null +++ b/circ/checkout-notes.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +# Copyright 2016 Aleisha Amohia +# +# 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 CGI qw ( -utf8 ); +use C4::Context; +use C4::Output; +use C4::Auth; +use Koha::Checkouts; + +my $query = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "circ/checkout-notes.tt", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { circulation => "manage_checkout_notes" }, + } +); + +my $schema = Koha::Database->new()->schema(); +my @notes = $schema->resultset('Issue')->search({ 'me.note' => { '!=', undef } }, { prefetch => [ 'borrower', { item => 'biblionumber' } ] }); +$template->param( + notes => \@notes, +); + +my $action; +foreach (qw( seen notseen )) { + $action = $_ if ( $query->param("mark_selected-$_") ); +} +$action ||= 'none'; + +my @issue_ids = $query->multi_param('issue_ids'); + +if ( $action eq 'seen' ) { + foreach my $issue_id ( @issue_ids ) { + my $issue = Koha::Checkouts->find($issue_id); + $issue->set({ noteseen => 1 })->store; + } +} elsif ( $action eq 'notseen' ) { + foreach my $issue_id ( @issue_ids ) { + my $issue = Koha::Checkouts->find($issue_id); + $issue->set({ noteseen => 0 })->store; + } +} + +$template->param( + selected_count => scalar(@issue_ids), + action => $action, +); + +output_html_with_http_headers $query, $cookie, $template->output; diff --git a/circ/circulation-home.pl b/circ/circulation-home.pl index 7d24d79663..f101f6dd8c 100755 --- a/circ/circulation-home.pl +++ b/circ/circulation-home.pl @@ -22,6 +22,7 @@ use C4::Auth; use C4::Output; use C4::Context; use Koha::BiblioFrameworks; +use Koha::Checkouts; my $query = new CGI; my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( @@ -39,5 +40,7 @@ $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' ) $template->{'VARS'}->{'AllowOfflineCirculation'} = C4::Context->preference('AllowOfflineCirculation'); +my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count; +$template->param( pending_checkout_notes => $pending_checkout_notes ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.perl b/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.perl new file mode 100644 index 0000000000..1e8c604340 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-17698_add-noteseen-column-to-issues.perl @@ -0,0 +1,13 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + unless( column_exists( 'issues', 'noteseen' ) ) { + $dbh->do(q|ALTER TABLE issues ADD COLUMN noteseen int(1) default NULL AFTER notedate|); + } + + unless( column_exists( 'old_issues', 'noteseen' ) ) { + $dbh->do(q|ALTER TABLE old_issues ADD COLUMN noteseen int(1) default NULL AFTER notedate|); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 17698: Add column issues.noteseen and old_issues.noteseen)\n"; +} diff --git a/installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-checkout-notes.sql b/installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-checkout-notes.sql new file mode 100644 index 0000000000..343314bc6f --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-17698_add-permission-to-manage-checkout-notes.sql @@ -0,0 +1 @@ +INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'manage_checkout_nots', 'Mark checkout notes as seen/not seen'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 81109a1520..206959f48e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1754,6 +1754,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues `onsite_checkout` int(1) NOT NULL default 0, -- in house use flag `note` LONGTEXT default NULL, -- issue note text `notedate` datetime default NULL, -- datetime of issue note (yyyy-mm-dd hh:mm::ss) + `noteseen` int(1) default NULL, -- describes whether checkout note has been seen 1, not been seen 0 or doesn't exist null PRIMARY KEY (`issue_id`), UNIQUE KEY `itemnumber` (`itemnumber`), KEY `issuesborridx` (`borrowernumber`), @@ -1785,6 +1786,7 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r `onsite_checkout` int(1) NOT NULL default 0, -- in house use flag `note` LONGTEXT default NULL, -- issue note text `notedate` datetime default NULL, -- datetime of issue note (yyyy-mm-dd hh:mm::ss) + `noteseen` int(1) default NULL, -- describes whether checkout note has been seen 1, not been seen 0 or doesn't exist null PRIMARY KEY (`issue_id`), KEY `old_issuesborridx` (`borrowernumber`), KEY `old_issuesitemidx` (`itemnumber`), diff --git a/installer/data/mysql/userpermissions.sql b/installer/data/mysql/userpermissions.sql index 93d030b410..ec53b0df61 100644 --- a/installer/data/mysql/userpermissions.sql +++ b/installer/data/mysql/userpermissions.sql @@ -4,6 +4,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'overdues_report', 'Execute overdue items report'), ( 1, 'force_checkout', 'Force checkout if a limitation exists'), ( 1, 'manage_restrictions', 'Manage restrictions for accounts'), + ( 1, 'manage_checkout_nots', 'Mark checkout notes as seen/not seen'), ( 3, 'parameters_remaining_permissions', 'Remaining system parameters permissions'), ( 3, 'manage_circ_rules', 'Manage circulation rules'), ( 4, 'edit_borrowers', 'Add, modify and view patron information'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc index c5330865fb..3bbbe7af25 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc @@ -31,6 +31,7 @@ [%- CASE 'manage_restrictions' -%]Manage restrictions for accounts [%- CASE 'overdues_report' -%]Execute overdue items report [%- CASE 'override_renewals' -%]Override blocked renewals + [%- CASE 'manage_checkout_notes' %]Mark checkout notes as seen/not seen [%- CASE 'manage_circ_rules' -%]manage circulation rules [%- CASE 'parameters_remaining_permissions' -%]Remaining system parameters permissions [%- CASE 'edit_borrowers' -%]Add, modify and view patron information diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/checkout-notes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/checkout-notes.tt new file mode 100644 index 0000000000..2fb1ec8593 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/checkout-notes.tt @@ -0,0 +1,164 @@ +[% USE Koha %] +[% USE KohaDates %] +[% USE Branches %] +[% INCLUDE 'doc-head-open.inc' %] +Home › Circulation › Checkout Notes +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables.inc' %] + +[% INCLUDE 'calendar.inc' %] + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'circ-search.inc' %] + + +
+
+
+ +

Checkout notes

+ +
+ + [% IF ( selected_count ) %] +
+ [% IF ( action == 'seen' ) %] + [% selected_count %] note(s) marked as seen. + [% ELSIF ( action == 'notseen' ) %] + [% selected_count %] note(s) marked as not seen. + [% ELSE %] + Failed to change the status of [% selected_count %] item(s). + [% END %] +
+ Return to checkout notes + [% ELSE %] + + [% IF ( notes ) %] +
+ Select all | Clear all +
+ +
+ + + + + + + + + + + + + + + [% FOREACH note IN notes %] + + + + + + + + + + [% END %] + +
 TitleNoteDateSet byStatusActions
[% note.item.biblionumber.title %] - [% note.item.biblionumber.author %] ([% note.item.barcode %])[% note.note %][% note.notedate | $KohaDates %][% note.borrower.firstname %] [% note.borrower.surname %] ([% note.borrower.cardnumber %])[% IF ( note.noteseen == 0 ) %] + Not seen + [% ELSIF ( note.noteseen == 1 ) %] + Seen + [% END %][% IF ( note.noteseen == 1 ) %] + + [% ELSIF ( note.noteseen == 0 ) %] + + [% END %]
+ +
+ + +
+ +
+ + [% END %] + + [% END %] + +
+
+
+ +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt index 802dd9af55..4f80a410b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt @@ -39,6 +39,11 @@ [% END %] [% END %] + [% IF ( Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes ) %] +
  • + Checkout notes [% IF ( pending_checkout_notes ) %][% pending_checkout_notes %][% END %] +
  • + [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt index 8a97473edc..59cc74698b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/intranet-main.tt @@ -172,6 +172,13 @@ [% END %] + [% IF Koha.Preference('AllowCheckoutNotes') && CAN_user_circulate_manage_checkout_notes && pending_checkout_notes %] +
    + Checkout notes pending: + [% pending_checkout_notes %] +
    + [% END %] + [% END %] diff --git a/mainpage.pl b/mainpage.pl index da6aaee924..34cd3a41c6 100755 --- a/mainpage.pl +++ b/mainpage.pl @@ -31,6 +31,7 @@ use Koha::Patron::Modifications; use Koha::Patron::Discharge; use Koha::Reviews; use Koha::ArticleRequests; +use Koha::Checkouts; my $query = new CGI; @@ -74,6 +75,7 @@ my $pending_article_requests = Koha::ArticleRequests->search_limited( $branch ? ( branchcode => $branch ) : (), } )->count; +my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count; $template->param( pendingcomments => $pendingcomments, @@ -82,6 +84,7 @@ $template->param( pending_borrower_modifications => $pending_borrower_modifications, pending_discharge_requests => $pending_discharge_requests, pending_article_requests => $pending_article_requests, + pending_checkout_notes => $pending_checkout_notes, ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/opac-issue-note.pl b/opac/opac-issue-note.pl index c279545e87..f97acdbd73 100755 --- a/opac/opac-issue-note.pl +++ b/opac/opac-issue-note.pl @@ -67,7 +67,7 @@ if ( $action eq 'issuenote' && C4::Context->preference('AllowCheckoutNotes') ) { my $note = $query->param('note'); my $scrubber = C4::Scrubber->new(); my $clean_note = $scrubber->scrub($note); - if ( $issue->set({ notedate => dt_from_string(), note => $clean_note })->store ) { + if ( $issue->set({ notedate => dt_from_string(), note => $clean_note, noteseen => 0 })->store ) { if ($clean_note) { # only send email if note not empty my $branch = Koha::Libraries->find( $issue->branchcode ); my $letter = C4::Letters::GetPreparedLetter ( diff --git a/opac/svc/checkout_notes b/opac/svc/checkout_notes index 43091daf43..a5682c8ceb 100755 --- a/opac/svc/checkout_notes +++ b/opac/svc/checkout_notes @@ -76,7 +76,7 @@ if ($is_ajax) { } if ( $issue ) { - $issue->set({ notedate => dt_from_string(), note => $clean_note })->store; + $issue->set({ notedate => dt_from_string(), note => $clean_note, noteseen => 0 })->store; if($clean_note) { # only send email if note not empty my $branch = Koha::Libraries->find( $issue->branchcode ); my $biblionumber = $issue->item->biblionumber; diff --git a/svc/checkout_notes b/svc/checkout_notes new file mode 100755 index 0000000000..5ad972c99a --- /dev/null +++ b/svc/checkout_notes @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2017 Aleisha Amohia +# +# 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 JSON qw( to_json ); +use CGI; +use C4::Service; +use C4::Auth qw /check_cookie_auth/; +use C4::Output qw(:DEFAULT :ajax); +use Koha::Checkouts; + +=head1 NAME + +svc/checkout_notes - Web service for managing patron notes set on issues + +=head1 DESCRIPTION + +=cut + +# AJAX requests +my $is_ajax = is_ajax(); +my $query = new CGI; +my ( $auth_status, $sessionID ) = check_cookie_auth( $query->cookie('CGISESSID'), { circulate => 'manage_checkout_notes' } ); +if ( $auth_status ne "ok" ) { + exit 0; +} +if ($is_ajax) { + my $issue_id = $query->param('issue_id'); + my $issue = Koha::Checkouts->find($issue_id); + my $action = $query->param('action'); + my $status = 'success'; + if ($action eq 'seen'){ + $issue->set({ noteseen => 1 })->store; + if ( $issue->noteseen != 1 ) { + $status = 'failure'; + } + } elsif ($action eq 'notseen'){ + $issue->set({ noteseen => 0 })->store; + if ( $issue->noteseen != 0 ) { + $status = 'failure'; + } + } + my $json = to_json ( { status => $status } ); + output_with_http_headers $query, undef, $json, 'js'; + exit; +} -- 2.39.5