]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Circ/CopyLocations.pm
no longer require authentication for copy location retrieve
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Circ / CopyLocations.pm
1 package OpenILS::Application::Circ::CopyLocations;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use Data::Dumper;
5 $Data::Dumper::Indent = 0;
6 use OpenSRF::EX qw(:try);
7 use OpenSRF::Utils::Logger qw(:logger);
8 use OpenILS::Application::AppUtils;
9 use OpenILS::Utils::Fieldmapper;
10 my $U = "OpenILS::Application::AppUtils";
11
12
13 __PACKAGE__->register_method(
14         api_name                => "open-ils.circ.copy_location.retrieve.all",
15         method          => 'cl_retrieve_all',
16         argc                    =>      1,
17         signature       => q/
18                 Retrieves the ranged set of copy locations for the requested org.
19                 If no org is provided, the home org of the requestor is used.
20                 @param authtoken The login session key
21                 @param orgId The org location id
22                 @return An array of copy location objects
23                 /);
24
25 sub cl_retrieve_all {
26         my( $self, $client, $orgId ) = @_;
27
28         if(!$orgId) {
29                 my $otree = $U->get_org_tree();
30                 $orgId = $otree->id;
31         }
32
33         $logger->debug("Fetching ranged copy location set for org $orgId");
34         return $U->storagereq(
35                 'open-ils.storage.ranged.asset.copy_location.retrieve.atomic', $orgId);
36 }
37
38 __PACKAGE__->register_method(
39         api_name                => 'open-ils.circ.copy_location.create',
40         method          => 'cl_create',
41         argc                    => 2,
42         signature       => q/
43                 Creates a new copy location.  Requestor must have the CREATE_COPY_LOCATION
44                 permission at the location specified on the new location object
45                 @param authtoken The login session key
46                 @param copyLoc The new copy location object
47                 @return The if of the new location object on success, event on error
48         /);
49
50 sub cl_create {
51         my( $self, $client, $authtoken, $copyLoc ) = @_;
52         my( $requestor, $evt ) = $U->checkses($authtoken);
53         return $evt if $evt;
54         $evt = $U->check_perms($requestor->id, 
55                 $copyLoc->owning_lib, 'CREATE_COPY_LOCATION');
56         return $evt if $evt;
57
58         my $cl;
59         ($cl, $evt) = $U->fetch_copy_location_by_name($copyLoc->name, $copyLoc->owning_lib);
60         return OpenILS::Event->new('COPY_LOCATION_EXISTS') if $cl;
61
62         my $id = $U->storagereq(
63                 'open-ils.storage.direct.asset.copy_location.create', $copyLoc );
64
65         return $U->DB_UPDATE_FAILED($copyLoc) unless $id;
66         return $id;
67 }
68
69 __PACKAGE__->register_method (
70         api_name                => 'open-ils.circ.copy_location.delete',
71         method          => 'cl_delete',
72         argc                    => 2,
73         signature       => q/
74                 Deletes a copy location. Requestor must have the 
75                 DELETE_COPY_LOCATION permission.
76                 @param authtoken The login session key
77                 @param id The copy location object id
78                 @return 1 on success, event on error
79         /);
80
81 sub cl_delete {
82         my( $self, $client, $authtoken, $id ) = @_;
83         my( $requestor, $evt ) = $U->checkses($authtoken);
84         return $evt if $evt;
85
86         my $cl;
87         ($cl, $evt) = $U->fetch_copy_location($id);
88         return $evt if $evt;
89
90         $evt = $U->check_perms($requestor->id, 
91                 $cl->owning_lib, 'DELETE_COPY_LOCATION');
92         return $evt if $evt;
93
94         my $resp = $U->storagereq(
95                 'open-ils.storage.direct.asset.copy_location.delete', $id );
96         
97         return $U->DB_UPDATE_FAILED unless $resp;
98         return 1;
99 }
100
101 __PACKAGE__->register_method (
102         api_name                => 'open-ils.circ.copy_location.update',
103         method          => 'cl_update',
104         argc                    => 2,
105         signature       => q/
106                 Updates a copy location object.  Requestor must have 
107                 the UPDATE_COPY_LOCATION permission
108                 @param authtoken The login session key
109                 @param copyLoc  The copy location object
110                 @return 1 on success, event on error
111         /);
112
113 sub cl_update {
114         my( $self, $client, $authtoken, $copyLoc ) = @_;
115
116         my( $requestor, $evt ) = $U->checkses($authtoken);
117         return $evt if $evt;
118
119         my $cl; 
120         ($cl, $evt) = $U->fetch_copy_location($copyLoc->id);
121         return $evt if $evt;
122
123         $evt = $U->check_perms($requestor->id, 
124                 $cl->owning_lib, 'UPDATE_COPY_LOCATION');
125         return $evt if $evt;
126
127         $copyLoc->owning_lib($cl->owning_lib); #disallow changing of the lib
128
129         my $resp = $U->storagereq(
130                 'open-ils.storage.direct.asset.copy_location.update', $copyLoc );
131         
132         return 1; # if there was no exception thrown, then the update was a success
133 }
134
135
136
137 666;