[open-ils-commits] r7668 - in trunk/Open-ILS/src: extras perlmods/OpenILS/Application

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Aug 15 10:43:25 EDT 2007


Author: erickson
Date: 2007-08-15 10:39:25 -0400 (Wed, 15 Aug 2007)
New Revision: 7668

Modified:
   trunk/Open-ILS/src/extras/ils_events.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
added support for patron search-by-location-and-depth to patron search api
added support for user_org_unit_opt_in handling
 - checking to see if it's globally enabled
 - checking to see if a patron has opted-in at the current workstation org
 - creating an opt-in record for a patron



Modified: trunk/Open-ILS/src/extras/ils_events.xml
===================================================================
--- trunk/Open-ILS/src/extras/ils_events.xml	2007-08-15 14:10:18 UTC (rev 7667)
+++ trunk/Open-ILS/src/extras/ils_events.xml	2007-08-15 14:39:25 UTC (rev 7668)
@@ -547,6 +547,9 @@
 	<event code='1639' textcode='REPORTER_SCHEDULE_NOT_FOUND'>
 		<desc xml:lang='en-US'>The requested reporter_schedule was not found</desc>
 	</event>
+	<event code='1640' textcode='ACTOR_USR_ORG_UNIT_OPT_IN_NOT_FOUND'>
+		<desc xml:lang='en-US'>The requested actor_usr_org_unit_opt_in was not found</desc>
+	</event>
 
 
 

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2007-08-15 14:10:18 UTC (rev 7667)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2007-08-15 14:39:25 UTC (rev 7668)
@@ -16,6 +16,7 @@
 use OpenILS::Utils::ModsParser;
 use OpenSRF::Utils::Logger qw/$logger/;
 use OpenSRF::Utils qw/:datetime/;
+use OpenSRF::Utils::SettingsClient;
 
 use OpenSRF::Utils::Cache;
 
@@ -1153,13 +1154,15 @@
 	method	=> "patron_adv_search",
 	api_name	=> "open-ils.actor.patron.search.advanced" );
 sub patron_adv_search {
-	my( $self, $client, $auth, $search_hash, $search_limit, $search_sort, $include_inactive ) = @_;
+	my( $self, $client, $auth, $search_hash, 
+        $search_limit, $search_sort, $include_inactive, $search_depth ) = @_;
+
 	my $e = new_editor(authtoken=>$auth);
 	return $e->event unless $e->checkauth;
 	return $e->event unless $e->allowed('VIEW_USER');
 	return $U->storagereq(
-		"open-ils.storage.actor.user.crazy_search", 
-		$search_hash, $search_limit, $search_sort, $include_inactive);
+		"open-ils.storage.actor.user.crazy_search", $search_hash, 
+            $search_limit, $search_sort, $include_inactive, $e->requestor->ws_ou, $search_depth);
 }
 
 
@@ -2961,11 +2964,90 @@
 
 
 
+__PACKAGE__->register_method(
+    method => 'user_opt_in_enabled',
+    api_name => 'open-ils.actor.user.org_unit_opt_in.enabled',
+    signature => q/
+        @return 1 if user opt-in is globally enabled, 0 otherwise.
+    /);
 
+sub user_opt_in_enabled {
+    my($self, $conn) = @_;
+    my $sc = OpenSRF::Utils::SettingsClient->new;
+    return 1 if lc($sc->config_value(share => user => 'opt_in')) eq 'true'; 
+    return 0;
+}
+    
 
+__PACKAGE__->register_method(
+    method => 'user_opt_in_at_org',
+    api_name => 'open-ils.actor.user.org_unit_opt_in.check',
+    signature => q/
+        @param $auth The auth token
+        @param user_id The ID of the user to test
+        @return 1 if the user has opted in at the specified org,
+            event on error, and 0 otherwise. /);
+sub user_opt_in_at_org {
+    my($self, $conn, $auth, $user_id) = @_;
 
+    # see if we even need to enforce the opt-in value
+    return 1 unless $self->user_opt_in_enabled;
 
+	my $e = new_editor(authtoken => $auth);
+	return $e->event unless $e->checkauth;
+    my $org_id = $e->requestor->ws_ou;
 
+    my $user = $e->retrieve_actor_user($user_id) or return $e->event;
+	return $e->event unless $e->allowed('VIEW_USER', $user->home_ou);
 
+    # user is automatically opted-in at the home org
+    return 1 if $user->home_ou eq $org_id;
+
+    my $vals = $e->search_actor_usr_org_unit_opt_in(
+        {org_unit=>$org_id, usr=>$user_id},{idlist=>1});
+
+    return 1 if @$vals;
+    return 0;
+}
+
+__PACKAGE__->register_method(
+    method => 'create_user_opt_in_at_org',
+    api_name => 'open-ils.actor.user.org_unit_opt_in.create',
+    signature => q/
+        @param $auth The auth token
+        @param user_id The ID of the user to test
+        @return The ID of the newly created object, event on error./);
+
+sub create_user_opt_in_at_org {
+    my($self, $conn, $auth, $user_id) = @_;
+
+	my $e = new_editor(authtoken => $auth, xact=>1);
+	return $e->die_event unless $e->checkauth;
+    my $org_id = $e->requestor->ws_ou;
+
+    my $user = $e->retrieve_actor_user($user_id) or return $e->die_event;
+	return $e->die_event unless $e->allowed('UPDATE_USER', $user->home_ou);
+
+    my $opt_in = Fieldmapper::actor::user_org_unit_opt_in->new;
+
+    $opt_in->org_unit($org_id);
+    $opt_in->usr($user_id);
+    $opt_in->staff($e->requestor->id);
+    $opt_in->opt_in_ts('now');
+    $opt_in->opt_in_ws($e->requestor->wsid);
+
+    $opt_in = $e->create_actor_user_org_unit_opt_in($opt_in)
+        or return $e->die_event;
+
+    $e->commit;
+
+    return $opt_in->id;
+}
+
+
+
+
+
+
 1;
 



More information about the open-ils-commits mailing list