Bugzilla – Attachment 132735 Details for
Bug 30063
Make the main patron search use the /patrons REST API route
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30063: Remove occurrences of C4::Utils::DataTables::Members
Bug-30063-Remove-occurrences-of-C4UtilsDataTablesM.patch (text/plain), 33.59 KB, created by
Jonathan Druart
on 2022-03-31 12:46:48 UTC
(
hide
)
Description:
Bug 30063: Remove occurrences of C4::Utils::DataTables::Members
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-03-31 12:46:48 UTC
Size:
33.59 KB
patch
obsolete
>From a84c16b9db357eaf929caffc99132f5cdd993244 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 14 Feb 2022 15:15:30 +0100 >Subject: [PATCH] Bug 30063: Remove occurrences of > C4::Utils::DataTables::Members >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: Séverine Queune <severine.queune@bulac.fr> >--- > C4/Utils/DataTables/Members.pm | 304 ----------- > circ/circulation.pl | 1 - > t/db_dependent/Utils/Datatables_Members.t | 598 ---------------------- > 3 files changed, 903 deletions(-) > delete mode 100644 C4/Utils/DataTables/Members.pm > delete mode 100755 t/db_dependent/Utils/Datatables_Members.t > >diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm >deleted file mode 100644 >index 15f04eb972a..00000000000 >--- a/C4/Utils/DataTables/Members.pm >+++ /dev/null >@@ -1,304 +0,0 @@ >-package C4::Utils::DataTables::Members; >- >-use Modern::Perl; >-use C4::Context; >-use C4::Utils::DataTables qw( dt_build_orderby ); >-use Koha::DateUtils qw( dt_from_string output_pref ); >- >-sub search { >- my ( $params ) = @_; >- my $searchmember = $params->{searchmember}; >- my $firstletter = $params->{firstletter}; >- my $categorycode = $params->{categorycode}; >- my $branchcode = $params->{branchcode}; >- my $searchtype = $params->{searchtype} || 'contain'; >- my $searchfieldstype = $params->{searchfieldstype} || 'standard'; >- my $has_permission = $params->{has_permission}; >- my $dt_params = $params->{dt_params}; >- >- unless ( $searchmember ) { >- $searchmember = $dt_params->{sSearch} // ''; >- } >- >- # If branches are independent and user is not superlibrarian >- # The search has to be only on the user branch >- my $userenv = C4::Context->userenv; >- my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); >- my @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; >- >- my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords); >- my $dbh = C4::Context->dbh; >- >- # Get the module_bit from a given permission code >- if ( $has_permission ) { >- ($has_permission->{module_bit}) = $dbh->selectrow_array(q| >- SELECT bit FROM userflags WHERE flag=? >- |, undef, $has_permission->{permission}); >- } >- >- my (@where, @conditions); >- # Get the iTotalRecords DataTable variable >- $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers"; >- if ( $has_permission ) { >- $iTotalQuery .= ' LEFT JOIN user_permissions ON borrowers.borrowernumber=user_permissions.borrowernumber'; >- $iTotalQuery .= ' AND module_bit=? AND code=?'; >- push @conditions, $has_permission->{module_bit}, $has_permission->{subpermission}; >- } >- >- if ( @restricted_branchcodes ) { >- push @where, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; >- push @conditions, @restricted_branchcodes; >- } >- if ( $has_permission ) { >- push @where, '( borrowers.flags = 1 OR borrowers.flags & (1 << ?) OR module_bit=? AND code=? )'; >- push @conditions, ($has_permission->{module_bit}) x 2, $has_permission->{subpermission}; >- } >- $iTotalQuery .= ' WHERE ' . join ' AND ', @where if @where; >- ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @conditions ); >- >- # Do that after iTotalQuery! >- if ( defined $branchcode and $branchcode ) { >- @restricted_branchcodes = @restricted_branchcodes >- ? grep ({ $_ eq $branchcode } @restricted_branchcodes) >- ? ($branchcode) >- : (undef) # Do not return any results >- : ($branchcode); >- } >- >- if ( $searchfieldstype eq 'dateofbirth' ) { >- # Return an empty list if the date of birth is not correctly formatted >- $searchmember = eval { output_pref( { str => $searchmember, dateformat => 'iso', dateonly => 1 } ); }; >- if ( $@ or not $searchmember ) { >- return { >- iTotalRecords => $iTotalRecords, >- iTotalDisplayRecords => 0, >- patrons => [], >- }; >- } >- } >- >- my $select = "SELECT >- borrowers.borrowernumber, borrowers.surname, borrowers.firstname, >- borrowers.othernames, >- borrowers.flags, >- borrowers.streetnumber, borrowers.streettype, borrowers.address, >- borrowers.address2, borrowers.city, borrowers.state, borrowers.zipcode, >- borrowers.country, cardnumber, borrowers.dateexpiry, >- borrowers.borrowernotes, borrowers.branchcode, borrowers.email, >- borrowers.userid, borrowers.dateofbirth, borrowers.categorycode, >- categories.description AS category_description, categories.category_type, >- branches.branchname, borrowers.phone"; >- my $from = "FROM borrowers >- LEFT JOIN branches ON borrowers.branchcode = branches.branchcode >- LEFT JOIN categories ON borrowers.categorycode = categories.categorycode"; >- my @where_args; >- if ( $has_permission ) { >- $from .= ' >- LEFT JOIN user_permissions ON borrowers.borrowernumber=user_permissions.borrowernumber >- AND module_bit=? AND code=?'; >- push @where_args, $has_permission->{module_bit}, $has_permission->{subpermission}; >- } >- my @where_strs; >- if(defined $firstletter and $firstletter ne '') { >- push @where_strs, "borrowers.surname LIKE ?"; >- push @where_args, "$firstletter%"; >- } >- if(defined $categorycode and $categorycode ne '') { >- push @where_strs, "borrowers.categorycode = ?"; >- push @where_args, $categorycode; >- } >- if(@restricted_branchcodes ) { >- push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; >- push @where_args, @restricted_branchcodes; >- } >- >- my $searchfields = { >- standard => C4::Context->preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid', >- email => 'email,emailpro,B_email', >- borrowernumber => 'borrowernumber', >- phone => 'phone,phonepro,B_phone,altcontactphone,mobile', >- address => 'streetnumber,streettype,address,address2,city,state,zipcode,country', >- }; >- >- # * is replaced with % for sql >- $searchmember =~ s/\*/%/g; >- >- # split into search terms >- my @terms; >- # consider coma as space >- $searchmember =~ s/,/ /g; >- if ( $searchtype eq 'contain' ) { >- @terms = split / /, $searchmember; >- } else { >- @terms = ($searchmember); >- } >- >- foreach my $term (@terms) { >- next unless $term; >- >- my $term_dt = eval { local $SIG{__WARN__} = {}; output_pref( { str => $term, dateonly => 1, dateformat => 'sql' } ); }; >- >- if ($term_dt) { >- $term = $term_dt; >- } else { >- $term .= '%' # end with anything >- if $term !~ /%$/; >- $term = "%$term" # begin with anythin unless start_with >- if $searchtype eq 'contain' && $term !~ /^%/; >- } >- >- my @where_strs_or; >- if ( defined $searchfields->{$searchfieldstype} ) { >- for my $searchfield ( split /,/, $searchfields->{$searchfieldstype} ) { >- push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfield) . " LIKE ?"; >- push @where_args, $term; >- } >- } else { >- push @where_strs_or, "borrowers." . $dbh->quote_identifier($searchfieldstype) . " LIKE ?"; >- push @where_args, $term; >- } >- >- >- if ( $searchfieldstype eq 'standard' and C4::Context->preference('ExtendedPatronAttributes') and $searchmember ) { >- push @where_strs_or, " borrowers.borrowernumber IN ( SELECT DISTINCT borrowernumber FROM borrower_attributes JOIN borrower_attribute_types USING (code) WHERE staff_searchable = 1 AND attribute LIKE ? ) "; >- push @where_args, $term; >- } >- >- push @where_strs, '('. join (' OR ', @where_strs_or) . ')' >- if @where_strs_or; >- } >- >- if ( $has_permission ) { >- push @where_strs, '( borrowers.flags = 1 OR borrowers.flags & (1 << ?) OR module_bit=? AND code=? )'; >- push @where_args, ($has_permission->{module_bit}) x 2, $has_permission->{subpermission}; >- } >- >- my $where = @where_strs ? " WHERE " . join (" AND ", @where_strs) : undef; >- my $orderby = dt_build_orderby($dt_params); >- >- my $limit; >- # If iDisplayLength == -1, we want to display all patrons >- if ( !$dt_params->{iDisplayLength} || $dt_params->{iDisplayLength} > -1 ) { >- # In order to avoid sql injection >- $dt_params->{iDisplayStart} =~ s/\D//g if defined($dt_params->{iDisplayStart}); >- $dt_params->{iDisplayLength} =~ s/\D//g if defined($dt_params->{iDisplayLength}); >- $dt_params->{iDisplayStart} //= 0; >- $dt_params->{iDisplayLength} //= 20; >- $limit = "LIMIT $dt_params->{iDisplayStart},$dt_params->{iDisplayLength}"; >- } >- >- $query = join( >- " ", >- ($select ? $select : ""), >- ($from ? $from : ""), >- ($where ? $where : ""), >- ($orderby ? $orderby : ""), >- ($limit ? $limit : "") >- ); >- $sth = $dbh->prepare($query); >- $sth->execute(@where_args); >- my $patrons = $sth->fetchall_arrayref({}); >- >- # Get the iTotalDisplayRecords DataTable variable >- $query = "SELECT COUNT(borrowers.borrowernumber) " . $from . ($where ? $where : ""); >- $sth = $dbh->prepare($query); >- $sth->execute(@where_args); >- ($iTotalDisplayRecords) = $sth->fetchrow_array; >- >- # Get some information on patrons >- foreach my $patron (@$patrons) { >- my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); >- $patron->{overdues} = $patron_object->get_overdues->count; >- $patron->{issues} = $patron_object->checkouts->count; >- $patron->{age} = $patron_object->get_age; >- my $balance = $patron_object->account->balance; >- # FIXME Should be formatted from the template >- $patron->{fines} = sprintf("%.2f", $balance); >- >- if( $patron->{dateexpiry} ) { >- # FIXME We should not format the date here, do it in template-side instead >- $patron->{dateexpiry} = output_pref( { dt => scalar dt_from_string( $patron->{dateexpiry}, 'iso'), dateonly => 1} ); >- } else { >- $patron->{dateexpiry} = ''; >- } >- } >- >- return { >- iTotalRecords => $iTotalRecords, >- iTotalDisplayRecords => $iTotalDisplayRecords, >- patrons => $patrons >- } >-} >- >-1; >-__END__ >- >-=head1 NAME >- >-C4::Utils::DataTables::Members - module for using DataTables with patrons >- >-=head1 SYNOPSIS >- >-This module provides (one for the moment) routines used by the patrons search >- >-=head2 FUNCTIONS >- >-=head3 search >- >- my $dt_infos = C4::Utils::DataTables::Members->search($params); >- >-$params is a hashref with some keys: >- >-=over 4 >- >-=item searchmember >- >- String to search in the borrowers sql table >- >-=item firstletter >- >- Introduced to contain 1 letter but can contain more. >- The search will done on the borrowers.surname field >- >-=item categorycode >- >- Search patrons with this categorycode >- >-=item branchcode >- >- Search patrons with this branchcode >- >-=item searchtype >- >- Can be 'start_with' or 'contain' (default value). Used for the searchmember parameter. >- >-=item searchfieldstype >- >- Can be 'standard' (default value), 'email', 'borrowernumber', 'phone', 'address' or 'dateofbirth', 'sort1', 'sort2' >- >-=item dt_params >- >- Is the reference of C4::Utils::DataTables::dt_get_params($input); >- >-=cut >- >-=back >- >-=head1 LICENSE >- >-This file is part of Koha. >- >-Copyright 2013 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 <http://www.gnu.org/licenses>. >diff --git a/circ/circulation.pl b/circ/circulation.pl >index ac8ef1e430b..dfa5cb1fd7c 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -34,7 +34,6 @@ use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_htt > use C4::Auth qw( get_session get_template_and_user ); > use C4::Koha; > use C4::Circulation qw( barcodedecode CanBookBeIssued AddIssue ); >-use C4::Utils::DataTables::Members; > use C4::Members; > use C4::Biblio qw( TransformMarcToKoha ); > use C4::Search qw( new_record_from_zebra ); >diff --git a/t/db_dependent/Utils/Datatables_Members.t b/t/db_dependent/Utils/Datatables_Members.t >deleted file mode 100755 >index 25128d88649..00000000000 >--- a/t/db_dependent/Utils/Datatables_Members.t >+++ /dev/null >@@ -1,598 +0,0 @@ >-#!/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 Test::More tests => 53; >- >-use C4::Context; >-use C4::Members; >- >-use Koha::Library; >-use Koha::Patrons; >-use Koha::Patron::Categories; >- >-use t::lib::Mocks; >-use t::lib::TestBuilder; >- >-use Koha::Database; >- >-use_ok( "C4::Utils::DataTables::Members" ); >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- >-my $builder = t::lib::TestBuilder->new; >- >-my $library = $builder->build({ >- source => "Branch", >-}); >- >-my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 1 } }); >-t::lib::Mocks::mock_userenv({ patron => $patron }); >- >-my $branchcode=$library->{branchcode}; >- >-my $john_doe = $builder->build({ >- source => "Borrower", >- value => { >- cardnumber => '123456', >- firstname => 'John', >- surname => 'Doe', >- branchcode => $branchcode, >- dateofbirth => '1983-03-01', >- userid => 'john.doe', >- initials => 'pacman', >- flags => 0, >- }, >-}); >- >-my $john_smith = $builder->build({ >- source => "Borrower", >- value => { >- cardnumber => '234567', >- firstname => 'John', >- surname => 'Smith', >- branchcode => $branchcode, >- dateofbirth => '1982-02-01', >- userid => 'john.smith', >- flags => 0, >- }, >-}); >- >-my $jane_doe = $builder->build({ >- source => "Borrower", >- value => { >- cardnumber => '345678', >- firstname => 'Jane', >- surname => 'Doe', >- branchcode => $branchcode, >- dateofbirth => '1983-03-01', >- userid => 'jane.doe', >- flags => 0, >- }, >-}); >-my $jeanpaul_dupont = $builder->build({ >- source => "Borrower", >- value => { >- cardnumber => '456789', >- firstname => 'Jean Paul', >- surname => 'Dupont', >- branchcode => $branchcode, >- dateofbirth => '1982-02-01', >- userid => 'jeanpaul.dupont', >- flags => 0, >- }, >-}); >-my $dupont_brown = $builder->build({ >- source => "Borrower", >- value => { >- cardnumber => '567890', >- firstname => 'Dupont', >- surname => 'Brown', >- branchcode => $branchcode, >- dateofbirth => '1979-01-01', >- userid => 'dupont.brown', >- flags => 0, >- }, >-}); >- >-# Set common datatables params >-my %dt_params = ( >- iDisplayLength => 10, >- iDisplayStart => 0 >-); >- >-t::lib::Mocks::mock_preference('DefaultPatronSearchFields', ''); >- >-# Search "John Doe" >-my $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "John Doe", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "John Doe has only one match on $branchcode (Bug 12595)"); >- >-ok( $search_results->{ patrons }[0]->{ cardnumber } eq $john_doe->{ cardnumber } >- && ! $search_results->{ patrons }[1], >- "John Doe is the only match (Bug 12595)"); >- >-# Search "Jane Doe" >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Jane Doe", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "Jane Doe has only one match on $branchcode (Bug 12595)"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $jane_doe->{ cardnumber }, >- "Jane Doe is the only match (Bug 12595)"); >- >-# Search "John" >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "John", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 2, >- "There are two John at $branchcode"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $john_doe->{ cardnumber }, >- "John Doe is the first result"); >- >-is( $search_results->{ patrons }[1]->{ cardnumber }, >- $john_smith->{ cardnumber }, >- "John Smith is the second result"); >- >-# Search "Doe" >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Doe", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 2, >- "There are two Doe at $branchcode"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $john_doe->{ cardnumber }, >- "John Doe is the first result"); >- >-is( $search_results->{ patrons }[1]->{ cardnumber }, >- $jane_doe->{ cardnumber }, >- "Jane Doe is the second result"); >- >-# Search "Smith" as surname - there is only one occurrence of Smith >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Smith", >- searchfieldstype => 'surname', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "There is one Smith at $branchcode when searching for surname"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $john_smith->{ cardnumber }, >- "John Smith is the first result"); >- >-# Search "Dupont" as surname - Dupont is used both as firstname and surname, we >-# Should only fin d the user with Dupont as surname >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Dupont", >- searchfieldstype => 'surname', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "There is one Dupont at $branchcode when searching for surname"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $jeanpaul_dupont->{ cardnumber }, >- "Jean Paul Dupont is the first result"); >- >-# Search "Doe" as surname - Doe is used twice as surname >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Doe", >- searchfieldstype => 'surname', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 2, >- "There are two Doe at $branchcode when searching for surname"); >- >-is( $search_results->{ patrons }[0]->{ cardnumber }, >- $john_doe->{ cardnumber }, >- "John Doe is the first result"); >- >-is( $search_results->{ patrons }[1]->{ cardnumber }, >- $jane_doe->{ cardnumber }, >- "Jane Doe is the second result"); >- >-# Search by userid >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "john.doe", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "John Doe is found by userid, standard search (Bug 14782)"); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "john.doe", >- searchfieldstype => 'userid', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "John Doe is found by userid, userid search (Bug 14782)"); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "john.doe", >- searchfieldstype => 'surname', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 0, >- "No members are found by userid, surname search"); >- >-my $attribute_type = Koha::Patron::Attribute::Type->new( >- { >- code => 'ATM_1', >- description => 'my attribute type', >- staff_searchable => 1 >- } >-)->store; >- >-Koha::Patrons->find( $john_doe->{borrowernumber} )->extended_attributes( >- [ >- { >- code => $attribute_type->code, >- attribute => 'the default value for a common user' >- } >- ] >-); >-Koha::Patrons->find( $jane_doe->{borrowernumber} )->extended_attributes( >- [ >- { >- code => $attribute_type->code, >- attribute => 'the default value for another common user' >- } >- ] >-); >-Koha::Patrons->find( $john_smith->{borrowernumber} )->extended_attributes( >- [ >- { >- code => $attribute_type->code, >- attribute => 'Attribute which not appears even if contains "Dupont"' >- } >- ] >-); >- >-t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "common user", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords}, 2, "There are 2 common users" ); >- >-t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 0); >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "common user", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >-is( $search_results->{ iTotalDisplayRecords}, 0, "There are still 2 common users, but the patron attribute is not searchable " ); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Jean Paul", >- searchfieldstype => 'standard', >- searchtype => 'start_with', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "Jean Paul Dupont is found using start with and two terms search 'Jean Paul' (Bug 15252)"); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Jean Pau", >- searchfieldstype => 'standard', >- searchtype => 'start_with', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "Jean Paul Dupont is found using start with and two terms search 'Jean Pau' (Bug 15252)"); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Jea Pau", >- searchfieldstype => 'standard', >- searchtype => 'start_with', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 0, >- "Jean Paul Dupont is not found using start with and two terms search 'Jea Pau' (Bug 15252)"); >- >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Jea Pau", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >-}); >- >-is( $search_results->{ iTotalDisplayRecords }, 1, >- "Jean Paul Dupont is found using contains and two terms search 'Jea Pau' (Bug 15252)"); >- >-my @datetimeprefs = ("dmydot","iso","metric","us"); >-my %dates_in_pref = ( >- dmydot => ["01.02.1982","01.03.1983","01.01.1979","01.01.1988"], >- iso => ["1982-02-01","1983-03-01","1979-01-01","1988-01-01"], >- metric => ["01/02/1982","01/03/1983","01/01/1979","01/01/1988"], >- us => ["02/01/1982","03/01/1983","01/01/1979","01/01/1988"], >- ); >-foreach my $dateformloo (@datetimeprefs){ >- t::lib::Mocks::mock_preference('dateformat', $dateformloo); >- t::lib::Mocks::mock_preference('DefaultPatronSearchFields', 'surname,firstname,othernames,userid,dateofbirth'); >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => $dates_in_pref{$dateformloo}[0], >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 2, >- "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[0], standard search fields plus dob works"); >- >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => $dates_in_pref{$dateformloo}[2], >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 1, >- "dateformat: $dateformloo One borrower has dob $dates_in_pref{$dateformloo}[2], standard search fields plus dob works"); >- >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => $dates_in_pref{$dateformloo}[1], >- searchfieldstype => 'dateofbirth', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 2, >- "dateformat: $dateformloo Two borrowers have dob $dates_in_pref{$dateformloo}[1], dateofbirth search field works"); >- >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => $dates_in_pref{$dateformloo}[3], >- searchfieldstype => 'dateofbirth', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 0, >- "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], dateofbirth search field works"); >- >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => $dates_in_pref{$dateformloo}[3], >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 0, >- "dateformat: $dateformloo No borrowers have dob $dates_in_pref{$dateformloo}[3], standard search fields plus dob works"); >-} >- >-# Date of birth formatting >-t::lib::Mocks::mock_preference('dateformat', 'metric'); >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "01/02/1982", >- searchfieldstype => 'dateofbirth', >- dt_params => \%dt_params >-}); >-is( $search_results->{ iTotalDisplayRecords }, 2, >- "Sarching by date of birth should handle date formatted given the dateformat pref"); >-$search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "1982-02-01", >- searchfieldstype => 'dateofbirth', >- dt_params => \%dt_params >-}); >-is( $search_results->{ iTotalDisplayRecords }, 2, >- "Sarching by date of birth should handle date formatted in iso"); >- >-subtest 'ExtendedPatronAttributes' => sub { >- plan tests => 2; >- t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 1); >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Dupont", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 3, >- "'Dupont' is contained in 2 surnames and a patron attribute. Patron attribute one should be displayed if searching in all fields (Bug 18094)"); >- >- $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "Dupont", >- searchfieldstype => 'surname', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- >- is( $search_results->{ iTotalDisplayRecords }, 1, >- "'Dupont' is contained in 2 surnames and a patron attribute. Patron attribute one should not be displayed if searching in specific fields (Bug 18094)"); >-}; >- >-subtest 'Search by any borrowers field (bug 17374)' => sub { >- plan tests => 2; >- >- my $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "pacman", >- searchfieldstype => 'initials', >- searchtype => 'contain', >- branchcode => $branchcode, >- dt_params => \%dt_params >- }); >- is( $search_results->{ iTotalDisplayRecords }, 1, "We find only 1 patron when searching for initials 'pacman'" ); >- >- is( $search_results->{ patrons }[0]->{ cardnumber }, $john_doe->{cardnumber}, "We find the correct patron when sesrching by initials" ) >-}; >- >-subtest 'Search with permissions' => sub { >- plan tests => 4; >- >- my $superlibrarian = $builder->build_object( >- { >- class => 'Koha::Patrons', >- value => { branchcode => $branchcode, flags => 1 } >- } >- ); >- my $librarian_with_full_permission = $builder->build_object( >- { >- class => 'Koha::Patrons', >- value => { branchcode => $branchcode, flags => 4100 } >- } >- ); # 4100 = 4096 (2^12 suggestions) + 4 (2^2 catalogue) >- my $librarian_with_subpermission = $builder->build_object( >- { class => 'Koha::Patrons', value => { branchcode => $branchcode } } ); >- C4::Context->dbh->do( >- q|INSERT INTO user_permissions(borrowernumber, module_bit, code) VALUES(?,?,?)|, >- undef, >- $librarian_with_subpermission->borrowernumber, >- 12, >- 'suggestions_manage' >- ); >- >- my $search_results = C4::Utils::DataTables::Members::search( >- { >- searchmember => "", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- has_permission => { >- permission => 'suggestions', >- subpermission => 'suggestions_manage' >- }, >- dt_params => { iDisplayLength => 3, iDisplayStart => 0 }, >- } >- ); >- is( $search_results->{iTotalDisplayRecords}, >- 3, "We find 3 patrons with suggestions_manage permission" ); >- is_deeply( >- [ sort map { $_->{borrowernumber} } @{ $search_results->{patrons} } ], >- [ >- $superlibrarian->borrowernumber, >- $librarian_with_full_permission->borrowernumber, >- $librarian_with_subpermission->borrowernumber >- ], >- 'We got the 3 patrons we expected' >- ); >- >- C4::Context->dbh->do( >- q|INSERT INTO user_permissions(borrowernumber, module_bit, code) VALUES(?,?,?)|, >- undef, >- $librarian_with_subpermission->borrowernumber, >- 13, >- 'moderate_comments' >- ); >- $search_results = C4::Utils::DataTables::Members::search( >- { >- searchmember => "", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- branchcode => $branchcode, >- has_permission => { >- permission => 'suggestions', >- subpermission => 'suggestions_manage' >- }, >- dt_params => { iDisplayLength => 3, iDisplayStart => 0 }, >- } >- ); >- is( $search_results->{iTotalDisplayRecords}, >- 3, "We find 3 patrons with suggestions_manage permission" ); >- is_deeply( >- [ sort map { $_->{borrowernumber} } @{ $search_results->{patrons} } ], >- [ >- $superlibrarian->borrowernumber, >- $librarian_with_full_permission->borrowernumber, >- $librarian_with_subpermission->borrowernumber >- ], >- 'We got the 3 patrons we expected' >- ); >- >-}; >- >-subtest 'return values' => sub { >- plan tests => 1; >- my $search_results = C4::Utils::DataTables::Members::search({ >- searchmember => "John Doe", >- searchfieldstype => 'standard', >- searchtype => 'contain', >- }); >- ok(exists $search_results->{patrons}->[0]->{othernames}, 'othernames should have been retrieved' ); >-}; >- >-# End >-$schema->storage->txn_rollback; >-- >2.25.1
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 30063
:
130608
|
130609
|
130610
|
130611
|
130612
|
130613
|
130614
|
130615
|
132387
|
132552
|
132731
|
132732
|
132733
|
132734
|
132735
|
132736
|
132737
|
132738
|
132739
|
132740
|
132741
|
132742
|
132743
|
132744
|
132745
|
132746
|
132747
|
132748
|
132749
|
132759
|
132760
|
132761
|
132762
|
132763
|
132764
|
132765
|
132766
|
132767
|
132768
|
132769
|
132770
|
132771
|
132772
|
132773
|
132774
|
132775
|
132776
|
132777
|
132958