diff options
| author | Russ Allbery <rra@stanford.edu> | 2007-11-20 02:16:25 +0000 | 
|---|---|---|
| committer | Russ Allbery <rra@stanford.edu> | 2007-11-20 02:16:25 +0000 | 
| commit | cad3cc7993bb8f21fb6aac27fabbb973c5438773 (patch) | |
| tree | eed169e35ba00fabeb84459780e32b2a306a8951 /perl/Wallet | |
| parent | 66da128c39971f9a40553af9351b489f1ad186e1 (diff) | |
Attempt to create the object with a default owner on get and store
when the object doesn't exist.
Diffstat (limited to 'perl/Wallet')
| -rw-r--r-- | perl/Wallet/Server.pm | 17 | 
1 files changed, 15 insertions, 2 deletions
| 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)) { | 
