Bugzilla – Attachment 21148 Details for
Bug 10502
Add independent branches option for sql reports
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10502 - Add independent branches option for sql reports
Bug-10502---Add-independent-branches-option-for-sq.patch (text/plain), 8.45 KB, created by
Kyle M Hall (khall)
on 2013-09-17 16:58:42 UTC
(
hide
)
Description:
Bug 10502 - Add independent branches option for sql reports
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-09-17 16:58:42 UTC
Size:
8.45 KB
patch
obsolete
>From f0386cf5291508412fe9a6a9036f2b0cb9834611 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 24 Jun 2013 10:11:45 -0400 >Subject: [PATCH] Bug 10502 - Add independent branches option for sql reports > >This patch adds the ability to hide reports created by other libraries >based on the new IndependentBranchesReports system preference. This is >accomplished by adding a branchcode field to the sql reports, which is >set on report creation. > >Test Plan: >1) Apply this patch >2) Run updatedatabase.pl >3) Enable IndependentBranchesReports >4) Log in with a non-superlibrarian staff account >5) View existing sql reports, you should see no difference. Existing > reports are 'grandfathered' in, assuming that existing reports may be > used by multiple libraries or library groups. >6) Ensure you have selected a library to act as via the "set library" link. >7) Create a new sql report. >8) Verify it was created and you can view and edit it. >9) Change the logged in library to a difference branch. >10) Observe that the report is no longer visible in the reports list. >--- > C4/Reports/Guided.pm | 14 ++++++++++- > installer/data/mysql/kohastructure.sql | 1 + > installer/data/mysql/sysprefs.sql | 1 + > installer/data/mysql/updatedatabase.pl | 23 ++++++++++++++++++++ > .../prog/en/modules/admin/preferences/admin.pref | 7 ++++++ > reports/guided_reports.pl | 15 +++++++++++++ > 6 files changed, 59 insertions(+), 2 deletions(-) > >diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm >index 22a23dd..2b20de0 100644 >--- a/C4/Reports/Guided.pm >+++ b/C4/Reports/Guided.pm >@@ -534,10 +534,12 @@ sub save_report { > my $cache_expiry = $fields->{cache_expiry} || 300; > my $public = $fields->{public}; > >+ my $branchcode = ( C4::Context->userenv && C4::Context->userenv->{branch} ne 'NO_LIBRARY_SET' ) ? C4::Context->userenv->{branch} : undef; >+ > my $dbh = C4::Context->dbh(); > $sql =~ s/(\s*\;\s*)$//; # removes trailing whitespace and /;/ >- my $query = "INSERT INTO saved_sql (borrowernumber,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public) VALUES (?,now(),now(),?,?,?,?,?,?,?,?,?)"; >- $dbh->do($query, undef, $borrowernumber, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public); >+ my $query = "INSERT INTO saved_sql (borrowernumber,branchcode,date_created,last_modified,savedsql,report_name,report_area,report_group,report_subgroup,type,notes,cache_expiry,public) VALUES (?,?,now(),now(),?,?,?,?,?,?,?,?,?)"; >+ $dbh->do($query, undef, $borrowernumber, $branchcode, $sql, $name, $area, $group, $subgroup, $type, $notes, $cache_expiry, $public); > > my $id = $dbh->selectrow_array("SELECT max(id) FROM saved_sql WHERE borrowernumber=? AND report_name=?", undef, > $borrowernumber, $name); >@@ -669,6 +671,14 @@ sub get_saved_reports { > push @args, $filter->{subgroup}; > } > } >+ >+ if ( C4::Context->preference('IndependentBranchesReports') && !C4::Context->IsSuperLibrarian() ) { >+ my $branches = >+ C4::Branch::GetIndependentGroupModificationRights( { stringify => 1 } ); >+ >+ push( @cond, "( s.branchcode IN ( $branches ) OR s.branchcode IS NULL )" ); >+ } >+ > $query .= " WHERE ".join( " AND ", map "($_)", @cond ) if @cond; > $query .= " ORDER by date_created"; > >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 99675b1..bdd71ba 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1841,6 +1841,7 @@ DROP TABLE IF EXISTS `saved_sql`; > CREATE TABLE saved_sql ( -- saved sql reports > `id` int(11) NOT NULL auto_increment, -- unique id and primary key assigned by Koha > `borrowernumber` int(11) default NULL, -- the staff member who created this report (borrowers.borrowernumber) >+ `branchcode` VARCHAR(10) NULL DEFAULT NULL, -- the branchcode of the staff member who created this report > `date_created` datetime default NULL, -- the date this report was created > `last_modified` datetime default NULL, -- the date this report was last edited > `savedsql` text, -- the SQL for this report >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 4b9c492..8a5ebba 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -132,6 +132,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('ImageLimit','5','','Limit images stored in the database by the Patron Card image manager to this number.','Integer'), > ('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo'), > ('IndependentBranches','0',NULL,'If ON, increases security between libraries','YesNo'), >+('IndependentBranchesReports','0', NULL, 'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.','YesNo'), > ('InProcessingToShelvingCart','0','','If set, when any item with a location code of PROC is \'checked in\', it\'s location code will be changed to CART.','YesNo'), > ('INTRAdidyoumean',NULL,NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'), > ('IntranetBiblioDefaultView','normal','normal|marc|isbd|labeled_marc','Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd','Choice'), >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 0fff005..075e537 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7203,6 +7203,29 @@ if ( CheckVersion($DBversion) ) { > SetVersion ($DBversion); > } > >+$DBversion = "3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do(q{ >+ INSERT INTO systempreferences ( >+ variable, >+ value, >+ options, >+ explanation, >+ type >+ ) VALUES ( >+ 'IndependentBranchesReports', >+ '0', >+ 'If enabled, custom reports will only be visible to librarians of the same library or library group as the report creator.', >+ 'YesNo' >+ ); >+ }); >+ $dbh->do(q{ >+ ALTER TABLE saved_sql ADD branchcode VARCHAR( 10 ) NULL DEFAULT NULL AFTER borrowernumber; >+ }); >+ print "Upgrade to $DBversion done (Bug 10502 - Add independent branches option for sql reports)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >index 97376ed..4e26953 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >@@ -84,6 +84,13 @@ Administration: > yes: Prevent > no: "Don't prevent" > - the logged in library from editing bibliographic records of other libraries. The owning library is defined by the branchcode in biblio.branchcode which should be mapped to a MARC field ( e.g. 951$o ). >+ - >+ - pref: IndependentBranchesReports >+ default: 0 >+ choices: >+ yes: Prevent >+ no: "Don't prevent" >+ - staff (but not superlibrarians) from accessing reports created by other libraries. > CAS Authentication: > - > - pref: casAuthentication >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index b9c49ad..fe73458 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -140,6 +140,21 @@ elsif ( $phase eq 'Show SQL'){ > elsif ( $phase eq 'Edit SQL'){ > my $id = $input->param('reports'); > my $report = get_saved_report($id); >+ >+ if ( $report->{branchcode} >+ && C4::Context->preference('IndependentBranchesReports') >+ && !C4::Context->IsSuperLibrarian() ) >+ { >+ unless ( >+ C4::Branch::GetIndependentGroupModificationRights( >+ { for => $report->{branchcode} } >+ ) >+ ) >+ { >+ print $input->redirect("/cgi-bin/koha/reports/guided_reports.pl?phase=Use%20saved"); >+ } >+ } >+ > my $group = $report->{report_group}; > my $subgroup = $report->{report_subgroup}; > $template->param( >-- >1.7.2.5
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 10502
:
19217
|
20767
|
21148
|
23486
|
23492
|
23640