Bug 26250: Fix tests when SearchEngine=Elastic
[srvgit] / admin / categories.pl
index f09c2bf..f9144e7 100755 (executable)
@@ -23,13 +23,13 @@ use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Auth;
-use C4::Branch;
 use C4::Output;
 use C4::Form::MessagingPreferences;
 use Koha::Patrons;
 use Koha::Database;
 use Koha::DateUtils;
 use Koha::Patron::Categories;
+use Koha::Libraries;
 
 my $input         = new CGI;
 my $searchfield   = $input->param('description') // q||;
@@ -43,7 +43,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
-        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
+        flagsrequired   => { parameters => 'manage_patron_categories' },
         debug           => 1,
     }
 );
@@ -55,13 +55,13 @@ if ( $op eq 'add_form' ) {
         $selected_branches = $category->branch_limitations;
     }
 
-    my $branches = GetBranches;
+    my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
     my @branches_loop;
-    foreach my $branchcode ( sort { uc( $branches->{$a}->{branchname} ) cmp uc( $branches->{$b}->{branchname} ) } keys %$branches ) {
-        my $selected = ( grep { $_ eq $branchcode } @$selected_branches ) ? 1 : 0;
+    foreach my $branch ( @$branches ) {
+        my $selected = ( grep { $_ eq $branch->{branchcode} } @$selected_branches ) ? 1 : 0;
         push @branches_loop,
-          { branchcode => $branchcode,
-            branchname => $branches->{$branchcode}->{branchname},
+          { branchcode => $branch->{branchcode},
+            branchname => $branch->{branchname},
             selected   => $selected,
           };
     }
@@ -92,8 +92,13 @@ elsif ( $op eq 'add_validate' ) {
     my $BlockExpiredPatronOpacActions = $input->param('BlockExpiredPatronOpacActions');
     my $checkPrevCheckout = $input->param('checkprevcheckout');
     my $default_privacy = $input->param('default_privacy');
+    my $reset_password = $input->param('reset_password');
+    my $change_password = $input->param('change_password');
     my @branches = grep { $_ ne q{} } $input->multi_param('branches');
 
+    $reset_password = undef if $reset_password eq -1;
+    $change_password = undef if $change_password eq -1;
+
     my $is_a_modif = $input->param("is_a_modif");
 
     if ($enrolmentperioddate) {
@@ -122,6 +127,8 @@ elsif ( $op eq 'add_validate' ) {
         $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions);
         $category->checkprevcheckout($checkPrevCheckout);
         $category->default_privacy($default_privacy);
+        $category->reset_password($reset_password);
+        $category->change_password($change_password);
         eval {
             $category->store;
             $category->replace_branch_limitations( \@branches );
@@ -148,6 +155,8 @@ elsif ( $op eq 'add_validate' ) {
             BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions,
             checkprevcheckout => $checkPrevCheckout,
             default_privacy => $default_privacy,
+            reset_password => $reset_password,
+            change_password => $change_password,
         });
         eval {
             $category->store;