From aebf4a58fe8f013ce7f0e5a46d920e679287295c Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 28 Feb 2012 14:28:14 -0500 Subject: [PATCH] User Activity : SIP activity tracking 1. Log user activity for all patron-related SIP actions, regardless of whether the SIP server verifies the user password. 2. Determine the "ewho" (i.e. 3rd-party) value from configuration. Each SIP login can now specify its own "activity_who" value. Additionally, a fall-through element can be added to the institution config. Signed-off-by: Bill Erickson Signed-off-by: Thomas Berezansky --- .../perlmods/lib/OpenILS/Application/AppUtils.pm | 29 ++++++++++++++++++++++ Open-ILS/src/perlmods/lib/OpenILS/SIP.pm | 6 ++++- Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm | 21 ++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index d214274ca6..e8369ea9a9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -1934,5 +1934,34 @@ sub bib_container_items_via_search { return [map { $ordering_hash{$_} } @$id_list]; } +# returns undef on success, Event on error +sub log_user_activity { + my ($class, $user_id, $who, $what, $e, $async) = @_; + + my $commit = 0; + if (!$e) { + $e = OpenILS::Utils::CStoreEditor->new(xact => 1); + $commit = 1; + } + + my $res = $e->json_query({ + from => [ + 'actor.insert_usr_activity', + $user_id, $who, $what, OpenSRF::AppSession->ingress + ] + }); + + if ($res) { # call returned OK + + $e->commit if $commit and @$res; + $e->rollback if $commit and !@$res; + + } else { + return $e->die_event; + } + + return undef; +} + 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm index 4f62b1be1d..4774174ab6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm @@ -29,6 +29,7 @@ my $U = 'OpenILS::Application::AppUtils'; my $editor; my $config; +my $login_account; my $target_encoding; # FIXME: this is configured at the institution level. use Digest::MD5 qw(md5_hex); @@ -38,7 +39,7 @@ sub new { my $type = ref($class) || $class; my $self = {}; - $self->{login} = $login; + $self->{login} = $login_account = $login; $config = $institution; syslog("LOG_DEBUG", "OILS: new ILS '%s'", $institution->{id}); @@ -95,6 +96,9 @@ sub editor { sub config { return $config; } +sub login_account { + return $login_account; +} sub get_option_value { my($self, $option) = @_; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm index 832c827b92..538a6a714a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm @@ -118,9 +118,30 @@ sub new { syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s => %s): found patron : barred=%s, card:active=%s", $key, $patron_id, $user->barred, $user->card->active ); + $U->log_user_activity($user->id, $self->get_act_who, 'verify'); + return $self; } +sub get_act_who { + my $self = shift; + my $config = OpenILS::SIP->config(); + my $login = OpenILS::SIP->login_account(); + + my $act_who = $config->{implementation_config}->{default_activity_who}; + my $force_who = $config->{implementation_config}->{force_activity_who}; + + # 1. future: test sip extension for caller-provided ewho and !$force_who + + # 2. See if the login is tagged with an ewho + return $login->{activity_who} if $login->{activity_who}; + + # 3. if all else fails, see if there is an institution-wide ewho + return $config->{activity_who} if $config->{activity_who}; + + return undef; +} + # grab patron penalties. Only grab non-archived penalties that are for fines, # excessive overdues, or otherwise block circluation activity sub flesh_user_penalties { -- 2.11.0