From c74c21e0eb16f7d729d729b90755fc87c364094f Mon Sep 17 00:00:00 2001 From: ByWater Staff Date: Thu, 10 Apr 2014 10:15:35 -0400 Subject: [PATCH] Bug 12022 - Independent branches does not isolate pending and approved comments by branch. Given Branches A and B Branch A patron logs on to OPAC and leaves a comment for a title. Branch B staff is then able to see these comments in Home > Tools > Comments > Approved comments, in both the "Approved Comments" and "Comments awaiting moderation" tabs. Test Plan: 1) Create some comments for two libraries 2) Enable IndependentBranches 3) View the comments, not you see comments from both library's patrons 4) Apply the patch for bug 10276 5) Apply this patch 6) View the comments again, note you only see the comments for the patrons of the library you are logged in as. --- C4/Review.pm | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) diff --git a/C4/Review.pm b/C4/Review.pm index dd989ed..c851712 100644 --- a/C4/Review.pm +++ b/C4/Review.pm @@ -21,6 +21,7 @@ use strict; use warnings; use C4::Context; +use C4::Branch; use vars qw($VERSION @ISA @EXPORT); @@ -124,10 +125,31 @@ sub getreviews { sub getallreviews { my ($status, $offset, $row_count) = @_; - my @params = ($status,($offset ? $offset : 0),($row_count ? $row_count : 20)); + my @params; my $dbh = C4::Context->dbh; - my $query = - "SELECT * FROM reviews WHERE approved=? order by datereviewed desc LIMIT ?, ?"; + + my $query = " + SELECT reviews.* + FROM reviews + LEFT JOIN borrowers USING ( borrowernumber ) + WHERE approved=? order by datereviewed desc LIMIT ?, ? + "; + push( @params, $status ); + + if ( C4::Context->preference("IndependentBranches") ) { + unless ( C4::Context->IsSuperLibrarian() ) { + my @branches = GetIndependentGroupModificationRights(); + $query .= + " AND ( borrowers.branchcode IN ( " + . join( ',', ('?') x @branches ) + . " ) OR borrowers.branchcode = '')"; + push( @params, @branches ); + } + } + + $query .= " ORDER BY datereviewed desc LIMIT ?, ?"; + push( @params, ($offset ? $offset : 0),($row_count ? $row_count : 20) ); + my $sth = $dbh->prepare($query) || warn $dbh->err_str; $sth->execute(@params); return $sth->fetchall_arrayref({}); -- 1.7.2.5