Bugzilla – Attachment 54785 Details for
Bug 12022
Independent branches does not isolate pending and approved comments by branch.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12022 - Independent branches does not isolate pending and approved comments by branch.
Bug-12022---Independent-branches-does-not-isolate-.patch (text/plain), 3.74 KB, created by
Kyle M Hall (khall)
on 2016-08-23 17:44:57 UTC
(
hide
)
Description:
Bug 12022 - Independent branches does not isolate pending and approved comments by branch.
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-08-23 17:44:57 UTC
Size:
3.74 KB
patch
obsolete
>From 8ef857af06e915fa88360dd5b6c9febc70ee1f3a Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 23 Aug 2016 17:42:44 +0000 >Subject: [PATCH] Bug 12022 - Independent branches does not isolate pending and > approved comments by branch. > >Test Plan: >1) Create some comments for two libraries >2) Log in as non-superlibrarian >3) Set the logged in library to one of those two libraries >4) View comments, not you only see the comments from patrons > whose home library matches the logged in library >5) Log in as a superlibrarian >6) Note you see all the comments reguardless of the patron's > home library >--- > C4/Review.pm | 19 +++++++++++++++++-- > t/db_dependent/Review.t | 40 +++++++++++++++++++++++++++++++++++++++- > 2 files changed, 56 insertions(+), 3 deletions(-) > >diff --git a/C4/Review.pm b/C4/Review.pm >index 5d56396..c35709b 100644 >--- a/C4/Review.pm >+++ b/C4/Review.pm >@@ -172,9 +172,24 @@ $offset position and the ($offset + $row_count) position. > > sub getallreviews { > my ( $status, $offset, $row_count ) = @_; >- my @params = ( $status, ( $offset ? $offset : 0 ), ( $row_count ? $row_count : 20 ) ); >+ my @params; >+ push( @params, $status ); >+ >+ my $library_limit = C4::Context->IsSuperLibrarian() ? q{} : q{ AND borrowers.branchcode = ?}; >+ push( @params, C4::Context->userenv->{'branch'} ) if ( $library_limit && C4::Context->userenv ); >+ >+ push( @params, $offset ? $offset : 0 ); >+ push( @params, $row_count ? $row_count : 20 ); >+ > my $dbh = C4::Context->dbh; >- my $query = "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; >+ my $query = qq{ >+ SELECT reviews.* FROM reviews >+ LEFT JOIN borrowers USING ( borrowernumber ) >+ WHERE approved = ? >+ $library_limit >+ ORDER BY datereviewed DESC >+ LIMIT ?, ? >+ }; > my $sth = $dbh->prepare($query); > $sth->execute(@params); > return $sth->fetchall_arrayref( {} ); >diff --git a/t/db_dependent/Review.t b/t/db_dependent/Review.t >index 248fe3e..0762973 100644 >--- a/t/db_dependent/Review.t >+++ b/t/db_dependent/Review.t >@@ -18,11 +18,12 @@ > > use Modern::Perl; > >-use Test::More tests => 117; >+use Test::More tests => 118; > use t::lib::TestBuilder; > > use Koha::Database; > use Time::Piece; >+use Test::MockModule; > > BEGIN { > use_ok('C4::Biblio'); >@@ -58,6 +59,19 @@ my $builder = t::lib::TestBuilder->new; > # ---------- Some borrowers for testing ------------------- > my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; > my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; >+my $branchcode2 = $builder->build({ source => 'Branch' })->{ branchcode }; >+ >+my $context = new Test::MockModule('C4::Context'); >+$context->mock( >+ 'userenv', >+ sub { >+ return { >+ flags => 0, >+ id => 'my_userid', >+ branch => $branchcode, >+ }; >+ } >+); > > my $b1 = Koha::Patron->new( > { surname => 'Borrower 1', >@@ -246,6 +260,30 @@ $reviews = getallreviews( $status, $offset, $row_count ); > is( @$reviews, 1, 'There is only 1 Review here' ); > is_deeply( $reviews->[0], $review2, 'We have only Review2' ); > >+$context->mock( >+ 'userenv', >+ sub { >+ return { >+ flags => 0, >+ id => 'my_userid', >+ branch => $branchcode2, >+ }; >+ } >+); >+my $no_reviews = getallreviews($status); >+is( @{$no_reviews}, 0, "No reviews returned for unused branchcode" ); >+$context->mock( >+ 'userenv', >+ sub { >+ return { >+ flags => 0, >+ id => 'my_userid', >+ branch => $branchcode, >+ }; >+ } >+); >+ >+ > # ---------- Testing numberofreviews ---------------------- > $status = 0; > $count = numberofreviews($status); >-- >2.1.4
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 12022
:
26979
|
26980
| 54785