Bug 25142: Fix wrong grep logical test
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 14 Apr 2020 11:22:44 +0000 (13:22 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 27 Apr 2020 09:44:49 +0000 (10:44 +0100)
To test and understand what's going on, you can try that bit of code:
my @a = qw( a b c a);
my @b = qw( b c d );
my @c;
@c = grep { 'a' eq $_ } @a ? 'ok' : ();
say @c;
@c = ( grep { 'a' eq $_ } @a ) ? 'ok' : ();
say @c;
@c = grep { 'a' eq $_ } @a ? ('ok') : (undef);
say @c;

The problem here:
Have patrons in 3 branches CPL, MPL, SPL
Have a non superlibrarian with edit_borrowers permission but
without view_borrower_infos_from_any_libraries, from CPL
Create a library group with CPL, MPL
Use that non superlibrarian to search for patrons
You can search for patrons fro CPL and MPL
BUT, edit the value for CPL, use SPL (edit the DOM)
Search and... oops

Apply this patch, try again

Also use a superlibrarian patron (and/or with view_borrower_infos_from_any_libraries)
and confirm that they can see all patrons

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Utils/DataTables/Members.pm

index 5bcd971..29efd0b 100644 (file)
@@ -57,7 +57,7 @@ sub search {
     # Do that after iTotalQuery!
     if ( defined $branchcode and $branchcode ) {
         @restricted_branchcodes = @restricted_branchcodes
-            ? grep { $_ eq $branchcode } @restricted_branchcodes
+            ? grep ({ $_ eq $branchcode } @restricted_branchcodes)
                 ? ($branchcode)
                 : (undef) # Do not return any results
             : ($branchcode);