Thingy add/edit via AJAX returned nothing useful, and lied about error status. Fixes bug #11781.

This commit is contained in:
Colin Kuskie 2010-08-15 23:16:53 -07:00
parent 04c49fb48e
commit 05c287cfc7
3 changed files with 30 additions and 5 deletions

View file

@ -1,5 +1,6 @@
7.9.13 7.9.13
- fixed #11783: Instances deleted during realtime run - fixed #11783: Instances deleted during realtime run
- fixed #11781: Thingy wrong retorn value from Ajax method
7.9.12 7.9.12
- webgui.org homepage gives 404 (#11778) - webgui.org homepage gives 404 (#11778)

View file

@ -2645,9 +2645,10 @@ sub www_editThingDataSaveViaAjax {
} }
my $thingProperties = $self->getThing($thingId); my $thingProperties = $self->getThing($thingId);
use Data::Dumper;
warn $thingId;
warn Dumper $thingProperties;
if ($thingProperties->{thingId}){ if ($thingProperties->{thingId}){
my ($privilegedGroup,$workflowId);
return $session->privilege->insufficient() unless $self->canEditThingData($thingId, $thingDataId return $session->privilege->insufficient() unless $self->canEditThingData($thingId, $thingDataId
,$thingProperties); ,$thingProperties);
@ -2658,12 +2659,15 @@ sub www_editThingDataSaveViaAjax {
my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId); my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId);
if ($errors){ if (@{ $errors }) {
$session->http->setStatus("400", "Bad Request"); $session->http->setStatus("400", "Bad Request");
return JSON->new->encode($errors); return JSON->new->encode($errors);
} }
$session->http->setStatus("200");
return '{}';
} }
else { else {
warn "thingId not found in thingProperties\n";
$session->http->setStatus("404", "Not Found"); $session->http->setStatus("404", "Not Found");
return JSON->new->encode({message => "The thingId you requested can not be found."}); return JSON->new->encode({message => "The thingId you requested can not be found."});
} }

View file

@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../../lib";
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; use WebGUI::Session;
use Test::More tests => 28; # increment this value for each test you create use Test::More tests => 30; # increment this value for each test you create
use Test::Deep; use Test::Deep;
use JSON; use JSON;
use WebGUI::Asset::Wobject::Thingy; use WebGUI::Asset::Wobject::Thingy;
@ -406,6 +406,7 @@ is($table, undef, '... drops thing specific table');
# getFieldValue # getFieldValue
# #
################################################################# #################################################################
{ {
my %newThingProperties = %thingProperties; my %newThingProperties = %thingProperties;
my $newThingId = $thingy->addThing(\%newThingProperties, 0); my $newThingId = $thingy->addThing(\%newThingProperties, 0);
@ -421,3 +422,22 @@ is($table, undef, '... drops thing specific table');
like($datetime, qr{^\d+/\d+/\d+\s+\d+:\d+}, "... DateTime field also returns data in user's format"); like($datetime, qr{^\d+/\d+/\d+\s+\d+:\d+}, "... DateTime field also returns data in user's format");
} }
#################################################################
#
# www_editThingDataSaveViaAjax
#
#################################################################
$session->request->setup_body({
thingId => $thingId,
thingDataId => 'new',
});
$session->user({userId => '3'});
$session->http->setStatus(200);
my $json = $thingy->www_editThingDataSaveViaAjax();
diag "json: ".$json;
is $json, '{}', 'www_editThingDataSaveViaAjax: Empty JSON hash';
is $session->http->getStatus, 200, '... http status=200';
$session->request->setup_body({ });