From 9d52044f65a611d49cd8f78f7aeaef24a018e357 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 2 Feb 2018 14:23:42 -0300 Subject: [PATCH] Bug 20133: Enable/disable the "Hide patron information" feature per group of libraries In order to control this feature correctly it needs to be enabled for group of libraries and not for all groups defined in the system. Groups will be used for different usages and so the feature must not be enabled by default for all of them. Test plan: Retest bug 18403 with the feature turned on/off for a given tree Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 12 +++++++----- t/db_dependent/Koha/Patrons.t | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index b5506e4dab..c1951a5b3c 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -778,16 +778,18 @@ sub libraries_where_can_see_patrons { ) ) { - my $library_groups = $self->library->library_groups; + my $library_groups = $self->library->library_groups({ ft_hide_patron_info => 1 }); if ( $library_groups->count ) { while ( my $library_group = $library_groups->next ) { - push @restricted_branchcodes, $library_group->parent->children->get_column('branchcode'); + my $parent = $library_group->parent; + if ( $parent->has_child( $self->branchcode ) ) { + push @restricted_branchcodes, $parent->children->get_column('branchcode'); + } } } - else { - push @restricted_branchcodes, $self->branchcode; - } + + @restricted_branchcodes = ( $self->branchcode ) unless @restricted_branchcodes; } } diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index bd3d586395..2278b8ca87 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 23; +use Test::More tests => 24; use Test::Warn; use Time::Fake; use DateTime; @@ -947,8 +947,8 @@ subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited # + library_12 # group2 # + library21 - my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store; - my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store; + my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1', ft_hide_patron_info => 1 } )->store; + my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2', ft_hide_patron_info => 1 } )->store; my $library_11 = $builder->build( { source => 'Branch' } ); my $library_12 = $builder->build( { source => 'Branch' } ); my $library_21 = $builder->build( { source => 'Branch' } ); -- 2.20.1