Bugzilla – Attachment 62031 Details for
Bug 18403
Hide patron information if not part of the logged in user library group
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18403: Article requests
Bug-18403-Article-requests.patch (text/plain), 5.89 KB, created by
Jonathan Druart
on 2017-04-10 21:33:54 UTC
(
hide
)
Description:
Bug 18403: Article requests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-04-10 21:33:54 UTC
Size:
5.89 KB
patch
obsolete
>From eff4537ed251d8d08359ff64d6bdff1973e22dc4 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 7 Apr 2017 17:53:35 -0300 >Subject: [PATCH] Bug 18403: Article requests > >Same as previously but for article requests. > >Test plan: >Test article requests and make sure you do not need the requests for >patrons that >are attached to a group that is not part of your library's group >--- > Koha/ArticleRequests.pm | 39 +++++++++++++++++++++++++++++++-------- > t/db_dependent/ArticleRequests.t | 33 ++++++++++++++++++++++++++++++++- > 2 files changed, 63 insertions(+), 9 deletions(-) > >diff --git a/Koha/ArticleRequests.pm b/Koha/ArticleRequests.pm >index bc47789..27be468 100644 >--- a/Koha/ArticleRequests.pm >+++ b/Koha/ArticleRequests.pm >@@ -38,6 +38,29 @@ Koha::ArticleRequests - Koha ArticleRequests Object class > > =cut > >+=head3 search_limited >+ >+my $article_requests = Koha::ArticleRequests->search_limited( $params, $attributes ); >+ >+Search for article requests according to logged in patron restrictions >+ >+=cut >+ >+sub search_limited { >+ my ( $self, $params, $attributes ) = @_; >+ >+ my $userenv = C4::Context->userenv; >+ my @restricted_branchcodes; >+ if ( $userenv ) { >+ my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); >+ @restricted_branchcodes = $logged_in_user->libraries_where_can_see_patrons; >+ } >+ # TODO This 'borrowernumber' relation name is confusing and needs to be renamed >+ $params->{'borrowernumber.branchcode'} = { -in => \@restricted_branchcodes } if @restricted_branchcodes; >+ $attributes->{join} = 'borrowernumber'; >+ return $self->search( $params, $attributes ); >+} >+ > =head3 pending > > =cut >@@ -45,8 +68,8 @@ Koha::ArticleRequests - Koha ArticleRequests Object class > sub pending { > my ( $self, $branchcode ) = @_; > my $params = { status => Koha::ArticleRequest::Status::Pending }; >- $params->{branchcode} = $branchcode if $branchcode; >- return Koha::ArticleRequests->search( $params ); >+ $params->{'me.branchcode'} = $branchcode if $branchcode; >+ return Koha::ArticleRequests->search_limited( $params ); > } > > =head3 processing >@@ -56,8 +79,8 @@ sub pending { > sub processing { > my ( $self, $branchcode ) = @_; > my $params = { status => Koha::ArticleRequest::Status::Processing }; >- $params->{branchcode} = $branchcode if $branchcode; >- return Koha::ArticleRequests->search( $params ); >+ $params->{'me.branchcode'} = $branchcode if $branchcode; >+ return Koha::ArticleRequests->search_limited( $params ); > } > > =head3 completed >@@ -67,8 +90,8 @@ sub processing { > sub completed { > my ( $self, $branchcode ) = @_; > my $params = { status => Koha::ArticleRequest::Status::Completed }; >- $params->{branchcode} = $branchcode if $branchcode; >- return Koha::ArticleRequests->search( $params ); >+ $params->{'me.branchcode'} = $branchcode if $branchcode; >+ return Koha::ArticleRequests->search_limited( $params ); > } > > =head3 canceled >@@ -78,8 +101,8 @@ sub completed { > sub canceled { > my ( $self, $branchcode ) = @_; > my $params = { status => Koha::ArticleRequest::Status::Canceled }; >- $params->{branchcode} = $branchcode if $branchcode; >- return Koha::ArticleRequests->search( $params ); >+ $params->{'me.branchcode'} = $branchcode if $branchcode; >+ return Koha::ArticleRequests->search_limited( $params ); > } > > =head3 _type >diff --git a/t/db_dependent/ArticleRequests.t b/t/db_dependent/ArticleRequests.t >index af9e1c8..951d2b6 100755 >--- a/t/db_dependent/ArticleRequests.t >+++ b/t/db_dependent/ArticleRequests.t >@@ -19,13 +19,15 @@ use Modern::Perl; > > use POSIX qw(strftime); > >-use Test::More tests => 49; >+use Test::More tests => 50; > use Koha::Database; > > use Koha::Biblio; > use Koha::Patron; > use Koha::Library; > >+use t::lib::TestBuilder; >+ > BEGIN { > use_ok('Koha::ArticleRequest'); > use_ok('Koha::ArticleRequests'); >@@ -35,6 +37,7 @@ BEGIN { > my $schema = Koha::Database->new()->schema(); > $schema->storage->txn_begin(); > >+my $builder = t::lib::TestBuilder->new; > my $dbh = C4::Context->dbh; > $dbh->{RaiseError} = 1; > >@@ -65,9 +68,14 @@ my $patron = Koha::Patron->new( > { > categorycode => $category->id, > branchcode => $branch->id, >+ flags => 1,# superlibrarian > } > )->store(); > ok( $patron->id, 'Koha::Patron created' ); >+my $patron_2 = $builder->build({ source => 'Borrower' }); >+$patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); >+ >+my $nb_article_requests = Koha::ArticleRequests->count; > > my $article_request = Koha::ArticleRequest->new( > { >@@ -173,4 +181,27 @@ ok( !$item->can_article_request($patron), 'Item is not requestable with rule t > is( $item->article_request_type($patron), 'no', 'Item article request type is no' ); > $rule->delete(); > >+subtest 'search_limited' => sub { >+ plan tests => 2; >+ C4::Context->_new_userenv('xxx'); >+ my $group_1 = Koha::Library::Group->new( { title => 'TEST Group 1' } )->store; >+ my $group_2 = Koha::Library::Group->new( { title => 'TEST Group 2' } )->store; >+ Koha::Library::Group->new({ parent_id => $group_1->id, branchcode => $patron->branchcode })->store(); >+ Koha::Library::Group->new({ parent_id => $group_2->id, branchcode => $patron_2->branchcode })->store(); >+ set_logged_in_user( $patron ); # Is superlibrarian >+ is( Koha::ArticleRequests->count, 3, 'Koha::ArticleRequests should return all article requests' ); >+ is( Koha::ArticleRequests->search_limited->count, 2, 'Koha::ArticleRequests->search_limited should return reviews depending on patron permissions' ); >+}; >+ > $schema->storage->txn_rollback(); >+ >+sub set_logged_in_user { >+ my ($patron) = @_; >+ C4::Context->set_userenv( >+ $patron->borrowernumber, $patron->userid, >+ $patron->cardnumber, 'firstname', >+ 'surname', $patron->library->branchcode, >+ 'Midway Public Library', $patron->flags, >+ '', '' >+ ); >+} >-- >2.9.3
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 18403
:
62010
|
62011
|
62012
|
62013
|
62014
|
62015
|
62016
|
62017
|
62018
|
62019
|
62020
|
62021
|
62022
|
62023
|
62024
|
62025
|
62026
|
62027
|
62028
|
62029
|
62030
|
62031
|
62032
|
62033
|
62302
|
62303
|
62830
|
62831
|
62832
|
62833
|
62834
|
62835
|
62836
|
62837
|
62838
|
62839
|
62840
|
62841
|
62842
|
62843
|
62844
|
62845
|
62846
|
62847
|
62848
|
62849
|
62850
|
62851
|
62852
|
62853
|
62854
|
62855
|
71392
|
71394
|
71500
|
71501
|
71502
|
71503
|
71504
|
71505
|
71506
|
71507
|
71508
|
71509
|
71510
|
71511
|
71512
|
71513
|
71514
|
71515
|
71516
|
71517
|
71518
|
71519
|
71520
|
71521
|
71522
|
71523
|
71524
|
71525
|
71526
|
71527
|
71528
|
71529
|
71530
|
71767