Bug 31095: Remove GetDebarments from members/memberentry.pl
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 24 Aug 2022 15:14:59 +0000 (16:14 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Jan 2023 13:19:36 +0000 (10:19 -0300)
This patch removes the use of GetDebarments from members/memberentry.pl
and replaces the references in the templates with patron.restrictions.

Test plan
1. Add a new user and confirm that the patron restrictions section does
   not appear on the form
2. Edit the user and confirm the patron restrictions section now appears
3. Add a manual restriction using the patron edit form
4. Confirm the restriction appears on the patron edit form
5. Confirm you can remove the restriction usine the patron edit form

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
members/memberentry.pl

index 48f62dd..e3839d8 100644 (file)
@@ -8,7 +8,7 @@
 [% PROCESS 'member-main-address-style.inc' %]
 [% PROCESS 'member-alt-address-style.inc' %]
 [% PROCESS 'member-alt-contact-style.inc' %]
-[% PROCESS 'patron_restrictions.inc' %]
+[% PROCESS 'restriction-types.inc' %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
     <title>
@@ -1409,7 +1409,7 @@ legend:hover {
 
                                     <fieldset class="rows" id="memberentry_restrictions">
                                         <legend id="restrictions_lgd">Patron restrictions</legend>
-                                        [% IF ( debarments ) %]
+                                        [% IF ( patron.restrictions.count ) %]
                                             <table>
                                                 <thead>
                                                     <tr>
@@ -1423,28 +1423,27 @@ legend:hover {
                                                     </tr>
                                                 </thead>
                                                 <tbody>
-                                                    [% FOREACH d IN debarments %]
-                                                        [% dtype = d.type %]
+                                                    [% FOREACH restriction IN patron.restrictions %]
                                                         <tr>
-                                                            <td>[% restriction_types.$dtype.display_text | html %]</td>
+                                                            <td>[% PROCESS restriction_type_description restriction_type=restriction.type %]</td>
                                                             <td>
-                                                                [% IF d.comment.search('OVERDUES_PROCESS') %]
-                                                                    Restriction added by overdues process [% d.comment.remove('OVERDUES_PROCESS ') | $raw %]
+                                                                [% IF restriction.comment.search('OVERDUES_PROCESS') %]
+                                                                    Restriction added by overdues process [% restriction.comment.remove('OVERDUES_PROCESS ') | $raw %]
                                                                 [% ELSE %]
-                                                                    [% d.comment | $raw %]
+                                                                    [% restriction.comment | $raw %]
                                                                 [% END %]
                                                             </td>
                                                             <td>
-                                                                [% IF d.expiration %]
-                                                                    [% d.expiration | $KohaDates %]
+                                                                [% IF restriction.expiration %]
+                                                                    [% restriction.expiration | $KohaDates %]
                                                                 [% ELSE %]
                                                                     <em>Indefinite</em>
                                                                 [% END %]
                                                             </td>
-                                                            <td>[% d.created | $KohaDates %]</td>
+                                                            <td>[% restriction.created | $KohaDates %]</td>
                                                             [% IF CAN_user_borrowers_edit_borrowers && CAN_user_circulate_manage_restrictions %]
                                                                 <td>
-                                                                    <input type="checkbox" id="debarment_[% d.borrower_debarment_id | html %]" name="remove_debarment" value="[% d.borrower_debarment_id | html %]" />
+                                                                    <input type="checkbox" id="debarment_[% restriction.borrower_debarment_id | html %]" name="remove_debarment" value="[% restriction.borrower_debarment_id | html %]" />
                                                                 </td>
                                                             [% END %]
                                                         </tr>
@@ -1453,10 +1452,10 @@ legend:hover {
                                             </table>
                                         [% ELSE %]
                                             <p>Patron is currently unrestricted.</p>
-                                        [% END # /IF ( debarments ) %]
+                                        [% END # /IF ( patron.restrictions.count ) %]
 
                                         [% IF CAN_user_borrowers_edit_borrowers && CAN_user_circulate_manage_restrictions %]
-                                            <p><a href="#" id="add_manual_restriction">Add manual restriction</a></p>
+                                        <p><a href="#" id="add_manual_restriction"><i class="fa fa-plus"></i> Add manual restriction</a></p>
                                             <fieldset id="manual_restriction_form">
                                                 <input type="hidden" id="add_debarment" name="add_debarment" value="0" />
                                                 <legend id="manual_restriction_lgd">Add manual restriction</legend>
@@ -1465,12 +1464,12 @@ legend:hover {
                                                     <li>
                                                         <label for="debarred_type">Type:</label>
                                                         <select name="debarred_type">
-                                                            [% FOREACH code IN restriction_types.keys %]
-                                                                [% IF !restriction_types.$code.is_system %]
-                                                                    [% IF restriction_types.$code.is_default %]
-                                                                    <option value="[% code | html %]" selected>[% PROCESS restriction_type_description restriction=restriction_types.$code %]</option>
+                                                            [% FOREACH restriction_type IN restriction_types %]
+                                                                [% IF !restriction_type.is_system %]
+                                                                    [% IF restriction_type.is_default %]
+                                                                    <option value="[% code | html %]" selected>[% PROCESS restriction_type_description %]</option>
                                                                     [% ELSE %]
-                                                                    <option value="[% code | html %]">[% PROCESS restriction_type_description restriction=restriction_types.$code %]</option>
+                                                                    <option value="[% code | html %]">[% PROCESS restriction_type_description %]</option>
                                                                     [% END %]
                                                                 [% END %]
                                                             [% END %]
index 2ebf3b4..0193cc3 100755 (executable)
@@ -35,7 +35,7 @@ use C4::Form::MessagingPreferences;
 use Koha::AuthUtils;
 use Koha::AuthorisedValues;
 use Koha::Email;
-use Koha::Patron::Debarments qw( AddDebarment DelDebarment GetDebarments );
+use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
 use Koha::Patron::Restriction::Types;
 use Koha::Cities;
 use Koha::DateUtils qw( dt_from_string );
@@ -118,8 +118,7 @@ foreach my $id ( @delete_guarantor ) {
 
 ## Deal with debarments
 $template->param(
-    debarments => scalar GetDebarments( { borrowernumber => $borrowernumber } ),
-    restriction_types => scalar Koha::Patron::Restriction::Types->keyed_on_code()
+    restriction_types => scalar Koha::Patron::Restriction::Types->search()
 );
 my @debarments_to_remove = $input->multi_param('remove_debarment');
 foreach my $d ( @debarments_to_remove ) {