From: erickson Date: Wed, 21 Nov 2007 16:06:37 +0000 (+0000) Subject: backporting fixes to the register workstation code and new workstation list method X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=17cf5ac022f7eef69c76e7b3fd3fffea9f0be9cf;p=Evergreen.git backporting fixes to the register workstation code and new workstation list method git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_2@8107 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 3d3ca48e3a..9330f96af7 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -2443,41 +2443,41 @@ __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}); + return $e->die_event unless $e->allowed('UPDATE_WORKSTATION', $owner); + + $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') } @@ -2486,11 +2486,40 @@ 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 } +__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',