From 02df7ca36e9e404e9add45ab5508872301be48eb Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 15 Aug 2007 13:30:17 +0000 Subject: [PATCH] settings server controlled opt-in functionallity for non-home_ou transactions git-svn-id: svn://svn.open-ils.org/ILS/trunk@7665 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 20 ++++++++++++++ Open-ILS/examples/opensrf.xml.example | 10 +++++++ .../OpenILS/Application/Storage/CDBI/actor.pm | 7 +++++ .../Application/Storage/Driver/Pg/dbi.pm | 6 +++++ .../Application/Storage/Publisher/actor.pm | 26 ++++++++++++++++++- Open-ILS/src/sql/Pg/005.schema.actors.sql | 10 +++++++ 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 7d721d4f80..687cfe25be 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -98,6 +98,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/examples/opensrf.xml.example b/Open-ILS/examples/opensrf.xml.example index d6d853c506..5f5e7d0350 100644 --- a/Open-ILS/examples/opensrf.xml.example +++ b/Open-ILS/examples/opensrf.xml.example @@ -17,8 +17,18 @@ Example opensrf config file for OpenILS /openils/var + + + + + false + + + /openils/conf/fm_IDL.xml + prefork + /openils/var/data/ils_events.xml diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm index c2e631b900..9f7ba25cf0 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm @@ -20,6 +20,13 @@ __PACKAGE__->columns( Essential => qw/usrname email first_given_name standing barred profile prefix suffix alert_message day_phone evening_phone other_phone mailing_address/ ); +#------------------------------------------------------------------------------- +package actor::usr_org_unit_opt_in; +use base qw/actor/; +__PACKAGE__->table( 'actor_usr_org_unit_opt_in' ); +__PACKAGE__->columns( Primary => qw/id/ ); +__PACKAGE__->columns( Essential => qw/org_unit usr staff opt_in_ts opt_in_ws/ ); + #------------------------------------------------------------------------------- package actor::org_unit_proximity; use base qw/actor/; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index 1bbdd6c8d9..fdd10d267b 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -393,6 +393,12 @@ actor::org_address->table( 'actor.org_address' ); actor::org_address->sequence( 'actor.org_address_id_seq' ); + #--------------------------------------------------------------------- + package actor::usr_org_unit_opt_in; + + actor::usr_org_unit_opt_in->table( 'actor.usr_org_unit_opt_in' ); + actor::usr_org_unit_opt_in->sequence( 'actor.usr_org_unit_opt_in_id_seq' ); + #--------------------------------------------------------------------- package actor::org_unit_proximity; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm index 406c06ba3a..2234a27746 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -4,6 +4,7 @@ use OpenILS::Application::Storage::CDBI::actor; use OpenSRF::Utils::Logger qw/:level/; use OpenSRF::Utils qw/:datetime/; use OpenILS::Utils::Fieldmapper; +use OpenSRF::Utils::SettingsClient; use DateTime; use DateTime::Format::ISO8601; @@ -438,6 +439,10 @@ sub patron_search { my $limit = shift || 1000; my $sort = shift; my $inactive = shift; + my $ws_ou = shift; + my $ws_ou_depth = shift || 0; + + my $strict_opt_in = OpenSRF::Utils::SettingsClient->new->config_value( share => user => 'opt_in' ); $sort = ['family_name','first_given_name'] unless ($$sort[0]); push @$sort,'id'; @@ -495,6 +500,8 @@ sub patron_search { my $u_table = actor::user->table; my $a_table = actor::user_address->table; + my $opt_in_table = actor::usr_org_unit_opt_in->table; + my $ou_table = actor::org_unit->table; my $u_select = "SELECT id as id FROM $u_table u WHERE $usr_where"; my $a_select = "SELECT usr as id FROM $a_table a WHERE $addr_where"; @@ -525,12 +532,29 @@ sub patron_search { $inactive = 'AND users.active = TRUE'; } + if (!$ws_ou) { # XXX This should be required!! + $ws_ou = actor::org_unit->search( { parent_ou => undef } )->[0]->id; + } + + my $opt_in_join = ''; + my $opt_in_where = ''; + if (lc($strict_opt_in) eq 'true') { + $opt_in_join = "LEFT JOIN $opt_in_table oi ON (oi.org_unit = $ws_ou AND users.id = oi.usr)"; + $opt_in_where = "AND (oi.id IS NOT NULL OR users.home_ou = $ws_ou)"; + } + + my $descendants = "actor.org_unit_descendants($ws_ou, $ws_ou_depth)"; + $select = <<" SQL"; SELECT DISTINCT $distinct_list FROM $u_table AS users JOIN ($select) AS search USING (id) + JOIN $descendants d ON (d.id = users.home_ou) + $opt_in_join $clone_select - WHERE users.deleted = FALSE $inactive + WHERE users.deleted = FALSE + $inactive + $opt_in_where ORDER BY $order_by LIMIT $limit SQL diff --git a/Open-ILS/src/sql/Pg/005.schema.actors.sql b/Open-ILS/src/sql/Pg/005.schema.actors.sql index 294bb04905..d783c5eef4 100644 --- a/Open-ILS/src/sql/Pg/005.schema.actors.sql +++ b/Open-ILS/src/sql/Pg/005.schema.actors.sql @@ -436,6 +436,16 @@ CREATE TABLE actor.workstation ( owning_lib INT NOT NULL REFERENCES actor.org_unit (id) ); +CREATE TABLE actor.usr_org_unit_opt_in ( + id SERIAL PRIMARY KEY, + org_unit INT NOT NULL REFERENCES actor.org_unit (id), + usr INT NOT NULL REFERENCES actor.usr (id), + staff INT NOT NULL REFERENCES actor.usr (id), + opt_in_ts TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + opt_in_ws INT NOT NULL REFERENCES actor.workstation (id), + CONSTRAINT usr_opt_in_once_per_org_unit UNIQUE (usr,org_unit) +); + CREATE TABLE actor.org_unit_setting ( id BIGSERIAL PRIMARY KEY, org_unit INT NOT NULL REFERENCES actor.org_unit ON DELETE CASCADE, -- 2.43.2