moved old-fashioned perm check to json_query for speed
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Feb 2008 20:10:26 +0000 (20:10 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 1 Feb 2008 20:10:26 +0000 (20:10 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@8573 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm

index c5af420..bbfc6e0 100644 (file)
@@ -9,7 +9,7 @@ use OpenILS::Utils::ModsParser;
 use OpenSRF::EX qw(:try);
 use OpenILS::Event;
 use Data::Dumper;
-use OpenILS::Utils::CStoreEditor;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Const qw/:const/;
 
 # ---------------------------------------------------------------------------
@@ -41,16 +41,30 @@ sub start_db_session {
        return $session;
 }
 
+my $PERM_QUERY = {
+    select => {
+        au => [ {
+            transform => 'permission.usr_has_perm',
+            alias => 'has_perm',
+            column => 'id',
+            params => []
+        } ]
+    },
+    from => 'au',
+    where => {},
+};
+
 
 # returns undef if user has all of the perms provided
 # returns the first failed perm on failure
 sub check_user_perms {
        my($self, $user_id, $org_id, @perm_types ) = @_;
        $logger->debug("Checking perms with user : $user_id , org: $org_id, @perm_types");
+
        for my $type (@perm_types) {
-               return $type unless ($self->storagereq(
-                       "open-ils.storage.permission.user_has_perm", 
-                       $user_id, $type, $org_id ));
+           $PERM_QUERY->{select}->{au}->[0]->{params} = [$type, $org_id];
+               $PERM_QUERY->{where}->{id} = $user_id;
+               return $type unless $self->is_true(new_editor()->json_query($PERM_QUERY)->[0]->{has_perm});
        }
        return undef;
 }