User activity tracking : user usr_activity field
authorBill Erickson <berick@esilibrary.com>
Mon, 6 Feb 2012 17:31:23 +0000 (12:31 -0500)
committerThomas Berezansky <tsbere@mvlc.org>
Thu, 8 Mar 2012 18:50:06 +0000 (13:50 -0500)
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 <retrieve> 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 <berick@esilibrary.com>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql

index 237c8c2..2924bfc 100644 (file)
@@ -2703,6 +2703,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field reporter:label="Circulations Performed as Staff" name="performed_circulations" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field reporter:label="Fund Allocation Percentages" name="fund_alloc_pcts" oils_persist:virtual="true" reporter:datatype="link"/>
                        <field reporter:label="Reservations" name="reservations" oils_persist:virtual="true" reporter:datatype="link"/>
+                       <field reporter:label="User Activity Entries" name="usr_activity" oils_persist:virtual="true" reporter:datatype="link"/>
                </fields>
                <links>
                        <link field="demographic" reltype="might_have" key="id" map="" class="rud"/>
@@ -2734,6 +2735,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="performed_circulations" reltype="has_many" key="circ_staff" map="" class="circ"/>
                        <link field="fund_alloc_pcts" reltype="has_many" key="allocator" map="" class="acqfap"/>
                        <link field="reservations" reltype="has_many" key="usr" map="" class="bresv"/>
+                       <link field="usr_activity" reltype="has_many" key="usr" map="" class="auact"/>
                </links>
        </class>
        <class id="cuat" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::usr_activity_type" oils_persist:tablename="config.usr_activity_type" reporter:label="User Activity Type">
@@ -2769,7 +2771,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <retrieve permission="VIEW_USER">
+                               <retrieve permission="RUN_REPORTS">
                                        <context link="usr" field="home_ou" />
                                </retrieve>
                        </actions>
index 60118d3..627ee87 100644 (file)
@@ -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;
index 2ca7c7b..94e7626 100644 (file)
@@ -11352,3 +11352,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'
+    );
+
index 30b3396..de8cc5e 100644 (file)
@@ -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;
 
 /*