From 9e864c8c28c5fb8cd6fc587b95e1952a8b13f793 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 19 Feb 2008 14:25:48 +0000 Subject: [PATCH] Removed up-front creation of BAD_PARAMS to prevent compile-time warnings added some initial purchase order an po_lineitem creation code, needs work git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8773 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Financials.pm | 109 +++++++++++++++++++-- .../perlmods/OpenILS/Application/Acq/Picklist.pm | 30 +++--- .../perlmods/OpenILS/Application/Acq/Provider.pm | 7 +- 3 files changed, 121 insertions(+), 25 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm index 9c5c342f33..59825d2a30 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm @@ -1,5 +1,5 @@ package OpenILS::Application::Acq::Financials; -use base qw/OpenILS::Application::Acq/; +use base qw/OpenILS::Application/; use strict; use warnings; use OpenSRF::Utils::Logger qw(:logger); @@ -11,9 +11,6 @@ use OpenILS::Event; use OpenILS::Application::AppUtils; my $U = 'OpenILS::Application::AppUtils'; -my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS'); - - # ---------------------------------------------------------------------------- # Funding Sources # ---------------------------------------------------------------------------- @@ -122,7 +119,8 @@ sub retrieve_org_funding_sources { return $e->event unless $e->checkauth; my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUNDING_SOURCE'; - return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUNDING_SOURCE/; + return OpenILS::Event->new('BAD_PARAMS') + unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUNDING_SOURCE/; my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list : $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1}); @@ -287,7 +285,8 @@ sub retrieve_org_funds { return $e->event unless $e->checkauth; my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUND'; - return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/; + return OpenILS::Event->new('BAD_PARAMS') + unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/; my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list : $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1}); @@ -460,7 +459,7 @@ __PACKAGE__->register_method( } ); -sub retrieve_fund_alloc { +sub retrieve_funding_source_allocations { my($self, $conn, $auth, $fund_alloc_id) = @_; my $e = new_editor(authtoken=>$auth); return $e->event unless $e->checkauth; @@ -476,9 +475,6 @@ sub retrieve_fund_alloc { return $fund_alloc; } - - - # ---------------------------------------------------------------------------- # Currency # ---------------------------------------------------------------------------- @@ -504,4 +500,97 @@ sub retrieve_all_currency_type { } +# ---------------------------------------------------------------------------- +# Purchase Orders +# ---------------------------------------------------------------------------- + +__PACKAGE__->register_method( + method => 'create_purchase_order', + api_name => 'open-ils.acq.purchase_order.create', + signature => { + desc => 'Creates a new purchase order', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'purchase_order to create', type => 'object'} + ], + return => {desc => 'The purchase order id, Event on failure'} + } +); + +sub create_purchase_order { + my($self, $conn, $auth, $p_order) = @_; + my $e = new_editor(xact=>1, authtoken=>$auth); + return $e->die_event unless $e->checkauth; + $p_order->owner($e->requestor->id); + + if($p_order->default_fund) { + # if a default fund is provided, make sure the requestor + # actually has permission to spend from that fund + my $fund = $e->retrieve_acq_fund($p_order->default_fund) + or return $e->die_event; + return $e->die_event unless $e->allowed('MANAGE_FUND', $fund->org, $fund); + } + + my $provider = $e->retrieve_acq_provider($p_order->provider) + or return $e->die_event; + + return $e->die_event unless $e->allowed('MANAGE_PROVIDER', $provider->owner, $provider); + + $e->create_acq_purchase_order($p_order) or return $e->die_event; + $e->commit; + return $p_order->id; +} + + +__PACKAGE__->register_method( + method => 'create_po_lineitem', + api_name => 'open-ils.acq.po_lineitem.create', + signature => { + desc => 'Creates a new purchase order line item', + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'purchase order line item to create', type => 'object'} + ], + return => {desc => 'The purchase order line item id, Event on failure'} + } +); + +sub create_po_lineitem { + my($self, $conn, $auth, $po_li, $options) = @_; + my $e = new_editor(xact=>1, authtoken=>$auth); + return $e->die_event unless $e->checkauth; + + my $po = $e->retrieve_acq_purchase_order($po_li->purchase_order) + or return $e->die_event; + + return OpenILS::Event->new('BAD_PARAMS') + unless $e->requestor->id == $po->owner; + + if($$options{picklist_entry}) { + # if a picklist_entry ID is provided, use that as the basis for this item + my $ple = $e->retrieve_acq_picklist_entry($$options{picklist_entry}) + or return $e->die_event; + $po_li->marc($ple->marc); + $po_li->eg_bib_id($ple->eg_bib_id); + } + + if($po_li->fund) { + # check fund perms if using the non-default fund + my $fund = $e->retrieve_acq_fund($po_li->fund) + or return $e->die_event; + return $e->die_event unless $e->allowed('MANAGE_FUND', $fund->org, $fund); + } + + my $provider = $e->retrieve_acq_provider($po->provider) + or return $e->die_event; + + return $e->die_event unless $e->allowed('MANAGE_PROVIDER', $provider->owner, $provider); + + $e->create_acq_po_lineitem($po_li) or return $e->die_event; + return $po_li->id; +} + + + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm index 77ef2019bc..8309d69e20 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm @@ -1,5 +1,5 @@ package OpenILS::Application::Acq::Picklist; -use base qw/OpenILS::Application::Acq/; +use base qw/OpenILS::Application/; use strict; use warnings; use OpenSRF::Utils::Logger qw(:logger); @@ -9,8 +9,6 @@ use OpenILS::Const qw/:const/; use OpenSRF::Utils::SettingsClient; use OpenILS::Event; -my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS'); - __PACKAGE__->register_method( method => 'create_picklist', @@ -30,7 +28,8 @@ sub create_picklist { my $e = new_editor(xact=>1, authtoken=>$auth); return $e->die_event unless $e->checkauth; return $e->die_event unless $e->allowed('CREATE_PICKLIST'); - return $BAD_PARAMS unless $e->requestor->id == $picklist->owner; + return OpenILS::Event->new('BAD_PARAMS') + unless $e->requestor->id == $picklist->owner; $e->create_acq_picklist($picklist) or return $e->die_event; $e->commit; return $picklist->id; @@ -58,7 +57,7 @@ sub update_picklist { # don't let them change the owner my $o_picklist = $e->retrieve_acq_picklist($picklist->id) or return $e->die_event; - return $BAD_PARAMS if ( + return OpenILS::Event->new('BAD_PARAMS') if ( $o_picklist->owner != $picklist->owner or $picklist->owner != $e->requestor->id ); @@ -92,7 +91,11 @@ sub retrieve_picklist { $picklist->entry_count(retrieve_picklist_entry_count($e, $picklist_id)) if $$options{flesh_entry_count}; - return $BAD_PARAMS unless $e->requestor->id == $picklist->owner; + if($e->requestor->id != $picklist->owner) { + return $e->event unless + $e->allowed('VIEW_PICKLIST', undef, $picklist); + } + return $picklist; } @@ -237,7 +240,8 @@ sub delete_picklist { my $picklist = $e->retrieve_acq_picklist($picklist_id) or return $e->die_event; # don't let anyone delete someone else's picklist - return $BAD_PARAMS if $picklist->owner != $e->requestor->id; + return OpenILS::Event->new('BAD_PARAMS') + if $picklist->owner != $e->requestor->id; $e->delete_acq_picklist($picklist) or return $e->die_event; $e->commit; @@ -270,7 +274,8 @@ sub create_picklist_entry { my $picklist = $e->retrieve_acq_picklist($entry->picklist) or return $e->die_event; - return $BAD_PARAMS unless $picklist->owner == $e->requestor->id; + return OpenILS::Event->new('BAD_PARAMS') + unless $picklist->owner == $e->requestor->id; # indicate the picklist was updated $picklist->edit_time('now'); @@ -315,7 +320,8 @@ sub retrieve_picklist_entry { my $picklist = $e->retrieve_acq_picklist($pl_entry->picklist) or return $e->event; - return $BAD_PARAMS if $picklist->owner != $e->requestor->id; + return OpenILS::Event->new('BAD_PARAMS') + if $picklist->owner != $e->requestor->id; return $pl_entry; } @@ -346,7 +352,8 @@ sub delete_picklist_entry { or return $e->die_event; # don't let anyone delete someone else's picklist entry - return $BAD_PARAMS if $picklist->owner != $e->requestor->id; + return OpenILS::Event->new('BAD_PARAMS') + if $picklist->owner != $e->requestor->id; $e->delete_acq_picklist_entry($pl_entry) or return $e->die_event; $e->commit; @@ -381,7 +388,8 @@ sub update_picklist_entry { ]) or return $e->die_event; # don't let anyone update someone else's picklist entry - return $BAD_PARAMS if $orig_entry->picklist->owner != $e->requestor->id; + return OpenILS::Event->new('BAD_PARAMS') + if $orig_entry->picklist->owner != $e->requestor->id; $e->update_acq_picklist_entry($pl_entry) or return $e->die_event; $e->commit; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Provider.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Provider.pm index 27b5fd3ec4..3e81b5e679 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Provider.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Provider.pm @@ -1,5 +1,5 @@ package OpenILS::Application::Acq::Provider; -use base qw/OpenILS::Application::Acq/; +use base qw/OpenILS::Application/; use strict; use warnings; use OpenILS::Event; @@ -11,8 +11,6 @@ use OpenSRF::Utils::SettingsClient; use OpenILS::Application::AppUtils; my $U = 'OpenILS::Application::AppUtils'; -my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS'); - __PACKAGE__->register_method( method => 'create_provider', @@ -87,7 +85,8 @@ sub retrieve_org_providers { my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_PROVIDER'; - return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_PROVIDER/; + return OpenILS::Event->new('BAD_PARAMS') + unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_PROVIDER/; my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list : $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1}); -- 2.11.0