LP#1356477: create new staging table for user settings
authorGalen Charlton <gmc@esilibrary.com>
Wed, 3 Aug 2016 19:37:39 +0000 (15:37 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 24 Aug 2016 21:58:27 +0000 (17:58 -0400)
This patch creates a new table called staging.setting_stage
that allows for storing user settings when a patron uses
(for example) the self-registration page.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Stage.pm
Open-ILS/src/sql/Pg/015.schema.staging.sql
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.staging-user-setting.sql [new file with mode: 0644]

index 65dc4db..485e4c6 100644 (file)
@@ -9608,6 +9608,17 @@ SELECT  usr,
         </fields>
     </class>
 
+    <class id="stgs" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="staging::setting_stage" oils_persist:tablename="staging.setting_stage" reporter:label="User Setting Stage">
+        <fields oils_persist:primary="row_id" oils_persist:sequence="staging.setting_stage_row_id_seq">
+            <field reporter:label="Row ID" name="row_id" reporter:datatype="id"/>
+            <field reporter:label="Row Date" name="row_date" reporter:datatype="timestamp"/>
+            <field reporter:label="User Name" name="usrname" reporter:datatype="text"/>
+            <field reporter:label="User Setting Code" name="setting" reporter:datatype="text"/>
+            <field reporter:label="User Setting Value" name="value" reporter:datatype="text"/>
+            <field reporter:label="Complete" name="complete" reporter:datatype="bool"/>
+        </fields>
+    </class>
+
        <class id="afs" controller="open-ils.cstore" oils_obj:fieldmapper="action::fieldset" oils_persist:tablename="action.fieldset" reporter:label="Fieldset">
                <fields oils_persist:primary="id" oils_persist:sequence="action.fieldset_id_seq">
                        <field reporter:label="Fieldset ID" name="id" reporter:datatype="id"/>
index 8f094b7..c8be321 100644 (file)
@@ -13,7 +13,8 @@ __PACKAGE__->register_method (
     api_name    => 'open-ils.actor.user.stage.create',
     signature => {
         desc => q/
-            Creates a new pending user account including addresses and statcats.
+            Creates a new pending user account including addresses, statcats, and
+            settings.
             Users are added to staging tables pending staff review.
         /,
         params => [
@@ -21,6 +22,7 @@ __PACKAGE__->register_method (
             {desc => 'Mailing address.  Optional', type => 'object', class => 'stgma'},
             {desc => 'Billing address.  Optional', type => 'object', class => 'stgba'},
             {desc => 'Statcats.  Optional.  This is an array of "stgsc" objects', type => 'array'},
+            {desc => 'Settings.  Optional.  This is an array of "stgs" objects', type => 'array'},
         ],
         return => {
             desc => 'username on success, Event on error',
@@ -31,7 +33,7 @@ __PACKAGE__->register_method (
 );
 
 sub create_user_stage {
-    my($self, $conn, $user, $mail_addr, $bill_addr, $statcats) = @_; # more?
+    my($self, $conn, $user, $mail_addr, $bill_addr, $statcats, $settings) = @_; # more?
 
     return OpenILS::Event->new('BAD_PARAMS') unless $user;
     return 0 unless $U->ou_ancestor_setting_value($user->home_ou, 'opac.allow_pending_user');
@@ -64,6 +66,13 @@ sub create_user_stage {
         }
     }
 
+    if($settings) {
+        foreach (@$settings) {
+            $_->usrname($uname);
+            $e->create_staging_setting_stage($_) or return $e->die_event;
+        }
+    }
+
     $e->commit;
     $conn->respond_complete($uname);
 
@@ -111,7 +120,8 @@ sub flesh_user_stage {
         billing_addresses => $e->search_staging_billing_address_stage({usrname => $user->usrname}),
         mailing_addresses => $e->search_staging_mailing_address_stage({usrname => $user->usrname}),
         cards => $e->search_staging_card_stage({usrname => $user->usrname}),
-        statcats => $e->search_staging_statcat_stage({usrname => $user->usrname})
+        statcats => $e->search_staging_statcat_stage({usrname => $user->usrname}),
+        settings => $e->search_staging_setting_stage({usrname => $user->usrname}),
     };
 }
 
@@ -171,6 +181,10 @@ sub delete_user_stage {
         $e->delete_staging_statcat_stage($statcat) or return $e->die_event;
     }
 
+    for my $setting (@{$data->{settings}}) {
+        $e->delete_staging_setting_stage($setting) or return $e->die_event;
+    }
+
     $e->commit;
     return 1;
 }
index 3f558e1..4dfc3ee 100644 (file)
@@ -60,6 +60,15 @@ CREATE TABLE staging.statcat_stage (
         complete        BOOL DEFAULT FALSE
 );
 
+CREATE TABLE staging.setting_stage (
+        row_id          BIGSERIAL PRIMARY KEY,
+        row_date        TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
+        usrname         TEXT NOT NULL,
+        setting         TEXT NOT NULL,
+        value           TEXT NOT NULL,
+        complete        BOOL DEFAULT FALSE
+);
+
 -- stored procedure for deleting expired pending patrons
 CREATE OR REPLACE FUNCTION staging.purge_pending_users() RETURNS VOID AS $$
 DECLARE
diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.staging-user-setting.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.schema.staging-user-setting.sql
new file mode 100644 (file)
index 0000000..55908ad
--- /dev/null
@@ -0,0 +1,12 @@
+BEGIN;
+
+CREATE TABLE staging.setting_stage (
+        row_id          BIGSERIAL PRIMARY KEY,
+        row_date        TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
+        usrname         TEXT NOT NULL,
+        setting         TEXT NOT NULL,
+        value           TEXT NOT NULL,
+        complete        BOOL DEFAULT FALSE
+);
+
+COMMIT;