From 1a737dcee6f600fc9d853f7318e1591b75b1349b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 5 Dec 2013 07:35:00 -0500 Subject: [PATCH] Bug 6254: make it possible to set default privacy setting for new patrons There is currently no way to set the privacy setting for newly created patrons. This patch adds a new field "default privacy" to the patron categories such that each patron category may have a different default privacy setting. Test Plan: 1) Apply this patch 2) Edit a patron category, change the default privacy to "forever" 3) Create a new patron of that category 4) Log into the catalog as that patron, verify the privacy setting is set to "forever" 5) Repeat steps 2-4 with the settings "never" and "default" Signed-off-by: Joel Sasse Signed-off-by: Jonathan Druart Bug 6254 [QA Followup 1] - can't set patron privacy by default * Adds default privacy column to summary table * Adds default privacy to delete category summary * Adds "AFTER categorycode" to the database update * Whitespace cleanup and formatting for affected code blocks * Switch basic DBI queries to DBIx::Class to simplify code * Adds reference to misc/cronjobs/batch_anonymise.pl to description Signed-off-by: Jonathan Druart Bug 6254 [QA Followup 2] - can't set patron privacy by default Signed-off-by: Jonathan Druart Bug 6254: QA FIX: remove trailing whitespaces This patch removes trailing whitespaces/tab and fix the fields order in the updatedb entry (according to the kohastructure.pl). Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton --- C4/Members.pm | 10 +++ admin/categorie.pl | 89 ++++++++----------- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 ++ .../prog/en/modules/admin/categorie.tt | 66 +++++++++++--- .../en/modules/admin/patron-attr-types.tt | 2 +- 6 files changed, 112 insertions(+), 63 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index f8324951ed..61eb2d9346 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -41,6 +41,7 @@ use Koha::DateUtils; use Koha::Borrower::Debarments qw(IsDebarred); use Text::Unaccent qw( unac_string ); use Koha::AuthUtils qw(hash_password); +use Koha::Database; our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); @@ -836,6 +837,15 @@ sub AddMember { $data{'dateenrolled'} = C4::Dates->new()->output("iso"); } + my $patron_category = + Koha::Database->new()->schema()->resultset('Category') + ->find( $data{'categorycode'} ); + $data{'privacy'} = + $patron_category->default_privacy() eq 'default' ? 1 + : $patron_category->default_privacy() eq 'never' ? 2 + : $patron_category->default_privacy() eq 'forever' ? 0 + : undef; + # create a disabled account if no password provided $data{'password'} = ($data{'password'})? hash_password($data{'password'}) : '!'; $data{'borrowernumber'}=InsertInTable("borrowers",\%data); diff --git a/admin/categorie.pl b/admin/categorie.pl index e2ea4c6f71..ebb91e7085 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -45,6 +45,7 @@ use C4::Branch; use C4::Output; use C4::Dates; use C4::Form::MessagingPreferences; +use Koha::Database; sub StringSearch { my ($searchstring,$type)=@_; @@ -125,23 +126,28 @@ if ($op eq 'add_form') { }; } - $template->param(description => $data->{'description'}, - enrolmentperiod => $data->{'enrolmentperiod'}, - enrolmentperioddate => $data->{'enrolmentperioddate'}, - upperagelimit => $data->{'upperagelimit'}, - dateofbirthrequired => $data->{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'} || 0), - overduenoticerequired => $data->{'overduenoticerequired'}, - issuelimit => $data->{'issuelimit'}, - reservefee => sprintf("%.2f",$data->{'reservefee'} || 0), - hidelostitems => $data->{'hidelostitems'}, - category_type => $data->{'category_type'}, - SMSSendDriver => C4::Context->preference("SMSSendDriver"), - TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"), - "type_".$data->{'category_type'} => 1, - branches_loop => \@branches_loop, - BlockExpiredPatronOpacActions => $data->{'BlockExpiredPatronOpacActions'}, - ); + $template->param( + description => $data->{'description'}, + enrolmentperiod => $data->{'enrolmentperiod'}, + enrolmentperioddate => $data->{'enrolmentperioddate'}, + upperagelimit => $data->{'upperagelimit'}, + dateofbirthrequired => $data->{'dateofbirthrequired'}, + enrolmentfee => sprintf( "%.2f", $data->{'enrolmentfee'} || 0 ), + overduenoticerequired => $data->{'overduenoticerequired'}, + issuelimit => $data->{'issuelimit'}, + reservefee => sprintf( "%.2f", $data->{'reservefee'} || 0 ), + hidelostitems => $data->{'hidelostitems'}, + category_type => $data->{'category_type'}, + SMSSendDriver => C4::Context->preference("SMSSendDriver"), + TalkingTechItivaPhone => + C4::Context->preference("TalkingTechItivaPhoneNotification"), + "type_" . $data->{'category_type'} => 1, + branches_loop => \@branches_loop, + BlockExpiredPatronOpacActions => + $data->{'BlockExpiredPatronOpacActions'}, + default_privacy => $data->{'default_privacy'}, + ); + if (C4::Context->preference('EnhancedMessagingPreferences')) { C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template); } @@ -169,7 +175,8 @@ if ($op eq 'add_form') { hidelostitems=?, overduenoticerequired=?, category_type=?, - BlockExpiredPatronOpacActions=? + BlockExpiredPatronOpacActions=?, + default_privacy=? WHERE categorycode=?" ); $sth->execute( @@ -185,6 +192,7 @@ if ($op eq 'add_form') { 'overduenoticerequired', 'category_type', 'block_expired', + 'default_privacy', 'categorycode' ) ); @@ -219,7 +227,8 @@ if ($op eq 'add_form') { hidelostitems, overduenoticerequired, category_type, - BlockExpiredPatronOpacActions + BlockExpiredPatronOpacActions, + default_privacy ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"); $sth->execute( @@ -235,7 +244,8 @@ if ($op eq 'add_form') { 'hidelostitems', 'overduenoticerequired', 'category_type', - 'block_expired' + 'block_expired', + 'default_privacy', ) ); $sth->finish; @@ -252,40 +262,14 @@ if ($op eq 'add_form') { ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { + my $schema = Koha::Database->new()->schema(); $template->param(delete_confirm => 1); - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select count(*) as total from borrowers where categorycode=?"); - $sth->execute($categorycode); - my $total = $sth->fetchrow_hashref; - $sth->finish; - $template->param(total => $total->{'total'}); - - my $sth2=$dbh->prepare("SELECT * FROM categories WHERE categorycode=?"); - $sth2->execute($categorycode); - my $data=$sth2->fetchrow_hashref; - $sth2->finish; - if ($total->{'total'} >0) { - $template->param(totalgtzero => 1); - } - - if ($data->{'enrolmentperioddate'} && $data->{'enrolmentperioddate'} eq '0000-00-00') { - $data->{'enrolmentperioddate'} = undef; - } - $template->param( description => $data->{'description'}, - enrolmentperiod => $data->{'enrolmentperiod'}, - enrolmentperioddate => $data->{'enrolmentperioddate'}, - upperagelimit => $data->{'upperagelimit'}, - dateofbirthrequired => $data->{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'} || 0), - overduenoticerequired => $data->{'overduenoticerequired'}, - issuelimit => $data->{'issuelimit'}, - reservefee => sprintf("%.2f",$data->{'reservefee'} || 0), - hidelostitems => $data->{'hidelostitems'}, - category_type => $data->{'category_type'}, - BlockExpiredPatronOpacActions => $data->{'BlockExpiredPatronOpacActions'}, - ); - # END $OP eq DELETE_CONFIRM + my $count = $schema->resultset('Borrower')->search( { categorycode => $categorycode } )->count(); + my $category = $schema->resultset('Category')->find($categorycode); + $category->enrolmentperioddate( C4::Dates::format_date( $category->enrolmentperioddate() ) ); + $template->param( category => $category, patrons_in_category => $count ); +# END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ($op eq 'delete_confirmed') { @@ -329,6 +313,7 @@ if ($op eq 'add_form') { reservefee => sprintf("%.2f",$results->[$i]{'reservefee'} || 0), hidelostitems => $results->[$i]{'hidelostitems'}, category_type => $results->[$i]{'category_type'}, + default_privacy => $results->[$i]{'default_privacy'}, "type_".$results->[$i]{'category_type'} => 1, branches => \@selected_branches, ); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 8111305046..a2d1800640 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -467,6 +467,7 @@ CREATE TABLE `categories` ( -- this table shows information related to Koha patr `hidelostitems` tinyint(1) NOT NULL default '0', -- are lost items shown to this category (1 for yes, 0 for no) `category_type` varchar(1) NOT NULL default 'A', -- type of Koha patron (Adult, Child, Professional, Organizational, Statistical, Staff) `BlockExpiredPatronOpacActions` tinyint(1) NOT NULL default '-1', -- wheither or not a patron of this category can renew books or place holds once their card has expired. 0 means they can, 1 means they cannot, -1 means use syspref BlockExpiredPatronOpacActions + `default_privacy` ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default', -- Default privacy setting for this patron category PRIMARY KEY (`categorycode`), UNIQUE KEY `categorycode` (`categorycode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 1f1c67280a..93d3f0e1da 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8519,6 +8519,13 @@ if (CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.15.00.XXX"; +if(CheckVersion($DBversion)) { + $dbh->do("ALTER TABLE categories ADD default_privacy ENUM( 'default', 'never', 'forever' ) NOT NULL DEFAULT 'default' AFTER category_type"); + print "Upgrade to $DBversion done (Bug 6254 - can't set patron privacy by default)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt index 6a64c01b7b..263cc8b4f9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt @@ -2,7 +2,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Patron categories › [% IF ( add_form ) %][% IF ( categorycode ) %]Modify category '[% categorycode |html %]'[% ELSE %]New category[% END %][% END %] [% IF ( add_validate ) %]Data recorded[% END %] -[% IF ( delete_confirm ) %][% IF ( totalgtzero ) %]Cannot delete: category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %] +[% IF ( delete_confirm ) %][% IF ( patrons_in_category > 0 ) %]Cannot delete: category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %] [% IF ( delete_confirmed ) %]Category deleted[% END %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'calendar.inc' %] @@ -99,7 +99,7 @@ @@ -186,7 +186,7 @@ [% END %] [% END %] - Select All if this category type must to be displayed all the time. Otherwise select librairies you want to associate with this value. + Select All branches if this category type must to be displayed all the time. Otherwise select libraries you want to associate with this value.
  • @@ -213,6 +213,26 @@ Choose whether patrons of this category be blocked from public catalog actions such as renewing and placing holds when their cards have expired.
  • +
  • + + + Controls how long a patrons checkout history is kept for new patrons of this category. "Never" anonymizes checkouts on return, and "Forever" keeps a patron's checkout history indefinitely. When set to "Default", the amount of history kept is controlled by the cronjob batch_anonymise.pl which should be set up by your system administrator. +
  • @@ -232,16 +252,18 @@
    - [% END %] [% IF ( delete_confirm ) %] - -
    -
    - [% IF ( totalgtzero ) %] - Category [% categorycode |html %] is in use. Deletion not possible![% ELSE %] -Confirm deletion of category [% categorycode |html %][% END %] + +
    + + [% IF ( patrons_in_category > 0 ) %] + Category [% categorycode |html %] is in use. Deletion not possible! + [% ELSE %] + Confirm deletion of category [% categorycode |html %] + [% END %] + [% IF ( totalgtzero ) %]
    This category is used [% total %] times. Deletion not possible
    [% END %] @@ -262,6 +284,19 @@ Confirm deletion of category [% categorycode |html %][% END %] + + + +
    Receives overdue notices: [% IF ( overduenoticerequired ) %]Yes[% ELSE %]No[% END %]
    Lost items in staff client[% IF ( hidelostitems ) %]Hidden by default[% ELSE %]Shown[% END %]
    Hold fee: [% reservefee %]
    Default privacy: + [% SWITCH category.default_privacy %] + [% CASE 'default' %] + Default + [% CASE 'never' %] + Never + [% CASE 'forever' %] + Forever + [% END %] +
    [% IF ( totalgtzero ) %] @@ -309,6 +344,7 @@ Confirm deletion of category [% categorycode |html %][% END %] Messaging [% END %] Branches limitations + Default privacy     @@ -382,6 +418,16 @@ Confirm deletion of category [% categorycode |html %][% END %] No limitation [% END %] + + [% SWITCH loo.default_privacy %] + [% CASE 'default' %] + Default + [% CASE 'never' %] + Never + [% CASE 'forever' %] + Forever + [% END %] + Edit Delete diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt index e561ae55ed..2fb8a68787 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt @@ -202,7 +202,7 @@ function CheckAttributeTypeForm(f) { [% END %] [% END %] - Select All if this attribute type must to be displayed all the time. Otherwise select librairies you want to associate with this value. + Select All if this attribute type must to be displayed all the time. Otherwise select libraries you want to associate with this value.
  • -- 2.20.1