From c367cd3ddbb9b7bacbc940afee4caaff65b0ee7f Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Mon, 14 Feb 2022 16:34:23 +0000
Subject: [PATCH] Bug 29926: Add ability for superlibrarians to batch edit
 password expiration dates

To test:
1 - Sign in as a superlibrarian
2 - Tools->Batch patron modification
3 - Add patrons with and without pasword expiration set
4 - Confirm dates display correctly on modification page, or show never
5 - Check the box to delete all dates
6 - Confirm patrons now show 'Never'
7 - Edit patrons again, set a date
8 - Confirm date is set correctly
9 - Sign in as a user with catalogue/tools/borrowers permissions, but not superlibrarian
10 - Confirm y9ou do not see, and cannnot edit password expiration dates

Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 .../prog/en/modules/tools/modborrowers.tt           | 13 +++++++++++++
 tools/modborrowers.pl                               | 10 ++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt
index 1a69521b97b..aae7fa29df1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt
@@ -221,6 +221,9 @@
                                                 <th>Mobile</th>
                                                 <th>Registration date</th>
                                                 <th>Expiry date</th>
+                                                [% IF CanUpdatePasswordExpiration %]
+                                                    <th>Password expiration date</th>
+                                                [% END %]
                                                 <th>Circulation note</th>
                                                 <th>OPAC note</th>
                                                 <th>Restriction expiration</th>
@@ -257,6 +260,15 @@
                                                     <td>[% borrower.mobile | html %]</td>
                                                     <td data-order="[% borrower.dateenrolled | html %]">[% borrower.dateenrolled | $KohaDates %]</td>
                                                     <td data-order="[% borrower.dateexpiry | html %]">[% borrower.dateexpiry | $KohaDates %]</td>
+                                                    [% IF CanUpdatePasswordExpiration %]
+                                                        [% IF borrower.password_expiration_date  %]
+                                                            <td data-order="[% borrower.password_expiration_date | html %]">
+                                                                [% borrower.password_expiration_date | $KohaDates %]
+                                                            </td>
+                                                        [% ELSE %]
+                                                            <td data-order="9999-99-99">Never</td>
+                                                        [% END %]
+                                                    [% END %]
                                                     <td>[% borrower.borrowernotes | html %]</td>
                                                     <td>[% borrower.opacnote | html %]</td>
                                                     <td data-order="[% borrower.debarred | html %]">[% borrower.debarred | $KohaDates %]</td>
@@ -312,6 +324,7 @@
                                                 [% CASE 'opacnote' %]<span>OPAC note:</span>
                                                 [% CASE 'debarred' %]<span>Restriction expiration:</span>
                                                 [% CASE 'debarredcomment' %]<span>Restriction comment:</span>
+                                                [% CASE 'password_expiration_date' %]<span>Password expiration date:</span>
                                             [% END %]
                                             </label>
                                             [% IF ( field.type == 'text' ) %]
diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl
index 8aed3f4b4b4..bb35b8e1c03 100755
--- a/tools/modborrowers.pl
+++ b/tools/modborrowers.pl
@@ -51,6 +51,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
 
+$template->param( CanUpdatePasswordExpiration => 1 ) if $logged_in_user->is_superlibrarian;
+
 my $dbh       = C4::Context->dbh;
 
 # Show borrower informations
@@ -330,6 +332,8 @@ if ( $op eq 'show' ) {
         },
     );
 
+    push @fields, { name => "password_expiration_date", type => "date" } if $logged_in_user->is_superlibrarian;
+
     $template->param('patron_attributes_codes', \@patron_attributes_codes);
     $template->param('patron_attributes_values', \@patron_attributes_values);
 
@@ -341,16 +345,18 @@ if ( $op eq 'do' ) {
 
     my @disabled = $input->multi_param('disable_input');
     my $infos;
-    for my $field ( qw/surname firstname branchcode categorycode streetnumber address address2 city state zipcode country email phone mobile sort1 sort2 dateenrolled dateexpiry borrowernotes opacnote debarred debarredcomment/ ) {
+    for my $field ( qw/surname firstname branchcode categorycode streetnumber address address2 city state zipcode country email phone mobile sort1 sort2 dateenrolled dateexpiry password_expiration_date borrowernotes opacnote debarred debarredcomment/ ) {
         my $value = $input->param($field);
         $infos->{$field} = $value if $value;
         $infos->{$field} = "" if grep { $_ eq $field } @disabled;
     }
 
-    for my $field ( qw( dateenrolled dateexpiry debarred ) ) {
+    for my $field ( qw( dateenrolled dateexpiry debarred password_expiration_date ) ) {
         $infos->{$field} = dt_from_string($infos->{$field}) if $infos->{$field};
     }
 
+    delete $infos->{password_expiration_date} unless $logged_in_user->is_superlibrarian;
+
     my @attributes = $input->multi_param('patron_attributes');
     my @attr_values = $input->multi_param('patron_attributes_value');
 
-- 
2.34.1