[open-ils-commits] r11054 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Nov 3 22:44:59 EST 2008


Author: erickson
Date: 2008-11-03 22:44:57 -0500 (Mon, 03 Nov 2008)
New Revision: 11054

Modified:
   trunk/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: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-11-04 03:44:42 UTC (rev 11053)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm	2008-11-04 03:44:57 UTC (rev 11054)
@@ -317,6 +317,7 @@
 
 my $holdcode    = "OpenILS::Application::Circ::Holds";
 my $transcode   = "OpenILS::Application::Circ::Transit";
+my %user_groups;
 
 sub DESTROY { }
 
@@ -450,6 +451,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;
 }
 
@@ -701,7 +707,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;
 }
 
@@ -712,10 +720,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