From: Jason Etheridge Date: Wed, 13 Jul 2022 11:55:18 +0000 (-0400) Subject: filter configs backend X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1ebbef4a2262780ec959ae59a09cff19903120b0;p=working%2FEvergreen.git filter configs backend Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 471ecd5082..bbf2be254d 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -15435,9 +15435,11 @@ SELECT usr, + + @@ -15531,6 +15533,30 @@ SELECT usr, + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm index 84f7b50d54..8b929cdaf6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm @@ -62,10 +62,23 @@ sub config { $config->{settings} = {map {$_->name => $json->decode($_->value)} @{$group->settings}}; - $logger->info("SIP settings " . $json->encode($config->{settings})); + $logger->info("SIP2: settings = " . $json->encode($config->{settings})); return $self->{config} = $config; } +sub filters { + my $self = shift; + return $self->{filters} if $self->{filters}; + + my $group = $self->editor->retrieve_sip_setting_group([ + $self->sip_account->setting_group, + {flesh => 1, flesh_fields => {sipsetg => ['filters']}} + ]); + + $logger->info("SIP2: found " . scalar(@{ $group->filters }) . " filters"); + return $self->{filters} = $group->filters; +} + # Retrieve an existing SIP session via SIP session token sub find { my ($class, $seskey) = @_; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Mediator.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Mediator.pm index c811980fe7..daecc8e66d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Mediator.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Mediator.pm @@ -26,6 +26,8 @@ use JSON::XS; use OpenSRF::System; use OpenSRF::Utils::Logger q/$logger/; use OpenILS::Application::AppUtils; +use OpenILS::Application::SIP2::Common; +use OpenILS::Application::SIP2::Session; my $U = 'OpenILS::Application::AppUtils'; my $json = JSON::XS->new; @@ -58,6 +60,11 @@ sub handler { # This key is required even if the client has not yet authenticated. return Apache2::Const::FORBIDDEN unless $seskey; + # so we can grab config and filter data + my $session = OpenILS::Application::SIPSession->find($seskey); + my $session_config = $session ? $session->config : undef; + my $session_filters = $session ? $session->filters : undef; + if ($msg_json) { eval { $message = $json->decode($msg_json) }; if ($message) { @@ -90,38 +97,34 @@ sub handler { $r->content_type('application/json'); # response = $VAR1 = {'fields' => [{'AO' => 'example'},{'BX' => 'YYYNYNYYNYYNNNYN'}],'fixed_fields' => ['Y','Y','Y','Y','N','N','999','999','20220706 154418','2.00'],'code' => '98'}; - # filters v1 = $VAR1 = { 'field' => { 'identifier' => 'AE', 'replace_with' => 'John Doe' } }; - # filters v1 = $VAR1 = { 'field' => { 'identifier' => 'AE', 'remove' => 'true' } }; - # filters v1 = $VAR1 = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] }; - my $filters = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] }; + #my $filters = { 'field' => [ { 'identifier' => 'AE', 'replace_with' => 'John Doe' }, { 'replace_with' => 'Jane Doe', 'identifier' => 'AE' } ] }; sub find_field_config { + my $filters = shift; my $field_id = shift; - my @relavent_field_configs = grep { $_->{identifier} eq $field_id } @{ $filters->{'field'} }; + my @relavent_field_configs = grep { $_->identifier eq $field_id && $_->enabled eq 't' } @{ $filters }; # since we can't do anything complicated yet, let's just return the first match return @relavent_field_configs ? $relavent_field_configs[0] : undef; } - if (defined $filters && defined $response->{fields} && ref $response->{fields} eq 'ARRAY') { + if (defined $session_filters && defined $response->{fields} && ref $response->{fields} eq 'ARRAY') { $response->{fields} = [ grep { my $keep = 1; my @fids = keys(%{$_}); my $fid = $fids[0]; - my $field_config = find_field_config( $fid ); - if ($field_config && defined $field_config->{remove}) { - if (($field_config->{remove} =~ /true|y|yes/i)) { # test truthiness - $keep = 0; # strip the entire field - } + my $field_config = find_field_config( $session_filters, $fid ); + if ($field_config && $field_config->strip eq 't') { + $keep = 0; # strip the entire field } $keep; # or not } map { my @fids = keys(%{$_}); my $fid = $fids[0]; - my $field_config = find_field_config( $fid ); - $field_config && defined $field_config->{replace_with} - ? { $fid => $field_config->{replace_with} } + my $field_config = find_field_config( $session_filters, $fid ); + $field_config && defined $field_config->replace_with + ? { $fid => $field_config->replace_with } : $_; } @{ $response->{fields} } diff --git a/Open-ILS/src/sql/Pg/410.schema.sip.sql b/Open-ILS/src/sql/Pg/410.schema.sip.sql index c07bdcffe1..e94b8fa4eb 100644 --- a/Open-ILS/src/sql/Pg/410.schema.sip.sql +++ b/Open-ILS/src/sql/Pg/410.schema.sip.sql @@ -49,5 +49,15 @@ CREATE TABLE sip.screen_message ( message TEXT NOT NULL ); +CREATE TABLE sip.filter ( + id SERIAL PRIMARY KEY, + enabled BOOLEAN NOT NULL DEFAULT FALSE, + setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id) + ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + identifier TEXT NOT NULL, + strip BOOLEAN NOT NULL DEFAULT FALSE, + replace_with TEXT +); + COMMIT; diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.sip-filters.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.sip-filters.sql new file mode 100644 index 0000000000..fe84200fd5 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.sip-filters.sql @@ -0,0 +1,18 @@ + +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); + +CREATE TABLE sip.filter ( + id SERIAL PRIMARY KEY, + enabled BOOLEAN NOT NULL DEFAULT FALSE, + setting_group INTEGER NOT NULL REFERENCES sip.setting_group (id) + ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + identifier TEXT NOT NULL, + strip BOOLEAN NOT NULL DEFAULT FALSE, + replace_with TEXT +); + +COMMIT; + +