LP#1915219: opt-in setting for overdue and predue emails
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Wed, 10 Feb 2021 00:31:52 +0000 (16:31 -0800)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 4 Mar 2021 15:44:18 +0000 (10:44 -0500)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Garry Collum <gcollum@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.overdue-email-opt-in-setting.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/Circulation/overdue-email-opt-in-setting.adoc [new file with mode: 0644]

index 3fd6d82..500d8a5 100644 (file)
@@ -3024,6 +3024,34 @@ INSERT INTO config.usr_setting_type (name,opac_visible,label,description,datatyp
         'string'
     );
 
+INSERT INTO config.usr_setting_type (
+    name,
+    opac_visible,
+    label,
+    description,
+    grp,
+    datatype,
+    reg_default
+) VALUES (
+    'circ.default_overdue_notices_enabled',
+    TRUE,
+    oils_i18n_gettext(
+        'circ.default_overdue_notices_enabled',
+        'Receive Overdue and Courtesy Emails',
+        'cust',
+        'label'
+    ),
+    oils_i18n_gettext(
+        'circ.default_overdue_notices_enabled',
+        'Receive overdue and predue email notifications',
+        'cust',
+        'description'
+    ),
+    'circ',
+    'bool',
+    'true'
+);
+
 -- Add groups for org_unit settings
 INSERT INTO config.settings_group (name, label) VALUES
 ('acq', oils_i18n_gettext('acq', 'Acquisitions', 'csg', 'label')),
@@ -9475,8 +9503,8 @@ INSERT INTO config.composite_attr_entry_definition (coded_value, definition) VAL
 
 -- Sample Overdue Notice --
 
-INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, template) 
-    VALUES (1, 'f', 1, '7 Day Overdue Email Notification', 'checkout.due', 'CircIsOverdue', 'SendEmail', '7 days', 'due_date', 'usr', '8 days', 
+INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, opt_in_setting, usr_field, template)
+    VALUES (1, 'f', 1, '7 Day Overdue Email Notification', 'checkout.due', 'CircIsOverdue', 'SendEmail', '7 days', 'due_date', 'usr', '8 days', 'circ.default_overdue_notices_enabled', 'usr',
 $$
 [%- USE date -%]
 [%- user = target.0.usr -%]
@@ -10832,8 +10860,8 @@ INSERT INTO config.record_attr_index_norm_map (attr,norm,pos)
 
 -- Sample Pre-due Notice --
 
-INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, template) 
-    VALUES (6, 'f', 1, '3 Day Courtesy Notice', 'checkout.due', 'CircIsOpen', 'SendEmail', '-3 days', 'due_date', 'usr', '-2 days',
+INSERT INTO action_trigger.event_definition (id, active, owner, name, hook, validator, reactor, delay, delay_field, group_field, max_delay, opt_in_setting, usr_field, template)
+    VALUES (6, 'f', 1, '3 Day Courtesy Notice', 'checkout.due', 'CircIsOpen', 'SendEmail', '-3 days', 'due_date', 'usr', '-2 days', 'circ.default_overdue_notices_enabled', 'usr',
 $$
 [%- USE date -%]
 [%- user = target.0.usr -%]
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.overdue-email-opt-in-setting.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.overdue-email-opt-in-setting.sql
new file mode 100644 (file)
index 0000000..ddae2ef
--- /dev/null
@@ -0,0 +1,64 @@
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+INSERT INTO config.usr_setting_type (
+    name,
+    opac_visible,
+    label,
+    description,
+    grp,
+    datatype,
+    reg_default
+) VALUES (
+    'circ.default_overdue_notices_enabled',
+    TRUE,
+    oils_i18n_gettext(
+        'circ.default_overdue_notices_enabled',
+        'Receive Overdue and Courtesy Emails',
+        'cust',
+        'label'
+    ),
+    oils_i18n_gettext(
+        'circ.default_overdue_notices_enabled',
+        'Receive overdue and predue email notifications',
+        'cust',
+        'description'
+    ),
+    'circ',
+    'bool',
+    'true'
+);
+
+COMMIT;
+
+\qecho
+\qecho The following query will set the circ.default_overdue_notices_enabled
+\qecho user setting to true (the default value) for all existing users,
+\qecho ensuring they continue to receive overdue/predue emails.
+\qecho
+\qecho     INSERT INTO actor.usr_setting (usr, name, value)
+\qecho     SELECT
+\qecho         id,
+\qecho         'circ.default_overdue_notices_enabled',
+\qecho         'true'
+\qecho     FROM actor.usr;
+\qecho
+\qecho The following query will add the circ.default_overdue_notices_enabled
+\qecho user setting as an opt-in setting for all action triggers that send
+\qecho emails based on a circ being due (unless another opt-in setting is
+\qecho already in use).
+\qecho
+\qecho     UPDATE action_trigger.event_definition
+\qecho     SET opt_in_setting = 'circ.default_overdue_notices_enabled',
+\qecho         usr_field = 'usr'
+\qecho     WHERE opt_in_setting IS NULL
+\qecho         AND hook = 'checkout.due'
+\qecho         AND reactor = 'SendEmail';
+\qecho
+\qecho Evergreen admins who wish to use the new setting should run both of
+\qecho the above queries.  Admins who do not wish to use it, or who are
+\qecho already using a custom opt-in setting of their own, do not need to
+\qecho do anything.
+\qecho
+
diff --git a/docs/RELEASE_NOTES_NEXT/Circulation/overdue-email-opt-in-setting.adoc b/docs/RELEASE_NOTES_NEXT/Circulation/overdue-email-opt-in-setting.adoc
new file mode 100644 (file)
index 0000000..4ba9969
--- /dev/null
@@ -0,0 +1,36 @@
+Opt-In Setting for Overdue and Predue Emails
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The "Receive Overdue and Courtesy Emails" user setting permits users to
+control whether they receive email notifications about overdue items.
+
+To use the setting, modify any action trigger event definitions which
+send emails about overdue items, setting the "Opt In Setting" to
+"circ.default_overdue_notices_enabled" and the "User Field" to "usr".
+You can accomplish this by running the following query in your database:
+
+----
+UPDATE action_trigger.event_definition
+SET opt_in_setting = 'circ.default_overdue_notices_enabled',
+    usr_field = 'usr'
+WHERE opt_in_setting IS NULL
+    AND hook = 'checkout.due'
+    AND reactor = 'SendEmail';
+----
+
+Once this is done, the patron registration screen in the staff client
+will show a "Receive Overdue and Courtesy Emails" checkbox, which will
+be checked by default.  To ensure that existing patrons continue to
+recieve email notifications, you will need to add the user setting to
+their accounts, which you can do by running the following query in your
+database:
+
+----
+INSERT INTO actor.usr_setting (usr, name, value)
+SELECT
+    id,
+    'circ.default_overdue_notices_enabled',
+    'true'
+FROM actor.usr;
+----
+
+