adding support for user-opt-in when allowed on the event definition
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Nov 2009 18:23:03 +0000 (18:23 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 13 Nov 2009 18:23:03 +0000 (18:23 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@14907 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Trigger.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/400.schema.action_trigger.sql
Open-ILS/src/sql/Pg/upgrade/0083.schema.action_trigger.event_definition.opt_in.sql [new file with mode: 0644]

index 35a1ed8..273f4da 100644 (file)
@@ -693,6 +693,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Template" name="template"  reporter:datatype="text"/>
                        <field reporter:label="Name" name="name"  reporter:datatype="text"/>
                        <field reporter:label="Granularity" name="granularity"  reporter:datatype="text"/>
+                       <field reporter:label="Opt-In User Field" name="usr_field"  reporter:datatype="text"/>
+                       <field reporter:label="Opt-In Setting Type" name="opt_in_setting"  reporter:datatype="link"/>
                        <field reporter:label="Environmet Entries" name="env" oils_persist:virtual="true"  reporter:datatype="link"/>
                        <field reporter:label="Parameters" name="params" oils_persist:virtual="true"  reporter:datatype="link"/>
                </fields>
@@ -705,6 +707,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="cleanup_failure" reltype="has_a" key="module" map="" class="atclean"/>
                        <link field="env" reltype="has_many" key="event_def" map="" class="atenv"/>
                        <link field="params" reltype="has_many" key="event_def" map="" class="atevparam"/>
+                       <link field="opt_in_setting" reltype="has_a" key="name" map="" class="cust"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
@@ -1106,11 +1109,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        <class id="aus" controller="open-ils.cstore" oils_obj:fieldmapper="actor::user_setting" oils_persist:tablename="actor.usr_setting" reporter:label="User Setting">
                <fields oils_persist:primary="id" oils_persist:sequence="actor.usr_setting_id_seq">
                        <field reporter:label="Setting ID" name="id" reporter:datatype="id" />
-                       <field reporter:label="Name" name="name" reporter:datatype="text"/>
+                       <field reporter:label="Name" name="name" reporter:datatype="link"/>
                        <field reporter:label="User" name="usr" reporter:datatype="link"/>
                        <field reporter:label="Value" name="value" reporter:datatype="text"/>
                </fields>
                <links>
+                       <link field="name" reltype="has_a" key="name" map="" class="cust"/>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
                </links>
        </class>
@@ -1736,6 +1740,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
        </class>
 
+       <class id="cust" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::usr_setting_type" oils_persist:tablename="config.usr_setting_type" reporter:label="User Setting Type">
+               <fields oils_persist:primary="name">
+                       <field name="name" reporter:datatype="text"/>
+                       <field name="label" reporter:datatype="text"/>
+                       <field name="description" reporter:datatype="text"/>
+                       <field name="datatype" reporter:datatype="text"/>
+                       <field name="fm_class" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="name" reltype="has_many" key="name" map="" class="aus"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions>
+                               <create permission="ADMIN_USER_SETTING_TYPE" global_required="true"/>
+                               <retrieve/>
+                               <update permission="ADMIN_USER_SETTING_TYPE" global_required="true"/>
+                               <delete permission="ADMIN_USER_SETTING_TYPE" global_required="true"/>
+                       </actions>
+               </permacrud>
+       </class>
        <class id="coust" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::org_unit_setting_type" oils_persist:tablename="config.org_unit_setting_type" reporter:label="Organizational Unit Setting Type">
                <fields oils_persist:primary="name">
                        <field name="name" reporter:datatype="text"/>
index 99c7f38..994f01e 100644 (file)
@@ -59,6 +59,21 @@ sub create_active_events_for_object {
 
     for my $def ( @$defs ) {
 
+        if ($def->usr_field && $def->opt_in_setting) {
+            my $ufield = $def->usr_field;
+            my $uid = $target->$ufield;
+            $uid = $uid->id if (ref $uid); # fleshed user object, unflesh it
+
+            my $opt_in_setting = $editor->search_actor_usr_setting(
+                { usr   => $uid,
+                  name  => $def->opt_in_setting,
+                  value => 'true'
+                }
+            );
+
+            next unless (@$opt_in_setting);
+        }
+
         my $date = DateTime->now;
 
         if ($hook_hash{$def->hook}->passive eq 'f') {
@@ -128,6 +143,21 @@ sub create_event_for_object_and_def {
 
     for my $def ( @$defs ) {
 
+        if ($def->usr_field && $def->opt_in_setting) {
+            my $ufield = $def->usr_field;
+            my $uid = $target->$ufield;
+            $uid = $uid->id if (ref $uid); # fleshed user object, unflesh it
+
+            my $opt_in_setting = $editor->search_actor_usr_setting(
+                { usr   => $uid,
+                  name  => $def->opt_in_setting,
+                  value => 'true'
+                }
+            );
+
+            next unless (@$opt_in_setting);
+        }
+
         my $date = DateTime->now;
 
         if ($hook_hash{$def->hook}->passive eq 'f') {
@@ -426,6 +456,19 @@ sub create_batch_events {
             }
         };
 
+        if ($def->usr_field && $def->opt_in_setting) {
+            push @{ $filter->{'-and'} }, {
+                '-exists' => {
+                    from  => 'aus',
+                    where => {
+                        name => $def->id,
+                        usr  => { '=' => { '+' . $hook_hash{$def->hook}->core_type => $def->usr_field } },
+                        value=> 'true'
+                    }
+                }
+            };
+        }
+
         $class =~ s/^Fieldmapper:://o;
         $class =~ s/::/_/go;
 
index 870131a..2d67552 100644 (file)
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0082'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0083'); -- miker
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index a225a51..37e2971 100644 (file)
@@ -115,6 +115,8 @@ CREATE TABLE action_trigger.event_definition (
     cleanup_failure TEXT        REFERENCES action_trigger.cleanup (module) DEFERRABLE INITIALLY DEFERRED,
     delay           INTERVAL    NOT NULL DEFAULT '5 minutes',
     max_delay       INTERVAL,
+    usr_field       TEXT,
+    opt_in_setting  TEXT        REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED,
     delay_field     TEXT,                 -- for instance, xact_start on a circ hook ... look for fields on hook.core_type where datatype=timestamp? If not set, delay from now()
     group_field     TEXT,                 -- field from this.hook.core_type to batch event targets together on, fed into reactor a group at a time.
     template        TEXT,                 -- the TT block.  will have an 'environment' hash (or array of hashes, grouped events) built up by validator and collector(s), which can be modified.
diff --git a/Open-ILS/src/sql/Pg/upgrade/0083.schema.action_trigger.event_definition.opt_in.sql b/Open-ILS/src/sql/Pg/upgrade/0083.schema.action_trigger.event_definition.opt_in.sql
new file mode 100644 (file)
index 0000000..36cfd41
--- /dev/null
@@ -0,0 +1,9 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0083');
+
+ALTER TABLE action_trigger.event_definition ADD COLUMN usr_field TEXT;
+ALTER TABLE action_trigger.event_definition ADD COLUMN opt_in_setting TEXT REFERENCES config.usr_setting_type (name) DEFERRABLE INITIALLY DEFERRED;
+
+COMMIT;
+