LP 1890629: Make Self-Registration Opt-in Settings Lookup Tree Aware user/dyrcona/lp1890629
authorJason Stephenson <jason@sigio.com>
Fri, 14 Aug 2020 16:42:24 +0000 (12:42 -0400)
committerJason Stephenson <jason@sigio.com>
Fri, 14 Aug 2020 16:42:24 +0000 (12:42 -0400)
Patron self-registration in the OPAC only shows the opt-in settings if
the events are owned specifically at one of the locations where patron
self-registration is also allowed.  The event could be owned higher up
the org. tree from the libraries that allow self-registration,
particularly in a consortium where not all members do
self-registration.  This patch changes the search for opt-in events to
include the ancestor org. units of those that allow self-registration.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm

index 4949d10..99b692b 100644 (file)
@@ -6,6 +6,7 @@ use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Event;
+use List::MoreUtils qw/uniq/;
 use Data::Dumper;
 $Data::Dumper::Indent = 0;
 my $U = 'OpenILS::Application::AppUtils';
@@ -135,13 +136,20 @@ sub collect_opt_in_settings {
     my $self = shift;
     my $e = $self->editor;
 
+    # Get the valid_orgs and their ancestors, because the event def
+    # may be owned higher up the tree.
+    my @opt_orgs = ();
+    for my $orgs (map { $U->get_org_ancestors($_) } @{ $self->ctx->{register}{valid_orgs} }) {
+        push(@opt_orgs, @{$orgs});
+    }
+
     my $types = $e->json_query({
         select => {cust => ['name']},
         from => {atevdef => 'cust'},
         transform => 'distinct',
         where => {
             '+atevdef' => {
-                owner => [ map { $_ } @{ $self->ctx->{register}{valid_orgs} } ],
+                owner => [ uniq @opt_orgs ],
                 active => 't'
             }
         }