filter z39.50 services retrieval based on use_perm
authorJason Etheridge <jason@esilibrary.com>
Fri, 22 Jul 2011 06:09:06 +0000 (02:09 -0400)
committerJason Etheridge <jason@esilibrary.com>
Fri, 22 Jul 2011 06:56:41 +0000 (02:56 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Z3950.pm
Open-ILS/xul/staff_client/server/cat/z3950.js

index a5cd5ca..5f3c0ab 100644 (file)
@@ -73,6 +73,9 @@ __PACKAGE__->register_method(
     method    => "query_services",
     api_name  => "open-ils.search.z3950.retrieve_services",
     signature => q/
+        @param auth The login session key
+        @param check_use_perm If true, checks the Use Perm on the services
+            against the requestor
         Returns a list of service names that we have config
         data for
     /
@@ -84,12 +87,12 @@ __PACKAGE__->register_method(
 # What services do we have config info for?
 # -------------------------------------------------------------------
 sub query_services {
-    my( $self, $client, $auth ) = @_;
+    my( $self, $client, $auth, $check_use_perm ) = @_;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
     return $e->event unless $e->allowed('REMOTE_Z3950_QUERY');
 
-    return fetch_service_defs();
+    return fetch_service_defs($check_use_perm,$e);
 }
 
 # -------------------------------------------------------------------
@@ -97,10 +100,13 @@ sub query_services {
 # -------------------------------------------------------------------
 sub fetch_service_defs {
 
+    my $check_use_perm = shift;
+    my $editor_with_authtoken = shift;
+
     my $hash = $sclient->config_value('z3950', 'services');
 
     # overlay config file values with in-db values
-    my $e = new_editor();
+    my $e = $editor_with_authtoken || new_editor();
     if($e->can('search_config_z3950_source')) {
 
         my $sources = $e->search_config_z3950_source(
@@ -118,6 +124,7 @@ sub fetch_service_defs {
                 record_format => $s->record_format,
                 transmission_format => $s->transmission_format,
                 auth => $s->auth,
+                use_perm => $s->use_perm
             };
 
             for my $a ( @{ $s->attrs } ) {
@@ -151,6 +158,22 @@ sub fetch_service_defs {
         }
     };
 
+    # If checking use_perm, then filter out any services which the requestor
+    # lacks the perm for
+    if ($check_use_perm) {
+        foreach my $s (keys %{ $hash }) {
+            if ($$hash{$s}{use_perm}) {
+                if ($U->check_perms(
+                    $e->requestor->id,
+                    $e->requestor->ws_ou,
+                    $$hash{$s}{use_perm}
+                )) {
+                    delete $$hash{$s};
+                }
+            };
+        }
+    }
+
     %services = %$hash; # cache these internally so we can actually use the db-configured sources
     return $hash;
 }
index dc600e8..ce7fc09 100644 (file)
@@ -371,7 +371,7 @@ cat.z3950.prototype = {
 
                                         var robj = obj.network.simple_request(
                                             'RETRIEVE_Z3950_SERVICES',
-                                            [ ses() ]
+                                            [ ses(), true ]
                                         );
                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
                                         obj.services = robj;