From bb1beb4f5d45fd288ad1ed8cb893b4bd2a01c1db Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 24 Jul 2014 13:33:06 +0200 Subject: [PATCH] Bug 12648: Refactoring to prepare user search for reuse A previous enhancement allows to link basket with patrons. Next patches will use the same way to link order with patrons. In order to avoir c/p of code, this patch refactores this part of code. Test plan: 1/ Verify there is no regression on adding/modifying users to a basket. (acqui/basket.pl?basketno=XXX, "Managed by", "Add user"). 2/ Note that you get a friendly message if the user is already present in the list and when the user has correctly been added to the list. 3/ Note that the list uses the member search service (ie. DataTable + serverside processing). Signed-off-by: Paola Rossi Signed-off-by: Tomas Cohen Arazi --- C4/Utils/DataTables/Members.pm | 6 +- ...asketuser_search.pl => add_user_search.pl} | 58 +++++++---- .../prog/en/modules/acqui/add_user_search.tt | 95 +++++++++++++++++++ .../en/modules/acqui/aqbasketuser_search.tt | 79 --------------- .../prog/en/modules/acqui/basket.tt | 32 +++---- .../modules/acqui/tables/members_results.tt | 21 ++++ svc/members/search | 2 +- 7 files changed, 176 insertions(+), 117 deletions(-) rename acqui/{aqbasketuser_search.pl => add_user_search.pl} (50%) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/tables/members_results.tt diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm index 95f6a82c9a..6a97ea3071 100644 --- a/C4/Utils/DataTables/Members.pm +++ b/C4/Utils/DataTables/Members.pm @@ -13,9 +13,13 @@ sub search { my $categorycode = $params->{categorycode}; my $branchcode = $params->{branchcode}; my $searchtype = $params->{searchtype}; - my $searchfieldstype = $params->{searchfieldstype}; + my $searchfieldstype = $params->{searchfieldstype} || 'standard'; my $dt_params = $params->{dt_params}; + unless ( $searchmember ) { + $searchmember = $dt_params->{sSearch}; + } + my ($iTotalRecords, $iTotalDisplayRecords); # If branches are independant and user is not superlibrarian diff --git a/acqui/aqbasketuser_search.pl b/acqui/add_user_search.pl similarity index 50% rename from acqui/aqbasketuser_search.pl rename to acqui/add_user_search.pl index 660fd499e1..a950464889 100755 --- a/acqui/aqbasketuser_search.pl +++ b/acqui/add_user_search.pl @@ -1,23 +1,21 @@ #!/usr/bin/perl -# script to find a basket user - -# Copyright 2012 BibLibre SARL -# # 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 2 of the License, or (at your option) any later -# version. +# Copyright 2014 BibLibre # -# 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. +# 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. # -# 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. +# 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; @@ -31,7 +29,7 @@ my $input = new CGI; my $dbh = C4::Context->dbh; my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( - { template_name => "acqui/aqbasketuser_search.tt", + { template_name => "acqui/add_user_search.tt", query => $input, type => "intranet", authnotrequired => 0, @@ -42,18 +40,35 @@ my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user( my $q = $input->param('q') || ''; my $op = $input->param('op') || ''; +my $referer = $input->referer(); + +# If this script is called by acqui/basket.pl +# the patrons to return should be superlibrarian or have the order_manage +# acquisition flag. +my $search_patrons_with_acq_perm_only = + ( $referer =~ m|acqui/basket.pl| ) + ? 1 : 0; + if( $op eq "do_search" ) { my $results = C4::Members::Search( $q, "surname"); my @users_loop; my $nresults = 0; foreach my $res (@$results) { - my $perms = haspermission( $res->{userid} ); - my $subperms = get_user_subpermissions( $res->{userid} ); + my $should_be_returned = 1; + + if ( $search_patrons_with_acq_perm_only ) { + $should_be_returned = 0; + my $perms = haspermission( $res->{userid} ); + my $subperms = get_user_subpermissions( $res->{userid} ); - if( $perms->{superlibrarian} == 1 - || $perms->{acquisition} == 1 - || $subperms->{acquisition}->{'order_manage'} ) { + if( $perms->{superlibrarian} == 1 + || $perms->{acquisition} == 1 + || $subperms->{acquisition}->{'order_manage'} ) { + $should_be_returned = 1; + } + } + if ( $should_be_returned ) { my %row = ( borrowernumber => $res->{borrowernumber}, cardnumber => $res->{cardnumber}, @@ -74,4 +89,7 @@ if( $op eq "do_search" ) { ); } +$template->param( + patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, +); output_html_with_http_headers( $input, $cookie, $template->output ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt new file mode 100644 index 0000000000..02c8035da4 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt @@ -0,0 +1,95 @@ +[% USE Koha %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Patron search +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables.inc' %] + + + + + +