From f29754d84296ef0560d8a326ee1d962353bf6115 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 4 Nov 2008 03:44:57 +0000 Subject: [PATCH] if a group is configured as rental/deposit exempt, honor descendent groups as well git-svn-id: svn://svn.open-ils.org/ILS/trunk@11054 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/Circulate.pm | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm index 878aa18e36..d7fb112f36 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm @@ -317,6 +317,7 @@ use OpenILS::Const qw/:const/; my $holdcode = "OpenILS::Application::Circ::Holds"; my $transcode = "OpenILS::Application::Circ::Transit"; +my %user_groups; sub DESTROY { } @@ -450,6 +451,11 @@ sub new { $self->capture('') unless $self->capture; + unless(%user_groups) { + my $gps = $self->editor->retrieve_all_permission_grp_tree; + %user_groups = map { $_->id => $_ } @$gps; + } + return $self; } @@ -701,7 +707,9 @@ sub is_deposit_exempt { $self->patron->profile->id : $self->patron->profile; my $groups = $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.deposit.exempt_groups', $self->editor); - return 1 if $groups and grep {$_ == $pid} @$groups; + for my $grp (@$groups) { + return 1 if $self->is_group_descendant($grp, $pid); + } return 0; } @@ -712,7 +720,21 @@ sub is_rental_exempt { $self->patron->profile->id : $self->patron->profile; my $groups = $U->ou_ancestor_setting_value( $self->circ_lib, 'circ.rental.exempt_groups', $self->editor); - return 1 if $groups and grep {$_ == $pid} @$groups; + for my $grp (@$groups) { + return 1 if $self->is_group_descendant($grp, $pid); + } + return 0; +} + +sub is_group_descendant { + my($self, $p_id, $c_id) = @_; + return 0 unless defined $p_id and defined $c_id; + return 1 if $c_id == $p_id; + while(my $grp = $user_groups{$c_id}) { + $c_id = $grp->parent; + return 0 unless defined $c_id; + return 1 if $c_id == $p_id; + } return 0; } -- 2.43.2