[open-ils-commits] r8107 -
branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Nov 21 11:24:17 EST 2007
Author: erickson
Date: 2007-11-21 11:06:37 -0500 (Wed, 21 Nov 2007)
New Revision: 8107
Modified:
branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
backporting fixes to the register workstation code and new workstation list method
Modified: branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2007-11-21 16:02:30 UTC (rev 8106)
+++ branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2007-11-21 16:06:37 UTC (rev 8107)
@@ -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