From 7045235a8d039ccbe5ba1c89f2b616c8c9ba3738 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Nov 2020 15:01:32 +0100 Subject: [PATCH] Bug 26738: [20.05.x] (bug 24819 follow-up) Fix manager selection Bug 23590 added a new feature to select the manager of a suggestion. One month later bug 24819 added the ability to pick the suggester. This second patchset broke the manager selection. This patch simplifies the way the suggester is selected, using the generic way and mimicking what is done for the manager. Test plan: - create a new purchase suggestion from within acquisitions (suggestion.pl?op=add) - click "select manager," search for user, click Select - see that the user you just selected shows under "Created by," - see that "Managed by" still says "You" - modify the suggester - save your suggestion => Everything is saved correctly QA will test the permission alert: Edit suggestion.tt and remove "&permissions=suggestions.suggestions_manage" Edit the suggestion, select a manager, pick a patron in the list who does not have sufficient permissions, save => you get the alert Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Tomas Cohen Arazi Bug 26738: (QA follow-up) Add missing filter Signed-off-by: Tomas Cohen Arazi Signed-off-by: Lucas Gass Signed-off-by: Lucas Gass --- .../prog/en/modules/common/patron_search.tt | 6 +- .../prog/en/modules/suggestion/suggestion.tt | 30 ++++++++-- .../suggestion/tables/suggester_search.tt | 36 ------------ .../intranet-tmpl/prog/js/suggestions.js | 17 ------ suggestion/add_user_search.pl | 7 ++- suggestion/suggester_search.pl | 57 ------------------- suggestion/suggestion.pl | 14 ++++- 7 files changed, 48 insertions(+), 119 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/tables/suggester_search.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/js/suggestions.js delete mode 100755 suggestion/suggester_search.pl diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt index b78ec9bd31..436e78cc05 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt @@ -285,7 +285,11 @@ [% ELSIF selection_type == 'select' %] function select_user(borrowernumber, data) { var p = window.opener; - p.select_user(borrowernumber, data); + [% IF callback %] + p.[% callback | html %](borrowernumber, data); + [% ELSE %] + p.select_user(borrowernumber, data); + [% END %] window.close(); } [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt index 1173c33223..845df295f1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tt @@ -264,6 +264,8 @@ [% SWITCH m.code %] [% CASE 'biblio_exists' %] A similar document already exists: [% m.title | html %]. Click on "Confirm your suggestion" to ignore this message. + [% CASE 'manager_not_enough_permissions' %] + The manager you selected does not have sufficient permissions. [% CASE %] [% m.code | html %] [% END %] @@ -390,7 +392,7 @@ [% INCLUDE 'date-format.inc' %] [% IF ( suggestedby_patron.borrowernumber ) %][% suggestedby_patron.surname | html %], [% suggestedby_patron.firstname | html %] ([% suggestedby_patron.cardnumber | html %]) [% Branches.GetName( suggestedby_patron.branchcode ) | html %] ([% suggestedby_patron.category.description | html %])[% END %] - Set to patron + Set to patron @@ -954,13 +956,13 @@ var tab = ''; function editManagerPopup(selected_tab) { tab = selected_tab; - window.open("/cgi-bin/koha/suggestion/add_user_search.pl?selection_type=select", + window.open("/cgi-bin/koha/suggestion/add_user_search.pl?selection_type=select&callback=select_manager&permissions=suggestions.suggestions_manage", 'PatronPopup', 'width=740,height=450,location=yes,toolbar=no,' + 'scrollbars=yes,resize=yes' ); } - function select_user(borrowernumber, borrower) { + function select_manager(borrowernumber, borrower) { var managedby_name = $("#managedby_name"+tab); var managedby = $("#managedby"+tab); managedby_name.empty(); @@ -990,6 +992,23 @@ [% END %] } + function editSuggesterPopup() { + window.open("/cgi-bin/koha/suggestion/add_user_search.pl?selection_type=select&callback=select_suggester", + 'PatronPopup', + 'width=740,height=450,location=yes,toolbar=no,' + + 'scrollbars=yes,resize=yes' + ); + } + + function select_suggester(borrowernumber, borrower) { + var suggested = ''; + suggested += ''; + suggested += borrower.surname + ', ' + borrower.firstname + ' (' + borrower.cardnumber + ')'; + suggested += ' '; + suggested += borrower.branchname + ' (' + borrower.category_description + ')'; + $("#tdsuggestedby").html(suggested); + return 0; + } $(document).ready(function(){ $("#edit_manager").on("click",function(e){ e.preventDefault(); @@ -1001,6 +1020,10 @@ editManagerPopup(selected_tab); }); + $("#edit_suggester").on("click", function(e){ + e.preventDefault(); + editSuggesterPopup(); + }); }); @@ -1190,6 +1213,5 @@ [% END %] [% Asset.js("js/acq.js") | $raw %] [% Asset.js("js/acquisitions-menu.js") | $raw %] - [% Asset.js("js/suggestions.js") | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/tables/suggester_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/tables/suggester_search.tt deleted file mode 100644 index a82f0e8dcb..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/tables/suggester_search.tt +++ /dev/null @@ -1,36 +0,0 @@ -[% USE raw %] -[% USE To %] -[% USE Branches %] -[% USE KohaDates %] -{ - "sEcho": [% sEcho | html %], - "iTotalRecords": [% iTotalRecords | html %], - "iTotalDisplayRecords": [% iTotalDisplayRecords | html %], - "aaData": [ - [% FOREACH data IN aaData %] - { - "dt_cardnumber": - "[% data.cardnumber | html %]", - "dt_name": - "[% INCLUDE 'patron-title.inc' borrowernumber = data.borrowernumber category_type = data.category_type firstname = data.firstname surname = data.surname othernames = data.othernames cardnumber = data.cardnumber invert_name = 1%]", - "dt_dateofbirth": - "[% data.dateofbirth | $KohaDates %]", - "dt_address": - "[% INCLUDE escape_address data=data %]", - "dt_action": - "Select" - }[% UNLESS loop.last %],[% END %] - [% END %] - ] -} -[% BLOCK escape_address %] -[%~ SET address = data.streetnumber _ ' ' %] -[%~ IF data.address %][% SET address = address _ data.address _ ' ' %][% END %] -[%~ IF data.address2 %][% SET address = address _ data.address2 _ ' ' %][% END %] -[%~ IF data.city %][% SET address = address _ data.city _ ' ' %][% END %] -[%~ IF data.state %][% SET address = address _ data.state _ ' ' %][% END %] -[%~ IF data.zipcode %][% SET address = address _ data.zipcode _ ' ' %][% END %] -[%~ IF data.country %][% SET address = address _ data.country _ ' ' %][% END %] -[%~ SET address = address _ Branches.GetName( data.branchcode ) %] -[%~ To.json( address ) | $raw ~%] -[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/suggestions.js b/koha-tmpl/intranet-tmpl/prog/js/suggestions.js deleted file mode 100644 index cff05bd094..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/js/suggestions.js +++ /dev/null @@ -1,17 +0,0 @@ -function select_user(borrowernumber, borrower) { - var suggested = ''; - suggested += ''; - suggested += borrower.surname + ', ' + borrower.firstname + ' (' + borrower.cardnumber + ')'; - suggested += ' '; - suggested += borrower.branchname + ' (' + borrower.category_description + ')'; - $("#tdsuggestedby").html(suggested); - return 0; -} - -$(document).ready(function(){ - $('body').on('click', '#suggester_search', function(e) { - e.preventDefault(); - var newin = window.open('suggester_search.pl','popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top'); - }); - -}); diff --git a/suggestion/add_user_search.pl b/suggestion/add_user_search.pl index 25014475ed..07b5589de4 100755 --- a/suggestion/add_user_search.pl +++ b/suggestion/add_user_search.pl @@ -43,16 +43,17 @@ my $selection_type = $input->param('selection_type') || 'add'; my $referer = $input->referer(); -# If this script is called by suggestion/suggestion.pl -# the patrons to return should be superlibrarian or have the suggestions_manage flag +# The patrons to return should be superlibrarian or have the suggestions_manage flag +my $permissions = $input->param('permissions'); my $search_patrons_with_suggestion_perm_only = - ( $referer =~ m|suggestion/suggestion.pl| ) + ( $permissions && $permissions eq 'suggestions.suggestions_manage' ) ? 1 : 0; my $patron_categories = Koha::Patron::Categories->search_limited; $template->param( patrons_with_suggestion_perm_only => $search_patrons_with_suggestion_perm_only, view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", + callback => scalar $input->param('callback'), columns => ['cardnumber', 'name', 'branch', 'category', 'action'], json_template => 'acqui/tables/members_results.tt', selection_type => $selection_type, diff --git a/suggestion/suggester_search.pl b/suggestion/suggester_search.pl deleted file mode 100755 index bdbb281137..0000000000 --- a/suggestion/suggester_search.pl +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Copyright 2020 BibLibre -# -# 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::Auth; -use C4::Output; -use C4::Members; - -use Koha::Patron::Categories; - -my $input = new CGI; - -my $dbh = C4::Context->dbh; - -my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( - { template_name => "common/patron_search.tt", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { suggestions => 'suggestions_manage' }, - } -); - -my $q = $input->param('q') || ''; -my $op = $input->param('op') || ''; - -my $referer = $input->referer(); - -my $patron_categories = Koha::Patron::Categories->search_limited; -$template->param( - view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", - columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ], - json_template => 'suggestion/tables/suggester_search.tt', - selection_type => 'select', - alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), - categories => $patron_categories, - aaSorting => 1, -); -output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 4f5c915e53..591c0159a1 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -134,13 +134,25 @@ if ( $op =~ /save/i ) { itemtype => $suggestion_only->{itemtype}, }); - if ( !$suggestion_only->{suggestionid} && ( my ($duplicatebiblionumber, $duplicatetitle) = FindDuplicate($biblio) ) && !$save_confirmed ) { + my $manager = Koha::Patrons->find( $suggestion_only->{managedby} ); + if ( $manager && not $manager->has_permission({suggestions => 'suggestions_manage'})) { + push @messages, { type => 'error', code => 'manager_not_enough_permissions' }; + $template->param( + messages => \@messages, + ); + delete $suggestion_ref->{suggesteddate}; + delete $suggestion_ref->{manageddate}; + delete $suggestion_ref->{managedby}; + Init($suggestion_ref); + } + elsif ( !$suggestion_only->{suggestionid} && ( my ($duplicatebiblionumber, $duplicatetitle) = FindDuplicate($biblio) ) && !$save_confirmed ) { push @messages, { type => 'error', code => 'biblio_exists', id => $duplicatebiblionumber, title => $duplicatetitle }; $template->param( messages => \@messages, need_confirm => 1 ); delete $suggestion_ref->{suggesteddate}; + delete $suggestion_ref->{manageddate}; Init($suggestion_ref); } else { -- 2.39.5