Bugzilla – Attachment 62844 Details for
Bug 18403
Hide patron information if not part of the logged in user library group
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18403: Add new methods Koha::Patrons->search_limited and use it where needed
Bug-18403-Add-new-methods-KohaPatrons-searchlimite.patch (text/plain), 4.02 KB, created by
Martin Renvoize (ashimema)
on 2017-04-28 15:30:31 UTC
(
hide
)
Description:
Bug 18403: Add new methods Koha::Patrons->search_limited and use it where needed
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2017-04-28 15:30:31 UTC
Size:
4.02 KB
patch
obsolete
>From 6313752c9406ee6c841c380225624f57f408959a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 6 Apr 2017 12:42:03 -0300 >Subject: [PATCH] Bug 18403: Add new methods Koha::Patrons->search_limited and > use it where needed > >Most of the time when we search for patrons we do not want to search for all patrons, >but just the ones the logged in user is allowed to see the information. >This patch takes care of that by adding a new search_limited method to Koha::Patrons. >When called this method only search for patrons that the logged in user is allowed >to see. > >Test plan: >Patron autocomplete search should be limited > >Signed-off-by: Jon McGowan <jon.mcgowan@ptfs-europe.com> >--- > Koha/Patrons.pm | 35 +++++++++++++++++++++++++++++++++++ > circ/ysearch.pl | 2 +- > members/memberentry.pl | 2 +- > opac/opac-memberentry.pl | 2 +- > 4 files changed, 38 insertions(+), 3 deletions(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index b8aebeb..1dfb396 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -41,6 +41,41 @@ Koha::Patron - Koha Patron Object class > > =cut > >+=head3 search_limited >+ >+my $patrons = Koha::Patrons->search_limit( $params, $attributes ); >+ >+Returns all the patrons the logged in user is allowed to see >+ >+=cut >+ >+sub search_limited { >+ my ( $self, $params, $attributes ) = @_; >+ >+ my $userenv = C4::Context->userenv; >+ my @restricted_branchcodes; >+ my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); >+ if ( $logged_in_user and not >+ $logged_in_user->can( >+ { borrowers => 'view_borrower_infos_from_any_libraries' } >+ ) >+ ) >+ { >+ if ( my $library_groups = $logged_in_user->library->library_groups ) >+ { >+ while ( my $library_group = $library_groups->next ) { >+ push @restricted_branchcodes, >+ $library_group->parent->children->get_column('branchcode'); >+ } >+ } >+ else { >+ push @restricted_branchcodes, $userenv->{branch}; >+ } >+ } >+ $params->{'me.branchcode'} = { -in => \@restricted_branchcodes } if @restricted_branchcodes; >+ return $self->search( $params, $attributes ); >+} >+ > =head3 search_housebound_choosers > > Returns all Patrons which are Housebound choosers. >diff --git a/circ/ysearch.pl b/circ/ysearch.pl >index 37eaed4..7a75c80 100755 >--- a/circ/ysearch.pl >+++ b/circ/ysearch.pl >@@ -67,7 +67,7 @@ foreach my $p (@parts) { > > push( @params, { branchcode => C4::Context->userenv->{branch} } ) if $limit_on_branch; > >-my $borrowers_rs = Koha::Patrons->search( >+my $borrowers_rs = Koha::Patrons->search_limited( > { -and => \@params }, > { > # Get the first 10 results >diff --git a/members/memberentry.pl b/members/memberentry.pl >index 4a1394c..c6d9ccd 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -241,7 +241,7 @@ if ( ( $op eq 'insert' ) and !$nodouble ) { > $conditions->{dateofbirth} = $newdata{dateofbirth} if $newdata{dateofbirth}; > } > $nodouble = 1; >- my $patrons = Koha::Patrons->search($conditions); >+ my $patrons = Koha::Patrons->search($conditions); # FIXME Should be search_limited? > if ( $patrons->count > 0) { > $nodouble = 0; > $check_member = $patrons->next->borrowernumber; >diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl >index dfaa965..487e000 100755 >--- a/opac/opac-memberentry.pl >+++ b/opac/opac-memberentry.pl >@@ -391,7 +391,7 @@ sub CheckForInvalidFields { > unless ( Email::Valid->address($borrower->{'email'}) ) { > push(@invalidFields, "email"); > } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) { >- my $patrons_with_same_email = Koha::Patrons->search( { email => $borrower->{email} })->count; >+ my $patrons_with_same_email = Koha::Patrons->search( { email => $borrower->{email} })->count; # FIXME Should be search_limited? > if ( $patrons_with_same_email ) { > push @invalidFields, "duplicate_email"; > } >-- >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 18403
:
62010
|
62011
|
62012
|
62013
|
62014
|
62015
|
62016
|
62017
|
62018
|
62019
|
62020
|
62021
|
62022
|
62023
|
62024
|
62025
|
62026
|
62027
|
62028
|
62029
|
62030
|
62031
|
62032
|
62033
|
62302
|
62303
|
62830
|
62831
|
62832
|
62833
|
62834
|
62835
|
62836
|
62837
|
62838
|
62839
|
62840
|
62841
|
62842
|
62843
|
62844
|
62845
|
62846
|
62847
|
62848
|
62849
|
62850
|
62851
|
62852
|
62853
|
62854
|
62855
|
71392
|
71394
|
71500
|
71501
|
71502
|
71503
|
71504
|
71505
|
71506
|
71507
|
71508
|
71509
|
71510
|
71511
|
71512
|
71513
|
71514
|
71515
|
71516
|
71517
|
71518
|
71519
|
71520
|
71521
|
71522
|
71523
|
71524
|
71525
|
71526
|
71527
|
71528
|
71529
|
71530
|
71767