[open-ils-commits] r11052 - branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Nov 3 22:42:45 EST 2008


Author: erickson
Date: 2008-11-03 22:42:43 -0500 (Mon, 03 Nov 2008)
New Revision: 11052

Modified:
   branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Log:
if a group is configured as rental/deposit exempt, honor descendent groups as well

Modified: branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-11-04 02:05:26 UTC (rev 11051)
+++ branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-11-04 03:42:43 UTC (rev 11052)
@@ -290,6 +290,7 @@
 
 my $holdcode    = "OpenILS::Application::Circ::Holds";
 my $transcode   = "OpenILS::Application::Circ::Transit";
+my %user_groups;
 
 sub DESTROY { }
 
@@ -417,6 +418,11 @@
 
     $self->capture('') unless $self->capture;
 
+    unless(%user_groups) {
+        my $gps = $self->editor->retrieve_all_permission_grp_tree;
+        %user_groups = map { $_->id => $_ } @$gps;
+    }
+
     return $self;
 }
 
@@ -597,7 +603,9 @@
         $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;
 }
 
@@ -608,10 +616,24 @@
         $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;
+}
+
 sub check_captured_holds {
    my $self    = shift;
    my $copy    = $self->copy;



More information about the open-ils-commits mailing list