[open-ils-commits] r7622 - trunk/Open-ILS/src/perlmods/OpenILS/Application

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Aug 6 18:54:04 EDT 2007


Author: erickson
Date: 2007-08-06 18:51:22 -0400 (Mon, 06 Aug 2007)
New Revision: 7622

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:

when someone wants to reuse a workstation, we no longer delete the 
exsiting workstation with the same name.  If necessary (and with appropriate
UPDATE_WORKSTATION perms), we change the owning_lib of the workstation.  If
not necessary, we just return the ID of the existing workstation.


removed some deprecated code.



Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2007-08-06 22:10:48 UTC (rev 7621)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2007-08-06 22:51:22 UTC (rev 7622)
@@ -2439,41 +2439,39 @@
 		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});
+                $existing->owning_lib($owner);
+			    return $e->die_event unless $e->update_actor_workstation($existing);
 
-	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]);
+                $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')
 		}
@@ -2482,7 +2480,7 @@
 	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
 }



More information about the open-ils-commits mailing list