gave cstore editor the ability to check an array of permissions
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Feb 2008 16:29:55 +0000 (16:29 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 6 Feb 2008 16:29:55 +0000 (16:29 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@8661 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/CStoreEditor.pm

index b7d0fbd..9d71564 100644 (file)
@@ -375,20 +375,10 @@ sub perm_checked {
 # $e->event is set and undef is returned
 # The perm user is $e->requestor->id and perm org defaults to the requestor's
 # ws_ou
-# If this perm at the given org has already been verified, true is returned
-# and the perm is not re-checked
+# if perm is an array of perms, method will return true at the first allowed
+# permission.  If none of the perms are allowed, the perm_failure event
+# is created with the last perm to fail
 # -----------------------------------------------------------------------------
-=head
-sub allowed {
-       my( $self, $perm, $org ) = @_;
-       my $uid = $self->requestor->id;
-       $org ||= $self->requestor->ws_ou;
-       $self->log(I, "checking perms user=$uid, org=$org, perm=$perm");
-       return 1 if $self->perm_checked($perm, $org); 
-       return $self->checkperm($uid, $org, $perm);
-}
-=cut
-
 my $PERM_QUERY = {
     select => {
         au => [ {
@@ -406,21 +396,26 @@ sub allowed {
        my( $self, $perm, $org ) = @_;
        my $uid = $self->requestor->id;
        $org ||= $self->requestor->ws_ou;
-       $self->log(I, "checking perms user=$uid, org=$org, perm=$perm");
-
-    # fill in the search hash
-    $PERM_QUERY->{select}->{au}->[0]->{params} = [$perm, $org];
-    $PERM_QUERY->{where}->{id} = $uid;
 
-    return 1 if $U->is_true($self->json_query($PERM_QUERY)->[0]->{has_perm});
+    my $perms = [$perm] unless ref($perm) eq 'ARRAY';
+    my $perm;
+    for $perm (@$perms) {
+           $self->log(I, "checking perms user=$uid, org=$org, perm=$perm");
+    
+        # fill in the search hash
+        $PERM_QUERY->{select}->{au}->[0]->{params} = [$perm, $org];
+        $PERM_QUERY->{where}->{id} = $uid;
+    
+        return 1 if $U->is_true($self->json_query($PERM_QUERY)->[0]->{has_perm});
+    }
 
     # set the perm failure event if the permission check returned false
        my $e = OpenILS::Event->new('PERM_FAILURE', ilsperm => $perm, ilspermloc => $org);
        $self->event($e);
        return undef;
-
 }
 
+
 =head
 sub checkperm {
        my($self, $userid, $org, $perm) = @_;