Bugzilla – Attachment 19217 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
0001-Bug-10502-Add-independent-branches-option-for-sql-re.patch (text/plain), 8.12 KB, created by
Kyle M Hall (khall)
on 2013-06-24 14:21:18 UTC
(
hide
)
Description:
Bug 10502 - Add independent branches option for sql reports
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-06-24 14:21:18 UTC
Size:
8.12 KB
patch
obsolete
>From 49a221d25553ad7bef51c2f497537d1ff5ee0c72 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 | 22 ++++++++++++++++++++ > .../prog/en/modules/admin/preferences/admin.pref | 7 ++++++ > reports/guided_reports.pl | 15 +++++++++++++ > 6 files changed, 58 insertions(+), 2 deletions(-) > >diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm >index f0db7a3..f5df245 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 96b5a36..2fe817f 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1837,6 +1837,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 fbd0387..5fb4608 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -427,3 +427,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' > INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo'); > INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo'); > INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); >+INSERT INTO systempreferences (variable,value,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'); >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 3708aa9..8c11db3 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7022,6 +7022,28 @@ CREATE TABLE IF NOT EXISTS borrower_files ( > SetVersion($DBversion); > } > >+$DBversion = "3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do(q{ >+ INSERT INTO systempreferences ( >+ variable, >+ value, >+ 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 1215ac1..bc90002 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 >@@ -70,6 +70,13 @@ Administration: > yes: Prevent > no: "Don't prevent" > - staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries. >+ - >+ - 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 929feea..ae52307 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -133,6 +133,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