Bug 6254: make it possible to set default privacy setting for new patrons
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 5 Dec 2013 12:35:00 +0000 (07:35 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 26 May 2014 01:17:37 +0000 (01:17 +0000)
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 <jsasse@plumcreeklibrary.net>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
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 <jonathan.druart@biblibre.com>
Bug 6254 [QA Followup 2] - can't set patron privacy by default

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
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 <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Members.pm
admin/categorie.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tt
koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt

index f832495..61eb2d9 100644 (file)
@@ -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);
index e2ea4c6..ebb91e7 100755 (executable)
@@ -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,
         );
index 8111305..a2d1800 100644 (file)
@@ -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;
index 1f1c672..93d3f0e 100755 (executable)
@@ -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)
index 6a64c01..263cc8b 100644 (file)
@@ -2,7 +2,7 @@
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Administration &rsaquo; Patron categories &rsaquo; [% 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 %]</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% INCLUDE 'calendar.inc' %]
@@ -99,7 +99,7 @@
 
 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; [% IF ( add_form ) %] <a href="/cgi-bin/koha/admin/categorie.pl">Patron categories</a> &rsaquo; [% IF ( categorycode ) %]Modify category '[% categorycode |html %]'[% ELSE %]New category[% END %][% END %]
 [% IF ( add_validate ) %] <a href="/cgi-bin/koha/admin/categorie.pl">Patron categories</a> &rsaquo; Data recorded[% END %]
-[% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/admin/categorie.pl">Patron categories</a> &rsaquo; [% IF ( totalgtzero ) %]Cannot delete: Category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %]
+[% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/admin/categorie.pl">Patron categories</a> &rsaquo; [% IF ( patrons_in_category > 0 ) %]Cannot delete: Category [% categorycode |html %] in use[% ELSE %]Confirm deletion of category '[% categorycode |html %]'[% END %][% END %]
 [% IF ( delete_confirmed ) %] <a href="/cgi-bin/koha/admin/categorie.pl">Patron categories</a> &rsaquo; Category deleted[% END %]
 [% IF ( else ) %]Patron categories[% END %]</div>
 
               [% END %]
             [% END %]
         </select>
-        <span>Select All if this category type must to be displayed all the time. Otherwise select librairies you want to associate with this value.
+        <span>Select <i>All branches</i> if this category type must to be displayed all the time. Otherwise select libraries you want to associate with this value.
         </span>
     </li>
     <li><label for="block_expired">Block expired patrons</label>
             Choose whether patrons of this category be blocked from public catalog actions such as renewing and placing holds when their cards have expired.   
         </span>
     </li>
+    <li>
+        <label for="default_privacy">Default privacy: </label>
+        <select id="default_privacy" name="default_privacy">
+            [% SWITCH default_privacy %]
+            [% CASE 'forever' %]
+                <option value="default">Default</option>
+                <option value="never">Never</option>
+                <option value="forever" selected="selected">Forever</option>
+            [% CASE 'never' %]
+                <option value="default">Default</option>
+                <option value="never" selected="selected">Never</option>
+                <option value="forever">Forever</option>
+            [% CASE %]
+                <option value="default" selected="selected">Default</option>
+                <option value="never">Never</option>
+                <option value="forever">Forever</option>
+            [% END %]
+        </select>
+        <span>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 <i>batch_anonymise.pl</i> which should be set up by your system administrator.</span>
+    </li>
     </ol>
 </fieldset>
 
        <form action="[% script_name %]" method="post">
                <input type="submit" value="OK" />
        </form>
-
 [% END %]
 
 [% IF ( delete_confirm ) %]
-       
-       <form action="[% script_name %]" method="post">
-       <fieldset><legend>      
-       [% IF ( totalgtzero ) %]
-       Category [% categorycode |html %] is in use.  Deletion not possible![% ELSE %]
-Confirm deletion of category [% categorycode |html %][% END %]</legend>
+    <form action="[% script_name %]" method="post">
+        <fieldset>
+            <legend>
+                [% IF ( patrons_in_category > 0 ) %]
+                    Category [% categorycode |html %] is in use.  Deletion not possible!
+                [% ELSE %]
+                    Confirm deletion of category [% categorycode |html %]
+                [% END %]
+            </legend>
 
 [% IF ( totalgtzero ) %]<div class="dialog alert"><strong>This category is used [% total %] times</strong>. Deletion not possible</div>[% END %]
        <table>
@@ -262,6 +284,19 @@ Confirm deletion of category [% categorycode |html %][% END %]</legend>
        <tr><th scope="row">Receives overdue notices: </th><td>[% IF ( overduenoticerequired ) %]Yes[% ELSE %]No[% END %]</td></tr>
        <tr><th scope="row">Lost items in staff client</th><td>[% IF ( hidelostitems ) %]Hidden by default[% ELSE %]Shown[% END %]</td></tr>
        <tr><th scope="row">Hold fee: </th><td>[% reservefee %]</td></tr>
+                <tr>
+                    <th scope="row">Default privacy: </th>
+                    <td>
+                        [% SWITCH category.default_privacy %]
+                        [% CASE 'default' %]
+                            Default
+                        [% CASE 'never' %]
+                            Never
+                        [% CASE 'forever' %]
+                            Forever
+                        [% END %]
+                    </td>
+                </tr>
 </table>
                <fieldset class="action">[% IF ( totalgtzero ) %]
 <input type="submit" value="OK" /></form>
@@ -309,6 +344,7 @@ Confirm deletion of category [% categorycode |html %][% END %]</legend>
             <th scope="col">Messaging</th>
             [% END %]
             <th scope="col">Branches limitations</th>
+            <th scope="col">Default privacy</th>
             <th scope="col">&nbsp; </th>
             <th scope="col">&nbsp; </th>
         </tr>
@@ -382,6 +418,16 @@ Confirm deletion of category [% categorycode |html %][% END %]</legend>
                                 No limitation
                             [% END %]
                         </td>
+                        <td>
+                            [% SWITCH loo.default_privacy %]
+                            [% CASE 'default' %]
+                                Default
+                            [% CASE 'never' %]
+                                Never
+                            [% CASE 'forever' %]
+                                Forever
+                            [% END %]
+                        </td>
                         <td><a href="[% loo.script_name %]?op=add_form&amp;categorycode=[% loo.categorycode |uri %]">Edit</a></td>
                         <td><a href="[% loo.script_name %]?op=delete_confirm&amp;categorycode=[% loo.categorycode |uri %]">Delete</a></td>
                </tr>
index e561ae5..2fb8a68 100644 (file)
@@ -202,7 +202,7 @@ function CheckAttributeTypeForm(f) {
                   [% END %]
                 [% END %]
             </select>
-            <span>Select All if this attribute type must to be displayed all the time. Otherwise select librairies you want to associate with this value.
+            <span>Select All if this attribute type must to be displayed all the time. Otherwise select libraries you want to associate with this value.
             </span>
         </li>
         <li>