Bugzilla – Attachment 157413 Details for
Bug 29523
Add a way to prevent embedding objects that should not be allowed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29523: Cache the restricted branches list
Bug-29523-Cache-the-restricted-branches-list.patch (text/plain), 4.98 KB, created by
Jonathan Druart
on 2023-10-19 09:57:56 UTC
(
hide
)
Description:
Bug 29523: Cache the restricted branches list
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-10-19 09:57:56 UTC
Size:
4.98 KB
patch
obsolete
>From 6ff023582983e590abf5c8be9748b0ee71bbfe77 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 3 Mar 2022 14:40:20 +0000 >Subject: [PATCH] Bug 29523: Cache the restricted branches list > >This patch introduces a very localised cache of the restricted branches >list in the logged in patron object. > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Patron.pm | 16 ++++++++-------- > t/db_dependent/Koha/Patrons.t | 5 +++++ > 2 files changed, 13 insertions(+), 8 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index d2f08a465ef..09c47d5366e 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1798,13 +1798,8 @@ sub can_see_things_from { > $can = 1; > } elsif ( $self->has_permission( { $permission => $subpermission } ) ) { > $can = 1; >- } elsif ( my $library_groups = $self->library->library_groups ) { >- while ( my $library_group = $library_groups->next ) { >- if ( $library_group->parent->has_child( $branchcode ) ) { >- $can = 1; >- last; >- } >- } >+ } elsif ( my @branches = $self->libraries_where_can_see_patrons ) { >+ $can = ( any { $_ eq $branchcode } @branches ) ? 1 : 0; > } > return $can; > } >@@ -1855,6 +1850,9 @@ sub libraries_where_can_see_things { > my $subpermission = $params->{subpermission}; > my $group_feature = $params->{group_feature}; > >+ return $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} >+ if exists( $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} ); >+ > my $userenv = C4::Context->userenv; > > return () unless $userenv; # For tests, but userenv should be defined in tests... >@@ -1888,7 +1886,9 @@ sub libraries_where_can_see_things { > @restricted_branchcodes = grep { defined $_ } @restricted_branchcodes; > @restricted_branchcodes = uniq(@restricted_branchcodes); > @restricted_branchcodes = sort(@restricted_branchcodes); >- return @restricted_branchcodes; >+ >+ $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} = \@restricted_branchcodes; >+ return @{ $self->{"_restricted_branchcodes:$permission:$subpermission:$group_feature"} }; > } > > =head3 has_permission >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 24d4f7a811f..5194f020ef6 100755 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -1350,11 +1350,13 @@ subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited > plan tests => 6; > > t::lib::Mocks::mock_userenv({ patron => $patron_11_1 }); >+ $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber ); > is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| ); > is( $patron_11_1->can_see_patron_infos( $patron_12 ), 1, q|patron_11_1 can see patron_12, from its group| ); > is( $patron_11_1->can_see_patron_infos( $patron_21 ), 1, q|patron_11_1 can see patron_11_2, from another group| ); > > t::lib::Mocks::mock_userenv({ patron => $patron_11_2 }); >+ $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber ); > is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| ); > is( $patron_11_2->can_see_patron_infos( $patron_12 ), 1, q|patron_11_2 can see patron_12, from its group| ); > is( $patron_11_2->can_see_patron_infos( $patron_21 ), 0, q|patron_11_2 can NOT see patron_21, from another group| ); >@@ -1363,15 +1365,18 @@ subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited > plan tests => 6; > > t::lib::Mocks::mock_userenv({ patron => $patron_11_1 }); >+ $patron_11_1 = Koha::Patrons->find( $patron_11_1->borrowernumber ); > my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests > is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' ); > is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' ); > > t::lib::Mocks::mock_userenv({ patron => $patron_11_2 }); >+ $patron_11_2 = Koha::Patrons->find( $patron_11_2->borrowernumber ); > is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); > is( Koha::Patrons->search_limited->count, 3, 'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12' ); > > t::lib::Mocks::mock_userenv({ patron => $patron_21 }); >+ $patron_21 = Koha::Patrons->find( $patron_21->borrowernumber ); > is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); > is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' ); > }; >-- >2.34.1
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 29523
:
127886
|
127887
|
127888
|
127889
|
127991
|
127992
|
127993
|
127994
|
128042
|
128043
|
128044
|
128045
|
128046
|
128047
|
128048
|
128688
|
128689
|
128690
|
128691
|
128692
|
128693
|
128694
|
131326
|
131331
|
131332
|
136684
|
136685
|
136686
|
136687
|
136688
|
136689
|
136690
|
136691
|
136692
|
136706
|
136714
|
148736
|
148737
|
148738
|
148739
|
148740
|
148741
|
148742
|
148743
|
148744
|
148745
|
150989
|
150990
|
150991
|
150992
|
150993
|
150994
|
150995
|
150996
|
150997
|
150998
|
156939
|
156940
|
156941
|
156942
|
156943
|
156944
|
156945
|
156946
|
156947
|
156948
|
156949
|
156965
|
157049
|
157071
|
157072
|
157073
|
157074
|
157075
|
157076
|
157077
|
157078
|
157079
|
157080
|
157081
|
157406
|
157407
|
157408
|
157409
|
157410
|
157411
|
157412
|
157413
|
157414
|
157415
|
157416
|
157673
|
157679
|
157683
|
157799
|
157881
|
157882
|
157883
|
157884
|
157885
|
157886
|
157887
|
157888
|
157889
|
157890
|
157891
|
157892
|
157893
|
158013