From: erickson Date: Mon, 6 Aug 2007 22:51:22 +0000 (+0000) Subject: when someone wants to reuse a workstation, we no longer delete the X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=76e142ec33ee702b559856410cc46b7c3b6b87d1;p=Evergreen.git 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@7622 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 9afc34569b..d0e5bea02e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -2439,41 +2439,39 @@ __PACKAGE__->register_method ( 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); + + $e->commit; + + } else { + $logger->info( + "attempt to register an existing workstation. returning existing ID"); + } + + return $existing->id; - 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]); } else { return OpenILS::Event->new('WORKSTATION_NAME_EXISTS') } @@ -2482,7 +2480,7 @@ sub register_workstation { 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 }