From c92fac0f33a417e0baf166428a13158951078516 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 6 Feb 2012 12:31:23 -0500 Subject: [PATCH] User activity tracking : user usr_activity field Added a new virtual field to actor.usr called "usr_activity". When fleshed, the value contains the most recent activities logged for the user. By default, only the most recent activity entry is fetched, however this commit also adds an org unit setting "circ.patron.usr_activity_retrieve.max" to control the number of entries returned for standard patron fleshing calls. Activity entries are fleshed in the calls: open-ils.actor.user.fleshed.retrieve open-ils.actor.user.fleshed.retrieve_by_barcode This change also updates the permacrud permission for usr_activity form VIEW_USER to RUN_REPORTS, with the assumption that any activity data beyond the configured amount (above) should be considered historical data that is not as readily accessable. Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 4 ++- .../src/perlmods/lib/OpenILS/Application/Actor.pm | 34 +++++++++++++++++++++- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 20 +++++++++++++ .../sql/Pg/upgrade/XXXX.schema.user-activity.sql | 21 +++++++++++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 7d645f1412..948ef7b44e 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -2633,6 +2633,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -2664,6 +2665,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -2699,7 +2701,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 60118d34e3..627ee87bcc 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -2955,7 +2955,8 @@ sub user_retrieve_fleshed_by_id { "addresses", "billing_address", "mailing_address", - "stat_cat_entries" ]; + "stat_cat_entries", + "usr_activity" ]; return new_flesh_user($user_id, $fields, $e); } @@ -2972,6 +2973,12 @@ sub new_flesh_user { $fetch_penalties = 1; } + my $fetch_usr_act = 0; + if(grep {$_ eq 'usr_activity'} @$fields) { + $fields = [grep {$_ ne 'usr_activity'} @$fields]; + $fetch_usr_act = 1; + } + my $user = $e->retrieve_actor_user( [ $id, @@ -3020,6 +3027,31 @@ sub new_flesh_user { ); } + # retrieve the most recent usr_activity entry + if ($fetch_usr_act) { + + # max number to return for simple patron fleshing + my $limit = $U->ou_ancestor_setting_value( + $e->requestor->ws_ou, + 'circ.patron.usr_activity_retrieve.max'); + + my $opts = { + flesh => 1, + flesh_fields => {auact => ['etype']}, + order_by => {auact => 'event_time DESC'}, + }; + + # 0 == none, <0 == return all + $limit = 1 unless defined $limit; + $opts->{limit} = $limit if $limit > 0; + + $user->usr_activity( + ($limit == 0) ? + [] : # skip the DB call + $e->search_actor_usr_activity([{usr => $user->id}, $opts]) + ); + } + $e->rollback; $user->clear_passwd(); return $user; diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index bfd2ddea89..fb02f93fe6 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -11346,3 +11346,23 @@ INSERT INTO config.usr_activity_type (id, ewho, ewhat, ehow, egroup, label) VALU -- reserve the first 1000 slots SELECT SETVAL('config.usr_activity_type_id_seq'::TEXT, 1000); +INSERT INTO config.org_unit_setting_type + (name, label, description, grp, datatype) + VALUES ( + 'circ.patron.usr_activity_retrieve.max', + oils_i18n_gettext( + 'circ.patron.usr_activity_retrieve.max', + 'Max user activity entries to retrieve (staff client)', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.patron.usr_activity_retrieve.max', + 'Sets the maxinum number of recent user activity entries to retrieve for display in the staff client. 0 means show none, -1 means show all. Default is 1.', + 'coust', + 'description' + ), + 'gui', + 'integer' + ); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql index 30b33960a5..de8cc5eb7d 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql @@ -126,6 +126,27 @@ INSERT INTO config.usr_activity_type (id, ewho, ewhat, ehow, egroup, label) VALU -- reserve the first 1000 slots SELECT SETVAL('config.usr_activity_type_id_seq'::TEXT, 1000); +INSERT INTO config.org_unit_setting_type + (name, label, description, grp, datatype) + VALUES ( + 'circ.patron.usr_activity_retrieve.max', + oils_i18n_gettext( + 'circ.patron.usr_activity_retrieve.max', + 'Max user activity entries to retrieve (staff client)', + 'coust', + 'label' + ), + oils_i18n_gettext( + 'circ.patron.usr_activity_retrieve.max', + 'Sets the maxinum number of recent user activity entries to retrieve for display in the staff client. 0 means show none, -1 means show all. Default is 1.', + 'coust', + 'description' + ), + 'gui', + 'integer' + ); + + COMMIT; /* -- 2.11.0