From: Galen Charlton Date: Wed, 3 Aug 2016 19:38:49 +0000 (-0400) Subject: LP#1356477: teach OPAC patron registration form about staged user (opt-in) settings X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d1d36d3d56dcbe46d462ce8e431911df7b7166b;p=evergreen%2Ftadl.git LP#1356477: teach OPAC patron registration form about staged user (opt-in) settings This patch causes a checkbox to be added for each user setting that controls opt-in for active Action/Trigger event definitions. In the specific context of email checkout receipts, this means that a patron who is self-registering can elect to get email checkout receipts by default. Signed-off-by: Galen Charlton Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm index 0b68f1aa65..4949d10073 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm @@ -24,6 +24,8 @@ sub load_patron_reg { $ctx->{register}{valid_orgs} = $self->setting_is_true_for_orgs('opac.allow_pending_user'); + $self->collect_opt_in_settings; + # just loading the form return Apache2::Const::OK unless $cgi->request_method eq 'POST'; @@ -62,6 +64,20 @@ sub load_patron_reg { # attempt to create a pending address $addr = undef unless $has_addr; + # opt-in settings + my $settings = []; + foreach (grep /^stgs\./, $cgi->param) { + my $val = $cgi->param($_); + next unless $val; # opt-in settings are always Boolean, + # so just skip if not set + $self->inspect_register_value($_, $val); + s/^stgs.//g; + my $setting = Fieldmapper::staging::setting_stage->new; + $setting->setting($_); + $setting->value('true'); + push @$settings, $setting; + } + # At least one value was invalid. Exit early and re-render. return Apache2::Const::OK if $ctx->{register}{invalid}; @@ -72,7 +88,7 @@ sub load_patron_reg { my $resp = $U->simplereq( 'open-ils.actor', 'open-ils.actor.user.stage.create', - $user, $addr + $user, $addr, undef, [], $settings ); if (!$resp or ref $resp) { @@ -115,6 +131,25 @@ sub collect_requestor_info { } } +sub collect_opt_in_settings { + my $self = shift; + my $e = $self->editor; + + my $types = $e->json_query({ + select => {cust => ['name']}, + from => {atevdef => 'cust'}, + transform => 'distinct', + where => { + '+atevdef' => { + owner => [ map { $_ } @{ $self->ctx->{register}{valid_orgs} } ], + active => 't' + } + } + }); + $self->ctx->{register}{opt_in_settings} = + $e->search_config_usr_setting_type({name => [map {$_->{name}} @$types]}); +} + # if the username is in use by an actor.usr OR a # pending user treat it as taken and warn the user. sub test_requested_username { @@ -223,7 +258,22 @@ sub collect_register_validation_settings { sub inspect_register_value { my ($self, $field_path, $value) = @_; my $ctx = $self->ctx; - my ($scls, $field) = split(/\./, $field_path); + my ($scls, $field) = split(/\./, $field_path, 2); + + if ($scls eq 'stgs') { + my $found = 0; + foreach my $type (@{ $self->ctx->{register}{opt_in_settings} }) { + if ($field eq $type->name) { + $found = 1; + } + } + if (!$found) { + $ctx->{register}{invalid}{$scls}{$field}{invalid} = 1; + $logger->info("patron register: trying to set an opt-in ". + "setting $field that is not allowed."); + } + return; + } if (!$value) { diff --git a/Open-ILS/src/templates/opac/register.tt2 b/Open-ILS/src/templates/opac/register.tt2 index 3c2d6375fb..962fa9ff73 100644 --- a/Open-ILS/src/templates/opac/register.tt2 +++ b/Open-ILS/src/templates/opac/register.tt2 @@ -172,6 +172,21 @@ FOR field_def IN register_fields; [% END %] + [% IF ctx.register.opt_in_settings.size > 0 %] + [% FOR optin IN ctx.register.opt_in_settings %] + + + + + + + + [% END %] + [% END %]