add home ou to aupsd so it can be used as a context org for passive
authorLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Wed, 29 Jun 2022 20:33:11 +0000 (16:33 -0400)
committerLlewellyn Marshall <llewellyn.marshall@ncdcr.gov>
Fri, 1 Jul 2022 19:50:33 +0000 (15:50 -0400)
event filter. change to passive event for password change

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/xxxx.data.password_age_reset.sql

index 91c3915..8ad8019 100644 (file)
@@ -2411,15 +2411,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        </class>
        <class id="aupsd" controller="open-ils.cstore" oils_obj:fieldmapper="actor::usr_password_set_date" reporter:label="User Password Set Date" oils_persist:readonly="true">
                <oils_persist:source_definition><![CDATA[
-                       SELECT usr,create_date,edit_date FROM actor.passwd
+                       SELECT ac.id, ac.usr as usr, au.home_ou as home_ou, ac.create_date as create_date, ac.edit_date as edit_date 
+            FROM actor.passwd ac 
+            JOIN actor.usr au on au.id = ac.usr 
                ]]></oils_persist:source_definition>
                <fields oils_persist:primary="id">
             <field reporter:label="User ID" name="usr" reporter:datatype="id" />
+            <field reporter:label="User Home OU" name="home_ou" reporter:datatype="id" />
                        <field reporter:label="Create Date" name="create_date" reporter:datatype="timestamp"/>
                        <field reporter:label="Last Edit Date" name="edit_date" reporter:datatype="timestamp"/>
                </fields>
                <links>
                        <link field="usr" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="home_ou" reltype="has_a" key="id" map="" class="aou"/>
                </links>
        </class>
        <class id="aupr" controller="open-ils.cstore" oils_obj:fieldmapper="actor::usr_password_reset" oils_persist:tablename="actor.usr_password_reset" reporter:label="User password reset requests">
index 432cacd..9ad9956 100644 (file)
@@ -525,7 +525,6 @@ sub update_patron {
     my $old_patron;
     my $barred_hook = '';
     my $renew_hook = '';
-    my $password_hook = '';
 
     if($patron->isnew()) {
         ( $new_patron, $evt ) = _add_patron($e, _clone_patron($patron));
@@ -556,8 +555,6 @@ sub update_patron {
             modify_migrated_user_password($e, $patron->id, $patron->passwd);
             $new_patron->passwd(''); # subsequent update will set
                                      # actor.usr.passwd to MD5('')
-            #$U->create_events_for_hook('au.passwd_changed', $db_user, $e->requestor->ws_ou);
-            $password_hook = 'au.passwd_changed';
         }
     }
 
@@ -606,9 +603,6 @@ sub update_patron {
 
         $tses->request('open-ils.trigger.event.autocreate', $barred_hook,
             $new_patron, $new_patron->home_ou) if $barred_hook;
-
-        $tses->request('open-ils.trigger.event.autocreate', $password_hook,
-            $new_patron, $new_patron->home_ou) if $password_hook;
     }
 
     $e->xact_begin; # $e->rollback is called in new_flesh_user
@@ -1658,7 +1652,7 @@ sub update_passwd {
         # would be required.  Noting here for future reference.
         modify_migrated_user_password($e, $db_user->id, $new_val);     
         $db_user->passwd('');
-        $U->create_events_for_hook('au.passwd_changed', $db_user, $e->requestor->ws_ou);
+
     } else {
 
         # if we don't clear the password, the user will be updated with
@@ -4433,8 +4427,7 @@ sub commit_password_reset {
 
     # All is well; update the password
     modify_migrated_user_password($e, $user->id, $password);
-    $U->create_events_for_hook('au.passwd_changed', $user, $user->home_ou);
-    
+
     # And flag that this password reset request has been honoured
     $aupr->[0]->has_been_reset('t');
     $e->update_actor_usr_password_reset($aupr->[0]);
index 6be4329..ad4e4f4 100644 (file)
@@ -166,35 +166,6 @@ sub PatronNotBarred {
     return !PatronBarred(@_);
 }
 
-# returns invalid if the patron's password was updated in the time
-# between now and the parent event being created
-sub PatronOldPassword {
-    my ($self, $env) = @_;
-    my $event = $env->{event};
-    # get add time of the event 
-    my $add_time = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($event->add_time));
-    # get the last time the user changed their password
-    my $aupsds = new_editor()->json_query({
-        select => {aupsd => ['create_date','edit_date']},
-        from => 'aupsd',
-        where => {
-            usr => $env->{target}->id
-        }
-    });
-
-    if(defined $aupsds){
-        my $pwd = $aupsds->[0];
-        #convert the dates with the DateTime module
-        if($pwd){
-            my $edit_datetime = DateTime::Format::ISO8601->parse_datetime(clean_ISO8601($pwd->{'edit_date'}));
-            # if the change time is after the add time, return invalid
-            return $edit_datetime <= $add_time;         
-        }
-    }    
-    
-    return 1;
-}
-
 # core type "circ".
 # Being "In Collections" means having the PATRON_IN_COLLECTIONS penalty 
 # applied to the user at or above the circ_lib of the target circ.
index f7fd081..2a12e46 100644 (file)
@@ -21329,14 +21329,41 @@ INSERT INTO config.org_unit_setting_type
     );
 
 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
-    'au.passwd_changed',
-    'au',
-    'An account password was updated',
-       false
+    'aupsd.passwd_changed',
+    'aupsd',
+    oils_i18n_gettext(
+        'au.passwd_changed',
+        'An account password was updated',
+        'ath',
+        'description'
+    ),
+       true
 );
 
