LP#1410369: Schema and supporting IDL entries
authorMike Rylander <mrylander@gmail.com>
Mon, 16 Feb 2015 17:54:40 +0000 (12:54 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 20 Feb 2015 21:58:17 +0000 (16:58 -0500)
This commit adds the table actor.usr_message,
a trigger to populate actor.usr_message as rows
get adding to actor.usr_note (or get updated to make
non-public notes become public), and new columns in
action.event_definition for specifying how to generate
user messages from A/T events.

It also copies over existing public user notes as
new, "read" user messages, as the current display
of the old user notes will be removed from TPac.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql [new file with mode: 0644]

index 4117732..685dd51 100644 (file)
@@ -1230,6 +1230,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <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="Event Repeatability Delay" name="repeat_delay"  reporter:datatype="interval"/>
+                       <field reporter:label="Message Template" name="message_template" reporter:datatype="text"/>
+                       <field reporter:label="Message Title" name="message_title" reporter:datatype="text"/>
+                       <field reporter:label="Message User Path" name="message_usr_path" reporter:datatype="text"/>
+                       <field reporter:label="Message Library Path" name="message_library_path" reporter:datatype="text"/>
                        <field reporter:label="Environment Entries" name="env" oils_persist:virtual="true"  reporter:datatype="link"/>
                        <field reporter:label="Parameters" name="params" oils_persist:virtual="true"  reporter:datatype="link"/>
@@ -2021,6 +2025,29 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="billing_location" reltype="has_a" key="id" map="" class="aou"/>
+       <class id="aum" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::usr_message" oils_persist:tablename="actor.usr_message" reporter:label="User Message">
+               <fields oils_persist:primary="id" oils_persist:sequence="actor.usr_note_id_seq">
+                       <field reporter:label="Creation Date/Time" name="create_date" reporter:datatype="timestamp"/>
+                       <field reporter:label="Read Date/Time" name="read_date" reporter:datatype="timestamp"/>
+                       <field reporter:label="Creating Library" name="sending_lib" reporter:datatype="link"/>
+                       <field reporter:label="Message ID" name="id" reporter:datatype="id" />
+                       <field reporter:label="Deleted?" name="deleted" reporter:datatype="bool"/>
+                       <field reporter:label="Title" name="title" reporter:datatype="text"/>
+                       <field reporter:label="User" name="usr" reporter:datatype="link" />
+                       <field reporter:label="Message" name="message" reporter:datatype="text"/>
+               </fields>
+               <links>
+                       <link field="usr" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="sending_lib" reltype="has_a" key="id" map="" class="aou"/>
+               </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+                       <actions> <!-- created magically, so no create action -->
+                               <retrieve permission="VIEW_USER" context_field="sending_lib" owning_user="usr"/>
+                               <update permission="UPDATE_USER" context_field="sending_lib" owning_user="usr"/>
+                               <delete permission="UPDATE_USER" context_field="sending_lib" owning_user="usr"/>
+                       </actions>
+               </permacrud>
+       </class>
        <class id="aun" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="actor::usr_note" oils_persist:tablename="actor.usr_note" reporter:label="User Note">
                <fields oils_persist:primary="id" oils_persist:sequence="actor.usr_note_id_seq">
                        <field reporter:label="Creation Date/Time" name="create_date" reporter:datatype="timestamp"/>
index 4c6d156..398736a 100644 (file)
@@ -152,6 +152,52 @@ CREATE TABLE actor.usr_note (
 CREATE INDEX actor_usr_note_usr_idx ON actor.usr_note (usr);
 CREATE INDEX actor_usr_note_creator_idx ON actor.usr_note ( creator );
+CREATE TABLE actor.usr_message (
+       id              SERIAL                          PRIMARY KEY,
+       usr             INT                             NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+       title           TEXT,                                      
+       message         TEXT                            NOT NULL,
+       create_date     TIMESTAMP WITH TIME ZONE        NOT NULL DEFAULT NOW(),
+       deleted         BOOL                            NOT NULL DEFAULT FALSE,
+       read_date       TIMESTAMP WITH TIME ZONE,
+       sending_lib     INT                             NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
+CREATE INDEX aum_usr ON actor.usr_message (usr);
+CREATE RULE protect_usr_message_delete AS
+       ON DELETE TO actor.usr_message DO INSTEAD (
+               UPDATE  actor.usr_message
+                 SET   deleted = TRUE
+                 WHERE OLD.id = actor.usr_message.id
+       );
+ALTER TALBE action_trigger.event_definition 
+       ADD COLUMN message_template TEXT,
+       ADD COLUMN message_usr_path TEXT,
+       ADD COLUMN message_library_path TEXT,
+       ADD COLUMN message_title TEXT;
+CREATE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$
+       IF NEW.pub THEN
+               IF TG_OP = 'UPDATE' THEN
+                       IF OLD.pub = TRUE THEN
+                               RETURN NEW;
+                       END IF;
+               END IF;
+               INSERT INTO actor.usr_message (usr, title, message, sending_lib)
+                       VALUES (NEW.usr, NEW.title, NEW.value, (SELECT home_ou FROM actor.usr WHERE id = NEW.creator));
+       END IF;
+       RETURN NEW;
+CREATE TRIGGER actor.convert_usr_note_to_message_tgr 
+       AFTER INSERT OR UPDATE ON actor.usr_note
+       FOR EACH ROW EXECUTE PROCEDURE actor.convert_usr_note_to_message();
 CREATE TABLE actor.usr_setting (
        id      BIGSERIAL       PRIMARY KEY,
index 396cd7d..81fce60 100644 (file)
@@ -190,6 +190,12 @@ CREATE TABLE action_trigger.event_definition (
     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.
     granularity     TEXT,   -- could specify a batch which is the only time these events should actually run
+    message_template        TEXT,
+    message_usr_path        TEXT,
+    message_library_path    TEXT,
+    message_title           TEXT,
     CONSTRAINT ev_def_owner_hook_val_react_clean_delay_once UNIQUE (owner, hook, validator, reactor, delay, delay_field),
     CONSTRAINT ev_def_name_owner_once UNIQUE (owner, name)
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.message-center.sql
new file mode 100644 (file)
index 0000000..3188441
--- /dev/null
@@ -0,0 +1,59 @@
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+CREATE TABLE actor.usr_message (
+    id          SERIAL                      PRIMARY KEY,
+    usr         INT                         NOT NULL REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED,
+    title       TEXT,
+    message     TEXT                        NOT NULL,
+    deleted     BOOL                        NOT NULL DEFAULT FALSE,
+    read_date   TIMESTAMP WITH TIME ZONE,
+    sending_lib INT                         NOT NULL REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED
+CREATE INDEX aum_usr ON actor.usr_message (usr);
+CREATE RULE protect_usr_message_delete AS
+    ON DELETE TO actor.usr_message DO INSTEAD (
+        UPDATE actor.usr_message
+            SET deleted = TRUE
+            WHERE OLD.id = actor.usr_message.id
+    );
+ALTER TABLE action_trigger.event_definition
+    ADD COLUMN message_template TEXT,
+    ADD COLUMN message_usr_path TEXT,
+    ADD COLUMN message_library_path TEXT,
+    ADD COLUMN message_title TEXT;
+CREATE FUNCTION actor.convert_usr_note_to_message () RETURNS TRIGGER AS $$
+    IF NEW.pub THEN
+        IF TG_OP = 'UPDATE' THEN
+            IF OLD.pub = TRUE THEN
+                RETURN NEW;
+            END IF;
+        END IF;
+        INSERT INTO actor.usr_message (usr, title, message, sending_lib)
+            VALUES (NEW.usr, NEW.title, NEW.value, (SELECT home_ou FROM actor.usr WHERE id = NEW.creator));
+    END IF;
+CREATE TRIGGER convert_usr_note_to_message_tgr
+    AFTER INSERT OR UPDATE ON actor.usr_note
+    FOR EACH ROW EXECUTE PROCEDURE actor.convert_usr_note_to_message();
+-- and copy over existing public user notes as (read) patron messages
+INSERT INTO actor.usr_message (usr, title, message, sending_lib, create_date, read_date)
+SELECT aun.usr, title, value, home_ou, aun.create_date, NOW()
+FROM actor.usr_note aun
+JOIN actor.usr au ON (au.id = aun.usr)
+WHERE aun.pub;