}
}
- 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(@_); }
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};
}
# return $e->event unless @$results;
# -----------------------------------------------------------------------------
sub runmethod {
- my( $self, $action, $type, $arg, $options ) = @_;
+ my( $self, $action, $type, $hint, $arg, $options ) = @_;
$options ||= {};
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";
}
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);
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.
}
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',
--- /dev/null
+#!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');
+
+