Bug 18403: Only display libraries from group in dropdown lists
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 5 Apr 2017 17:11:02 +0000 (14:11 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Feb 2018 18:41:38 +0000 (15:41 -0300)
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 <jon.mcgowan@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/Libraries.pm
Koha/Template/Plugin/Branches.pm
circ/overdue.pl
koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/overdue.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt

index fa2bf17..927368e 100644 (file)
@@ -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 );
 }
 
index 8c4bb14..18c53de 100644 (file)
@@ -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
index eea9e05..ff65712 100755 (executable)
@@ -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);
     }
 
index a10fc2f..4fbb927 100644 (file)
@@ -85,7 +85,7 @@
 
         <p>
             <label for="branchcode">Library: </label>
-            [% SET branches = Branches.all( selected => branchcode_filter ) %]
+            [% SET branches = Branches.all( selected => branchcode_filter, only_my_group => 1 ) %]
             <select name="branchcode_filter" id="branchcode">
                 [% IF branches.size != 1 %]
                   <option value="">Any</option>
index eefc912..da5d885 100644 (file)
@@ -31,7 +31,7 @@
                 <form id="ar-branchcode-form" method="post">
                     <select name="branchcode" id="branchcode">
                         <option value="">All libraries</option>
-                        [% FOREACH b IN Branches.all %]
+                        [% FOREACH b IN Branches.all( only_from_group => 1 ) %]
                             [% IF b.branchcode == branchcode %]
                                 <option value="[% b.branchcode %]" selected="selected">[% b.branchname %]</option>
                             [% ELSE %]
index f170689..eaf0472 100644 (file)
       [% FOREACH overdueloo IN overdueloop %]
         <tr>
           <td><span title="[% overdueloo.duedate %]">[% overdueloo.duedate | $KohaDates %]</span></td>
-          <td><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% overdueloo.borrowernumber %]">[% overdueloo.surname %][% IF (overdueloo.firstname) %], [% overdueloo.firstname %][% END %] ([% overdueloo.cardnumber %])</a>
-          [% IF ( overdueloo.email ) %][<a href="mailto:[% overdueloo.email %]?subject=[% INCLUDE subject %] [% overdueloo.title |html %]">email</a>][% END %]
-          [% IF ( overdueloo.phone ) %]([% overdueloo.phone %])[% ELSIF ( overdueloo.mobile ) %]([% overdueloo.mobile %])[% ELSIF ( overdueloo.phonepro ) %]([% overdueloo.phonepro %])[% END %]</td>
+          <td>
+            [% 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 ) %][<a href="mailto:[% overdueloo.email %]?subject=[% INCLUDE subject %] [% overdueloo.title |html %]">email</a>][% END %]
+                [% IF ( overdueloo.phone ) %]([% overdueloo.phone %])[% ELSIF ( overdueloo.mobile ) %]([% overdueloo.mobile %])[% ELSIF ( overdueloo.phonepro ) %]([% overdueloo.phonepro %])[% END %]</td>
+            [% END %]
           <td>[% IF overdueloo.branchcode %][% Branches.GetName( overdueloo.branchcode ) %][% END %]</td>
           <td>[% INCLUDE 'biblio-default-view.inc' biblionumber = overdueloo.biblionumber %][% overdueloo.title |html %]  [% overdueloo.subtitle %]</a> [% IF ( overdueloo.author ) %], by [% overdueloo.author %][% END %][% IF ( overdueloo.enumchron ) %], [% overdueloo.enumchron %][% END %]</td>
           <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% overdueloo.biblionumber %]&amp;itemnumber=[% overdueloo.itemnum %]#item[% overdueloo.itemnum %]">[% overdueloo.barcode %]</a></td>
         <label>Library of the patron:</label>
         <select name="branch" id="branch">
             <option value="">Any</option>
-            [% PROCESS options_for_libraries libraries => Branches.all( selected => branchfilter ) %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => branchfilter, only_from_group => 1 ) %]
         </select>
     </li>
 
index 19353ef..03ee94d 100644 (file)
             <label for="branchlimit">Library: </label>
             <select name="branchlimit" id="branchlimit">
                 <option value="">All</option>
-                [% PROCESS options_for_libraries libraries => Branches.all() %]
+                [% PROCESS options_for_libraries libraries => Branches.all( only_from_group => 1 ) %]
             </select>
         </li>
     </ol></fieldset>
index d5001a8..341d32b 100644 (file)
@@ -195,7 +195,7 @@ function filterByFirstLetterSurname(letter) {
                     <li>
                         <label for="branchcode_filter">Library:</label>
                         <select id="branchcode_filter">
-                            [% SET libraries = Branches.all() %]
+                            [% SET libraries = Branches.all( only_from_group => 1 ) %]
                             [% IF libraries.size != 1 %]
                                 <option value="">Any</option>
                             [% END %]
index babcfd7..eb84757 100644 (file)
@@ -506,7 +506,7 @@ function filterByFirstLetterSurname(letter) {
             </li>
             <li>
               <label for="branchcode_filter">Library:</label>
-              [% SET branches = Branches.all( selected => branchcode_filter ) %]
+              [% SET branches = Branches.all( selected => branchcode_filter, only_from_group => 1 ) %]
               <select id="branchcode_filter">
                 [% IF branches.size != 1 %]
                   <option value="">Any</option>
index 4980fba..0957468 100644 (file)
@@ -679,7 +679,7 @@ $(document).ready(function() {
     <li>
         <label for="libraries" class="required">Library:</label>
         <select name="branchcode" size="1" id="libraries">
-            [% PROCESS options_for_libraries libraries => Branches.all( selected => userbranch ) %]
+            [% PROCESS options_for_libraries libraries => Branches.all( selected => userbranch, only_from_group => 1 ) %]
         </select>
         <span class="required">Required</span>
     </li>