filter configs backend
authorJason Etheridge <jason@EquinoxOLI.org>
Wed, 13 Jul 2022 11:55:18 +0000 (07:55 -0400)
committerJason Etheridge <jason@EquinoxOLI.org>
Wed, 13 Jul 2022 11:55:18 +0000 (07:55 -0400)
Signed-off-by: Jason Etheridge <jason@EquinoxOLI.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Session.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/SIP2Mediator.pm
Open-ILS/src/sql/Pg/410.schema.sip.sql
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.sip-filters.sql [new file with mode: 0644]

index 471ecd5..bbf2be2 100644 (file)
@@ -15435,9 +15435,11 @@ SELECT  usr,
                        <field name="label" reporter:datatype="text" reporter:label="Label" oils_obj:required="true"/>
                        <field name="institution" reporter:datatype="text" reporter:label="SIP Institution" oils_obj:required="true"/>
                        <field name="settings" reporter:datatype="link" reporter:label="Settings" oils_persist:virtual="true"/>
+                       <field name="filters" reporter:datatype="link" reporter:label="Filters" oils_persist:virtual="true"/>
                </fields>
                <links>
                        <link field="settings" reltype="has_many" key="setting_group" map="" class="sipset"/>
+                       <link field="filters" reltype="has_many" key="setting_group" map="" class="sipfilter"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
@@ -15531,6 +15533,30 @@ SELECT  usr,
                        </actions>
                </permacrud>
        </class>
+       <class id="sipfilter" controller="open-ils.cstore open-ils.pcrud"
+               oils_obj:fieldmapper="sip::filter" 
+               oils_persist:tablename="sip.filter" 
+               reporter:label="SIP Filter">
+               <fields oils_persist:primary="id" oils_persist:sequence="sip.filter_id_seq">
+                       <field name="id" reporter:datatype="id" reporter:label="ID" reporter:selector="name"/>
+                       <field name="enabled" reporter:datatype="bool" reporter:label="Enabled"/>
+                       <field name="setting_group" reporter:datatype="link" reporter:label="Settings Group" oils_obj:required="true" config_field="true"/>
+                       <field name="identifier" reporter:datatype="text" reporter:label="Field Identifier" oils_obj:required="true"/>
+                       <field name="strip" reporter:datatype="bool" reporter:label="Strip Field" />
+                       <field name="replace_with" reporter:datatype="text" reporter:label="Replacement Field Value" />
+               </fields>
+               <links>
+                       <link field="setting_group" reltype="has_a" key="id" map="" class="sipsetg"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="SIP_ADMIN" global_required="true"/>
+                               <retrieve permission="SIP_ADMIN" global_required="true"/>
+                               <update permission="SIP_ADMIN" global_required="true"/>
+                               <delete permission="SIP_ADMIN" global_required="true"/>
+                       </actions>
+               </permacrud>
+       </class>
 
        <!-- ********************************************************************************************************************* -->
 </IDL>
index 84f7b50..8b929cd 100644 (file)
@@ -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) = @_;
index c811980..daecc8e 100644 (file)
@@ -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} }
index c07bdcf..e94b8fa 100644 (file)
@@ -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 (file)
index 0000000..fe84200
--- /dev/null
@@ -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;
+
+