From 9abb870a7a81d0fb5192543a64d13d33133e0975 Mon Sep 17 00:00:00 2001
From: Alex Buckley <alexbuckley@catalyst.net.nz>
Date: Tue, 27 Feb 2024 02:31:09 +0000
Subject: [PATCH] Bug 36169: Patron categories with type='Staff' should be able
 to have guarantees
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Library staff - whose patron category has a type='Staff' should be able to have guarantees added.

Test plan:
1) Create a 'Library staff' patron category with 'Category type' = 'Staff'

2) Create a patron account using the 'Library staff' patron category

3) Notice the '+ Add guarantee' button is not displayed in the members toolbar for the 'Library staff' patron you created

4) Apply patches and restart services

5) Refresh your browser window

6) Notice the '+ Add guarantee' button is now displaying for the 'Library staff' patron

7) Confirm you can successfully add a guarantee

8) Run unit test t/db_dependent/Koha/Patrons.t

Sponsored-By: Waitaki District Council, New Zealand
Signed-off-by: Tadeusz „tadzik” Sośnierz <tadeusz@sosnierz.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
---
 Koha/Patron.pm                |  4 ++--
 t/db_dependent/Koha/Patrons.t | 17 ++++++++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Koha/Patron.pm b/Koha/Patron.pm
index 2034a6d1378..6e4eeffb912 100644
--- a/Koha/Patron.pm
+++ b/Koha/Patron.pm
@@ -2020,13 +2020,13 @@ sub is_superlibrarian {
 
 my $is_adult = $patron->is_adult
 
-Return true if the patron has a category with a type Adult (A) or Organization (I)
+Return true if the patron has a category with a type Adult (A), Organization (I) or Staff (S)
 
 =cut
 
 sub is_adult {
     my ( $self ) = @_;
-    return $self->category->category_type =~ /^(A|I)$/ ? 1 : 0;
+    return $self->category->category_type =~ /^(A|I|S)$/ ? 1 : 0;
 }
 
 =head3 is_child
diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t
index 68ea342a6e3..38c744195a8 100755
--- a/t/db_dependent/Koha/Patrons.t
+++ b/t/db_dependent/Koha/Patrons.t
@@ -1414,7 +1414,7 @@ subtest 'account_locked' => sub {
 };
 
 subtest 'is_child | is_adult' => sub {
-    plan tests => 8;
+    plan tests => 10;
     my $category = $builder->build_object(
         {
             class => 'Koha::Patron::Categories',
@@ -1463,21 +1463,36 @@ subtest 'is_child | is_adult' => sub {
             value => { categorycode => $category->categorycode }
         }
     );
+    $category = $builder->build_object(
+        {
+           class => 'Koha::Patron::Categories',
+           value => { category_type => 'S' }
+        }
+    );
+    my $patron_staff = $builder->build_object(
+        {
+           class => 'Koha::Patrons',
+           value => { categorycode => $category->categorycode }
+        }
+    );
     is( $patron_adult->is_adult, 1, 'Patron from category A should be considered adult' );
     is( $patron_adult_i->is_adult, 1, 'Patron from category I should be considered adult' );
     is( $patron_child->is_adult, 0, 'Patron from category C should not be considered adult' );
     is( $patron_other->is_adult, 0, 'Patron from category O should not be considered adult' );
+    is( $patron_staff->is_adult, 1, 'Patron from category S should be considered adult' );
 
     is( $patron_adult->is_child, 0, 'Patron from category A should be considered child' );
     is( $patron_adult_i->is_child, 0, 'Patron from category I should be considered child' );
     is( $patron_child->is_child, 1, 'Patron from category C should not be considered child' );
     is( $patron_other->is_child, 0, 'Patron from category O should not be considered child' );
+    is( $patron_staff->is_child, 0, 'Patron from category S should not be considered child' );
 
     # Clean up
     $patron_adult->delete;
     $patron_adult_i->delete;
     $patron_child->delete;
     $patron_other->delete;
+    $patron_staff->delete;
 };
 
 subtest 'overdues' => sub {
-- 
2.30.2