From e09ed656af5f75a82ccfa29318081e217618c32d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Apr 2017 14:11:02 -0300 Subject: [PATCH] Bug 18403: Only display libraries from group in dropdown lists From where patrons it's about patrons, we do not want to display the libraries from all the system, but only the ones from the group. Test plan: - See the overdues (circ/overdue.pl) and make sure you can only see overdues from patrons part of your group (do not forget to test the CSV export). - Search for patrons, the 'library' filters (headers and left side) should only display libraries from your group - Search for article request by patron's library: only the libraries from your group should be displayed Signed-off-by: Signed-off-by: Jon McGowan Signed-off-by: Jonathan Druart --- Koha/Libraries.pm | 29 +++++++++++++++++-- Koha/Template/Plugin/Branches.pm | 3 +- circ/overdue.pl | 12 ++++++-- .../prog/en/includes/patron-search.inc | 2 +- .../prog/en/modules/circ/article-requests.tt | 2 +- .../prog/en/modules/circ/overdue.tt | 11 ++++--- .../prog/en/modules/circ/view_holdsqueue.tt | 2 +- .../prog/en/modules/common/patron_search.tt | 2 +- .../prog/en/modules/members/member.tt | 2 +- .../prog/en/modules/members/memberentrygen.tt | 2 +- 10 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Koha/Libraries.pm b/Koha/Libraries.pm index fa2bf17b04..927368e6a4 100644 --- a/Koha/Libraries.pm +++ b/Koha/Libraries.pm @@ -45,10 +45,35 @@ Koha::Libraries - Koha Library Object set class sub search_filtered { my ( $self, $params, $attributes ) = @_; - if ( C4::Context::only_my_library ) { - $params->{branchcode} = C4::Context->userenv->{branch}; + my @branchcodes; + if ( my $userenv = C4::Context->userenv ) { + if ( C4::Context::only_my_library ) { + push @branchcodes, $userenv->{branch}; + } + else { + my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); + unless ( + $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 @branchcodes, + $library_group->parent->children->get_column('branchcode'); + } + } + else { + push @branchcodes, $userenv->{branch}; + } + } + } } + $params->{branchcode} = { -in => \@branchcodes } if @branchcodes; + delete $params->{only_from_group}; return $self->SUPER::search( $params, $attributes ); } diff --git a/Koha/Template/Plugin/Branches.pm b/Koha/Template/Plugin/Branches.pm index 8c4bb14d74..18c53ded81 100644 --- a/Koha/Template/Plugin/Branches.pm +++ b/Koha/Template/Plugin/Branches.pm @@ -59,10 +59,11 @@ sub all { my ( $self, $params ) = @_; my $selected = $params->{selected}; my $unfiltered = $params->{unfiltered} || 0; + my $only_from_group = $params->{only_from_group} || 0; my $libraries = $unfiltered ? Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed - : Koha::Libraries->search_filtered( {}, { order_by => ['branchname'] } )->unblessed; + : Koha::Libraries->search_filtered( { only_from_group => $only_from_group }, { order_by => ['branchname'] } )->unblessed; for my $l ( @$libraries ) { if ( defined $selected and $l->{branchcode} eq $selected diff --git a/circ/overdue.pl b/circ/overdue.pl index eea9e05dca..ff65712d2a 100755 --- a/circ/overdue.pl +++ b/circ/overdue.pl @@ -63,6 +63,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); +our $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; + my $dbh = C4::Context->dbh; my $req; @@ -296,6 +298,7 @@ if ($noreport) { } push @overduedata, { + patron => scalar Koha::Patrons->find( $data->{borrowernumber} ), duedate => $data->{date_due}, borrowernumber => $data->{borrowernumber}, barcode => $data->{barcode}, @@ -369,14 +372,19 @@ sub build_csv { my @lines = (); # build header ... - my @keys = qw /duedate title author borrowertitle firstname surname phone barcode email address address2 zipcode city country - branchcode itemcallnumber biblionumber borrowernumber itemnum issuedate replacementprice streetnumber streettype/; + my @keys = + qw ( duedate title author borrowertitle firstname surname phone barcode email address address2 zipcode city country + branchcode itemcallnumber biblionumber borrowernumber itemnum issuedate replacementprice streetnumber streettype); my $csv = Text::CSV_XS->new(); $csv->combine(@keys); push @lines, $csv->string(); + my @private_keys = qw( dueborrowertitle firstname surname phone email address address2 zipcode city country streetnumber streettype ); # ... and rest of report foreach my $overdue ( @{ $overdues } ) { + unless ( $logged_in_user->can_see_patron_infos( $overdue->{patron} ) ) { + $overdue->{$_} = undef for @private_keys; + } push @lines, $csv->string() if $csv->combine(map { $overdue->{$_} } @keys); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index a10fc2fb7e..4fbb927dd9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -85,7 +85,7 @@

- [% SET branches = Branches.all( selected => branchcode_filter ) %] + [% SET branches = Branches.all( selected => branchcode_filter, only_my_group => 1 ) %] - [% FOREACH b IN Branches.all %] + [% FOREACH b IN Branches.all( only_from_group => 1 ) %] [% IF b.branchcode == branchcode %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt index f170689233..eaf0472a9e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt @@ -58,9 +58,12 @@ [% FOREACH overdueloo IN overdueloop %] [% overdueloo.duedate | $KohaDates %] - [% overdueloo.surname %][% IF (overdueloo.firstname) %], [% overdueloo.firstname %][% END %] ([% overdueloo.cardnumber %]) - [% IF ( overdueloo.email ) %][email][% END %] - [% IF ( overdueloo.phone ) %]([% overdueloo.phone %])[% ELSIF ( overdueloo.mobile ) %]([% overdueloo.mobile %])[% ELSIF ( overdueloo.phonepro ) %]([% overdueloo.phonepro %])[% END %] + + [% INCLUDE 'patron-title.inc' patron=overdueloo.patron hide_patron_infos_if_needed=1 link_to="circulation_reserves" %] + [% IF logged_in_user.can_see_patron_infos( overdueloo.patron ) %] + [% IF ( overdueloo.email ) %][email][% END %] + [% IF ( overdueloo.phone ) %]([% overdueloo.phone %])[% ELSIF ( overdueloo.mobile ) %]([% overdueloo.mobile %])[% ELSIF ( overdueloo.phonepro ) %]([% overdueloo.phonepro %])[% END %] + [% END %] [% IF overdueloo.branchcode %][% Branches.GetName( overdueloo.branchcode ) %][% END %] [% INCLUDE 'biblio-default-view.inc' biblionumber = overdueloo.biblionumber %][% overdueloo.title |html %] [% overdueloo.subtitle %] [% IF ( overdueloo.author ) %], by [% overdueloo.author %][% END %][% IF ( overdueloo.enumchron ) %], [% overdueloo.enumchron %][% END %] [% overdueloo.barcode %] @@ -174,7 +177,7 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt index 19353eff75..03ee94d00f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt @@ -175,7 +175,7 @@ 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 d5001a8bfb..341d32bf1e 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 @@ -195,7 +195,7 @@ function filterByFirstLetterSurname(letter) {

  • [% IF branches.size != 1 %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 4980fbaa16..0957468c7e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -679,7 +679,7 @@ $(document).ready(function() {
  • Required
  • -- 2.39.5