From 951b648d8fc770db14bec9d8621d090d8ccb0756 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 1 Aug 2014 13:29:41 -0400 Subject: [PATCH] LP#1347774 CStoreEditor anonymous PCRUD additions * Exporter repairs : use export_to_level * pcrud personality call argument mod repair * log pcrud personality json_query attempts loudly to ease transition * CStoreEditor anon/pcrud personality live test * CStoreEditor anon pcrud default to undef authtoken: The presence of an authtoken ("ANONYMOUS") in the editor can be misleading at higher levels of the code, since it implies a presumably functional authtoken has been provided somewhow. Apply ANONYMOUS only as needed to API calls instead. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- .../lib/OpenILS/Utils/CStoreEditor.pm | 26 ++++++++-------- Open-ILS/src/perlmods/live_t/07-anon_pcrud.t | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 Open-ILS/src/perlmods/live_t/07-anon_pcrud.t diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm index 995461011c..c2893241b4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/CStoreEditor.pm @@ -69,7 +69,8 @@ sub import { } } - return $class->SUPER::import( @super_args ); + # Exporter doesn't like you to call it's import() directly + return $class->export_to_level(1, $class, @super_args); } sub new_editor { return OpenILS::Utils::CStoreEditor->new(@_); } @@ -213,7 +214,6 @@ sub died { sub authtoken { my( $self, $auth ) = @_; $self->{authtoken} = $auth if $auth; - return 'ANONYMOUS' if ($self->personality eq 'open-ils.pcrud' and !defined($self->{authtoken})); return $self->{authtoken}; } @@ -743,7 +743,7 @@ sub __arg_to_string { # return $e->event unless @$results; # ----------------------------------------------------------------------------- sub runmethod { - my( $self, $action, $type, $arg, $options ) = @_; + my( $self, $action, $type, $hint, $arg, $options ) = @_; $options ||= {}; @@ -762,7 +762,7 @@ sub runmethod { my @arg = ( ref($arg) eq 'ARRAY' ) ? @$arg : ($arg); my $method = ''; if ($self->personality eq 'open-ils.pcrud') { - $method = $self->app.".$action.$type"; + $method = $self->app.".$action.$hint"; } else { $method = $self->app.".direct.$type.$action"; } @@ -827,8 +827,9 @@ sub runmethod { my $obj; my $err = ''; - # In pcrud mode, sub authtoken returns 'ANONYMOUS' if one is not yet set - unshift(@$arg, $self->authtoken) if ($self->personality eq 'open-ils.pcrud'); + # in PCRUD mode, if no authtoken is set, fall back to anonymous. + unshift(@arg, ($self->authtoken || 'ANONYMOUS')) + if ($self->personality eq 'open-ils.pcrud'); try { $obj = $self->request($method, @arg); @@ -918,14 +919,10 @@ sub init { my $map = $Fieldmapper::fieldmap; for my $object (keys %$map) { my $obj = __fm2meth($object, '_'); - my $type; - if (__PACKAGE__->personality eq 'open-ils.pcrud') { - $type = $object->json_hint; - } else { - $type = __fm2meth($object, '.'); - } + my $type = __fm2meth($object, '.'); + my $hint = $object->json_hint; foreach my $command (qw/ update retrieve search create delete batch_retrieve retrieve_all /) { - eval "sub ${command}_$obj {return shift()->runmethod('$command', '$type', \@_);}\n"; + eval "sub ${command}_$obj {return shift()->runmethod('$command', '$type', '$hint', \@_);}\n"; } # TODO: performance test against concatenating a big string of all the subs and eval'ing only ONCE. } @@ -937,6 +934,9 @@ sub json_query { my( $self, $arg, $options ) = @_; if( $self->personality eq 'open-ils.pcrud' ) { + $self->log(E, "json_query is not allowed when using the ". + "open-ils.pcrud personality of CStoreEditor: " .Dumper($arg)); + $self->event( OpenILS::Event->new( 'JSON_QUERY_NOT_ALLOWED', diff --git a/Open-ILS/src/perlmods/live_t/07-anon_pcrud.t b/Open-ILS/src/perlmods/live_t/07-anon_pcrud.t new file mode 100644 index 0000000000..9fddac7c55 --- /dev/null +++ b/Open-ILS/src/perlmods/live_t/07-anon_pcrud.t @@ -0,0 +1,31 @@ +#!perl + +use Test::More tests => 5; + +diag("Tests Anonymous PCRUD personality for CStoreEditor"); + +use strict; use warnings; + +use OpenILS::Utils::TestUtils; +use OpenILS::Utils::CStoreEditor (':funcs', personality => 'open-ils.pcrud'); +my $script = OpenILS::Utils::TestUtils->new(); +$script->bootstrap; + +my $e = new_editor; +$e->init; + +is ($e->personality, 'open-ils.pcrud', 'Confirm personality'); + +my $org = $e->retrieve_actor_org_unit(1); +is($org->id, 1, 'Anon org unit retrieved'); + +my $user = $e->retrieve_actor_user(1); +is($user, undef, 'Anon user not retrieved'); + +$org = $e->search_actor_org_unit({id => 1})->[0]; +is($org->id, 1, 'Anon org unit searched'); + +$user = $e->search_actor_user({id => 1})->[0]; +is($user, undef, 'Anon user not searched'); + + -- 2.43.2