my $old_patron;
my $barred_hook = '';
+ my $renew_hook = '';
if($patron->isnew()) {
( $new_patron, $evt ) = _add_patron($e, _clone_patron($patron));
$old_patron = $e->retrieve_actor_user($patron->id) or
return $e->die_event;
+ $renew_hook = 'au.renewed' if ($old_patron->expire_date ne $new_patron->expire_date);
+
if($U->is_true($old_patron->barred) != $U->is_true($new_patron->barred)) {
my $perm = $U->is_true($old_patron->barred) ? 'UNBAR_PATRON' : 'BAR_PATRON';
return $e->die_event unless $e->allowed($perm, $patron->home_ou);
my $tses = OpenSRF::AppSession->create('open-ils.trigger');
if($patron->isnew) {
$tses->request('open-ils.trigger.event.autocreate',
- 'au.create', $new_patron, $new_patron->home_ou);
+ 'au.created', $new_patron, $new_patron->home_ou);
} else {
$tses->request('open-ils.trigger.event.autocreate',
- 'au.update', $new_patron, $new_patron->home_ou);
+ 'au.updated', $new_patron, $new_patron->home_ou);
+
+ $tses->request('open-ils.trigger.event.autocreate', $renew_hook,
+ $new_patron, $new_patron->home_ou) if $renew_hook;
$tses->request('open-ils.trigger.event.autocreate', $barred_hook,
$new_patron, $new_patron->home_ou) if $barred_hook;
my $virtual_id; #id of the card before creation
+ my $card_changed = 0;
my $cards = $patron->cards();
for my $card (@$cards) {
$new_patron->card($card->id());
$new_patron->ischanged(1);
}
+ $card_changed++;
} elsif( ref($card) and $card->ischanged() ) {
$evt = _update_card($e, $card);
return (undef, $evt) if $evt;
+ $card_changed++;
}
}
+ $U->create_events_for_hook('au.barcode_changed', $new_patron, $e->requestor->ws_ou)
+ if $card_changed;
+
return ( $new_patron, undef );
}
return new OpenILS::Event('INCORRECT_PASSWORD');
}
+ my $at_event = 0;
if( $api =~ /password/o ) {
# NOTE: with access to the plain text password we could crypt
# the password without the extra MD5 pre-hashing. Other changes
return new OpenILS::Event('USERNAME_EXISTS');
}
$db_user->usrname($new_val);
+ $at_event++;
} elsif( $api =~ /email/o ) {
$db_user->email($new_val);
+ $at_event++;
}
}
$e->update_actor_user($db_user) or return $e->die_event;
$e->commit;
+ $U->create_events_for_hook('au.updated', $db_user, $e->requestor->ws_ou)
+ if $at_event;
+
# update the cached user to pick up these changes
$U->simplereq('open-ils.auth', 'open-ils.auth.session.reset_timeout', $auth, 1);
return 1;
my $e = new_editor(authtoken => $auth, xact => 1);
return $e->die_event unless $e->checkauth;
+ my $user = $e->retrieve_actor_user($addr->usr) or return $e->die_event;
if($addr->usr != $e->requestor->id) {
- my $user = $e->retrieve_actor_user($addr->usr) or return $e->die_event;
return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou);
}
}
$e->commit;
+ $U->create_events_for_hook('au.updated', $user, $e->requestor->ws_ou);
+
return $addr->id;
}
INSERT INTO action_trigger.hook (key, core_type, description, passive)
VALUES ('au.created', 'au', 'A user was created', 't');
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.updated', 'au', 'A user was updated', 't');
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.barcode_changed', 'au', 'A card was updated or created for an existing user', 't');
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.renewed', 'au', 'A user was renewed by having their expire date changed', 't');
+
--SQL to create event definition for new account creation notice
--Inactive, owned by top of org tree by default. Modify to suit needs.
--- /dev/null
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- First, normalize the au.create[d] and au.update[d] hooks. The code and seed data differ.
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.created', 'au', 'A user was created', 't') ON CONFLICT DO NOTHING;
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.updated', 'au', 'A user was updated', 't') ON CONFLICT DO NOTHING;
+
+
+UPDATE action_trigger.event_definition SET hook = 'au.created' WHERE hook = 'au.create';
+UPDATE action_trigger.event_definition SET hook = 'au.updated' WHERE hook = 'au.update';
+
+DELETE FROM action_trigger.hook WHERE key = 'au.create';
+DELETE FROM action_trigger.hook WHERE key = 'au.update';
+
+-- Now the entirely new ones...
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.renewed', 'au', 'A user was renewed by having their expire date changed', 't');
+
+INSERT INTO action_trigger.hook (key, core_type, description, passive)
+ VALUES ('au.barcode_changed', 'au', 'A card was updated or created for an existing user', 't');
+
+COMMIT;