From cad3cc7993bb8f21fb6aac27fabbb973c5438773 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 20 Nov 2007 02:16:25 +0000 Subject: Attempt to create the object with a default owner on get and store when the object doesn't exist. --- perl/Wallet/Server.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'perl/Wallet/Server.pm') diff --git a/perl/Wallet/Server.pm b/perl/Wallet/Server.pm index bb1a90c..429b3fb 100644 --- a/perl/Wallet/Server.pm +++ b/perl/Wallet/Server.pm @@ -401,10 +401,16 @@ sub owner { # Retrieve the information associated with an object, or returns undef and # sets the internal error if the retrieval fails or if the user isn't -# authorized. +# authorized. If the object doesn't exist, attempts dynamic creation of the +# object using the default ACL mappings (if any). sub get { my ($self, $type, $name) = @_; my $object = $self->retrieve ($type, $name); + if (not defined $object and $self->error =~ /^cannot find/) { + if ($self->create ($type, $name)) { + $object = $self->retrieve ($type, $name); + } + } return undef unless defined $object; return undef unless $self->acl_check ($object, 'get'); my $result = $object->get ($self->{user}, $self->{host}); @@ -414,10 +420,17 @@ sub get { # Store new data in an object, or returns undef and sets the internal error if # the object can't be found or if the user isn't authorized. Also don't -# permit storing undef, although storing the empty string is fine. +# permit storing undef, although storing the empty string is fine. If the +# object doesn't exist, attempts dynamic creation of the object using the +# default ACL mappings (if any). sub store { my ($self, $type, $name, $data) = @_; my $object = $self->retrieve ($type, $name); + if (not defined $object and $self->error =~ /^cannot find/) { + if ($self->create ($type, $name)) { + $object = $self->retrieve ($type, $name); + } + } return undef unless defined $object; return undef unless $self->acl_check ($object, 'store'); if (not defined ($data)) { -- cgit v1.2.3