-INSERT INTO action_trigger.validator (module, description) VALUES (
-    'PatronOldPassword', 'Confirm that the patron has not updated their password since this event was created.'
+-- Sample Password Update Notice --
+
+INSERT INTO action_trigger.event_definition (active, owner, name, delay_field, delay, max_delay, repeat_delay, hook, validator, reactor,  template) 
+    VALUES ('f', 1, 'Password Update Notice', 'edit_date','90 days', '91 days','90 days' 'aupsd.passwd_changed', 'NOOP_True', 'SendEmail',
+$$
+[%- USE date -%]
+[%- user = target.usr -%]
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender || helpers.get_org_setting(user.home_ou, 'org.bounced_emails') %]
+Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
+Subject: Password Update Required
+Auto-Submitted: auto-generated
+
+Dear [% user.family_name %], [% user.first_given_name %]
+Regularly updating your password is an essential part of maintaining the security of your account. At the time of writing, your password is 90 days old. Please log in to the system or contact a system administrator to update your password. 
+
+$$);
+
+INSERT INTO action_trigger.environment (
+    event_def,
+    path
+) VALUES (
+    currval('action_trigger.event_definition_id_seq'),
+    'usr'
 );
 
 ------------------- Disabled example A/T defintions ------------------------------
index 01cdafd..9a7ce68 100644 (file)
@@ -1,6 +1,6 @@
 BEGIN;
 
---SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
 
 -- password age display setting
 
@@ -26,15 +26,41 @@ INSERT INTO config.org_unit_setting_type
     );
 
 INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
-    'au.passwd_changed',
-    'au',
-    'An account password was updated',
-       false
+    'aupsd.passwd_changed',
+    'aupsd',
+    oils_i18n_gettext(
+        'au.passwd_changed',
+        'An account password was updated',
+        'ath',
+        'description'
+    ),
+       true
 );
 
-INSERT INTO action_trigger.validator (module, description) VALUES (
-    'PatronOldPassword', 'Confirm that the patron has not updated their password since this event was created.'
-);
+-- Sample Password Update Notice --
+
+INSERT INTO action_trigger.event_definition (active, owner, name, delay_field, delay, max_delay, repeat_delay, hook, validator, reactor,  template) 
+    VALUES ('f', 1, 'Password Update Notice', 'edit_date','90 days', '91 days','90 days' 'aupsd.passwd_changed', 'NOOP_True', 'SendEmail',
+$$
+[%- USE date -%]
+[%- user = target.usr -%]
+To: [%- params.recipient_email || user.email %]
+From: [%- params.sender_email || default_sender || helpers.get_org_setting(user.home_ou, 'org.bounced_emails') %]
+Date: [%- date.format(date.now, '%a, %d %b %Y %T -0000', gmt => 1) %]
+Subject: Password Update Required
+Auto-Submitted: auto-generated
+
+Dear [% user.family_name %], [% user.first_given_name %]
+Regularly updating your password is an essential part of maintaining the security of your account. At the time of writing, your password is 90 days old. Please log in to the system or contact a system administrator to update your password. 
 
+$$);
+
+INSERT INTO action_trigger.environment (
+    event_def,
+    path
+) VALUES (
+    currval('action_trigger.event_definition_id_seq'),
+    'usr'
+);
 --ROLLBACK;
 COMMIT;
\ No newline at end of file