[open-ils-commits] r8648 - branches/rel_1_2_1/Open-ILS/src/perlmods/OpenILS/Application

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Feb 5 17:57:44 EST 2008


Author: erickson
Date: 2008-02-05 17:29:22 -0500 (Tue, 05 Feb 2008)
New Revision: 8648

Modified:
   branches/rel_1_2_1/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
backport fixes to workstation registration -- we no longer delete workstations when using .override

Modified: branches/rel_1_2_1/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- branches/rel_1_2_1/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2008-02-05 20:00:37 UTC (rev 8647)
+++ branches/rel_1_2_1/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2008-02-05 22:29:22 UTC (rev 8648)
@@ -2443,41 +2443,41 @@
 		if the name is already in use.
 	/);
 
-sub _register_workstation {
-	my( $self, $connection, $authtoken, $name, $owner ) = @_;
-	my( $requestor, $evt ) = $U->checkses($authtoken);
-	return $evt if $evt;
-	$evt = $U->check_perms($requestor->id, $owner, 'REGISTER_WORKSTATION');
-	return $evt if $evt;
+sub register_workstation {
+	my( $self, $conn, $authtoken, $name, $owner ) = @_;
 
-	my $ws = $U->cstorereq(
-		'open-ils.cstore.direct.actor.workstation.search', { name => $name } );
-	return OpenILS::Event->new('WORKSTATION_NAME_EXISTS') if $ws;
+	my $e = new_editor(authtoken=>$authtoken, xact=>1);
+	return $e->die_event unless $e->checkauth;
+	return $e->die_event unless $e->allowed('REGISTER_WORKSTATION', $owner);
+	my $existing = $e->search_actor_workstation({name => $name})->[0];
 
-	$ws = Fieldmapper::actor::workstation->new;
-	$ws->owning_lib($owner);
-	$ws->name($name);
+	if( $existing ) {
 
-	my $id = $U->storagereq(
-		'open-ils.storage.direct.actor.workstation.create', $ws );
-	return $U->DB_UPDATE_FAILED($ws) unless $id;
+		if( $self->api_name =~ /override/o ) {
+            # workstation with the given name exists.  
 
-	$ws->id($id);
-	return $ws->id();
-}
+            if($owner ne $existing->owning_lib) {
+                # if necessary, update the owning_lib of the workstation
 
-sub register_workstation {
-	my( $self, $conn, $authtoken, $name, $owner ) = @_;
+                $logger->info("changing owning lib of workstation ".$existing->id.
+                    " from ".$existing->owning_lib." to $owner");
+			    return $e->die_event unless 
+                    $e->allowed('UPDATE_WORKSTATION', $existing->owning_lib); 
 
-	my $e = new_editor(authtoken=>$authtoken, xact=>1);
-	return $e->event unless $e->checkauth;
-	return $e->event unless $e->allowed('REGISTER_WORKSTATION'); # XXX rely on editor perms
-	my $existing = $e->search_actor_workstation({name => $name});
+			    return $e->die_event unless $e->allowed('UPDATE_WORKSTATION', $owner); 
 
-	if( @$existing ) {
-		if( $self->api_name =~ /override/o ) {
-			return $e->event unless $e->allowed('DELETE_WORKSTATION'); # XXX rely on editor perms
-			return $e->event unless $e->delete_actor_workstation($$existing[0]);
+                $existing->owning_lib($owner);
+			    return $e->die_event unless $e->update_actor_workstation($existing);
+
+                $e->commit;
+
+            } else {
+                $logger->info(  
+                    "attempt to register an existing workstation.  returning existing ID");
+            }
+
+            return $existing->id;
+
 		} else {
 			return OpenILS::Event->new('WORKSTATION_NAME_EXISTS')
 		}
@@ -2486,12 +2486,41 @@
 	my $ws = Fieldmapper::actor::workstation->new;
 	$ws->owning_lib($owner);
 	$ws->name($name);
-	$e->create_actor_workstation($ws) or return $e->event;
+	$e->create_actor_workstation($ws) or return $e->die_event;
 	$e->commit;
 	return $ws->id; # note: editor sets the id on the new object for us
 }
 
+__PACKAGE__->register_method (
+	method		=> 'workstation_list',
+	api_name		=> 'open-ils.actor.workstation.list',
+	signature	=> q/
+		Returns a list of workstations registered at the given location
+		@param authtoken The login session key
+		@param ids A list of org_unit.id's for the workstation owners
+	/);
 
+sub workstation_list {
+	my( $self, $conn, $authtoken, @orgs ) = @_;
+
+	my $e = new_editor(authtoken=>$authtoken);
+	return $e->event unless $e->checkauth;
+    my %results;
+
+    for my $o (@orgs) {
+	    return $e->event 
+            unless $e->allowed('REGISTER_WORKSTATION', $o);
+        $results{$o} = $e->search_actor_workstation({owning_lib=>$o});
+    }
+    return \%results;
+}
+
+
+
+
+
+
+
 __PACKAGE__->register_method (
 	method		=> 'fetch_patron_note',
 	api_name		=> 'open-ils.actor.note.retrieve.all',



More information about the open-ils-commits mailing list