From b12c719b09c37c8ce0f1b09cf155360d1ad1a687 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 15 Aug 2010 23:16:53 -0700 Subject: [PATCH] Thingy add/edit via AJAX returned nothing useful, and lied about error status. Fixes bug #11781. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/Thingy.pm | 10 +++++++--- t/Asset/Wobject/Thingy.t | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ced412fe2..d3678fa4a 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.9.13 - fixed #11783: Instances deleted during realtime run + - fixed #11781: Thingy wrong retorn value from Ajax method 7.9.12 - webgui.org homepage gives 404 (#11778) diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index cff8e5d9b..8ecb4ad0b 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -2587,9 +2587,10 @@ sub www_editThingDataSaveViaAjax { } my $thingProperties = $self->getThing($thingId); + use Data::Dumper; + warn $thingId; + warn Dumper $thingProperties; if ($thingProperties->{thingId}){ - my ($privilegedGroup,$workflowId); - return $session->privilege->insufficient() unless $self->canEditThingData($thingId, $thingDataId ,$thingProperties); @@ -2600,12 +2601,15 @@ sub www_editThingDataSaveViaAjax { my ($newThingDataId,$errors) = $self->editThingDataSave($thingId,$thingDataId); - if ($errors){ + if (@{ $errors }) { $session->http->setStatus(400); return JSON->new->encode($errors); } + $session->http->setStatus("200"); + return '{}'; } else { + warn "thingId not found in thingProperties\n"; $session->http->setStatus(404); return JSON->new->encode({message => "The thingId you requested can not be found."}); } diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t index 8df49d803..704dae16c 100644 --- a/t/Asset/Wobject/Thingy.t +++ b/t/Asset/Wobject/Thingy.t @@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Test::MockAsset; 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 JSON; use WebGUI::Asset::Wobject::Thingy; @@ -404,6 +404,7 @@ is($table, undef, '... drops thing specific table'); # getFieldValue # ################################################################# + { my %newThingProperties = %thingProperties; my $newThingId = $thingy->addThing(\%newThingProperties, 0); @@ -419,3 +420,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"); } +################################################################# +# +# 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({ });