Add and use a patron search that overrides opt-in invisibility
authorDan Scott <dscott@laurentian.ca>
Wed, 14 Sep 2011 20:02:14 +0000 (16:02 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 20 Apr 2018 16:06:20 +0000 (12:06 -0400)
Something like this is required for API calls that need to operate
against a number of libraries in a given instance that are using opt-in;
otherwise, attempts to search for users will fail and you may end up
creating near-duplicates etc.

The implementation adds an
open-ils.actor.search.patron.advanced.opt_in_override method to
open-ils.actor, which, if invoked, checks to see if the caller has the
OPT_IN_OVERRIDE permission. If so, then the crazy_search ignores the
normal opt-in limits and searches all pertinent users in the database.

As a global permission, OPT_IN_OVERRIDE is a blunt instrument. Others
might want to put together a more refined version that uses OU depths to
define boundaries.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm

index 47576b1..cff262d 100644 (file)
@@ -1355,10 +1355,18 @@ sub patron_adv_search {
     }
     return ($fleshed ? undef : []) unless $search_ok;
 
+    my $ignore_opt_in = 0;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
     return $e->event unless $e->allowed('VIEW_USER');
 
+    # Override opt-in permissions
+    if ($self->api_name =~ /opt_in_override/) {
+        if ($e->allowed('OPT_IN_OVERRIDE')) {
+            $ignore_opt_in = 1;
+        }
+    }
+
     # depth boundary outside of which patrons must opt-in, default to 0
     my $opt_boundary = 0;
     $opt_boundary = $U->ou_ancestor_setting_value($e->requestor->ws_ou,'org.patron_opt_boundary') if user_opt_in_enabled($self);
@@ -1379,7 +1387,7 @@ sub patron_adv_search {
     my $ids = $U->storagereq(
         "open-ils.storage.actor.user.crazy_search", $search_hash,
         $search_limit, $search_sort, $include_inactive,
-        $e->requestor->ws_ou, $search_ou, $opt_boundary, $offset);
+        $e->requestor->ws_ou, $search_ou, $opt_boundary, $offset, $ignore_opt_in);
 
     return $ids unless $self->api_name =~ /fleshed/;
 
index bcf4508..0b61f3b 100644 (file)
@@ -659,6 +659,7 @@ sub patron_search {
     my $search_org = shift || $ws_ou;
     my $opt_boundary = shift || 0;
     my $offset = shift || 0;
+       my $opt_in_override = shift;
 
     my $penalty_sort = 0;
 
@@ -798,7 +799,7 @@ sub patron_search {
     my $descendants = "actor.org_unit_descendants($search_org)";
 
     my $opt_in_where = '';
-    if (lc($strict_opt_in) eq 'true') {
+    if (lc($strict_opt_in) eq 'true' && (!$opt_in_override)) {
         $opt_in_where = "AND (";
         $opt_in_where .= "EXISTS (select id FROM $opt_in_table ";
         $opt_in_where .= " WHERE org_unit in (select (actor.org_unit_ancestors($ws_ou)).id)";