diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-06-03 22:08:19 +0200 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2013-06-04 00:09:44 +0200 |
commit | 2060defad2971122d634d22d25f002ee4bad1eff (patch) | |
tree | 4c79bf7a72c5fc932f9216ea6d2e1117c3c50e36 | |
parent | 9282361c2d7a935ee2252fb19b434ea85a22e8d6 (diff) | |
download | ecs2-2060defad2971122d634d22d25f002ee4bad1eff.tar.gz ecs2-2060defad2971122d634d22d25f002ee4bad1eff.zip |
Missing headers when POST on resource queue.
There were missing headers X-EcsSender and X-EcsReceiverCommunities
when accessing a resource through a POST on its queue mode or a
DELETE. This was caused by deleting the relationships between message
memberships before composing the headers. To prevent a double rendering
error it was also necessary to devide the show_render method.
-rw-r--r-- | app/controllers/messages_controller.rb | 16 | ||||
-rw-r--r-- | test/functional/messages_controller_test.rb | 8 |
2 files changed, 20 insertions, 4 deletions
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0ab375b..c087362 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -26,6 +26,7 @@ class MessagesController < ApplicationController def initialize super + @render_cmd=nil end def index @@ -45,6 +46,7 @@ class MessagesController < ApplicationController Message.filter(__method__, @app_namespace, @ressource_name, @record, params) @body = @record.body show_render + eval(@render_cmd) else raise Ecs::AuthorizationException, "You are not allowed to access this resource, " + @@ -67,6 +69,9 @@ class MessagesController < ApplicationController end def destroy + @body = @record.body + @memberships = Membership.receiver(@participant.id, @record.id) + show_render case when @record.outtimed_auths_resource_by_non_owner?(@app_namespace, @resource_name, @participant) @record.destroy_as_receiver(@participant) @@ -76,8 +81,7 @@ class MessagesController < ApplicationController else @record.destroy_as_receiver(@participant) end - @body = @record.body - show_render + eval(@render_cmd) end def fifo @@ -177,12 +181,16 @@ protected @body = @record.body if request.post? if @record + show_render @record.destroy_as_receiver(@participant) + eval(@render_cmd) else raise ActiveRecord::RecordNotFound end + else + show_render + eval(@render_cmd) end - show_render else empty_render end @@ -232,7 +240,7 @@ protected if stale?(:etag => @record, :last_modified => @record.updated_at.utc, :x_ecs_receiver_communities => x_ecs_receiver_communities, :x_ecs_sender => x_ecs_sender) - render :text => @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type) + @render_cmd='render :text => @body, :layout => false, :status => 200, :content_type => Mime::Type.lookup(@record.content_type)' end end diff --git a/test/functional/messages_controller_test.rb b/test/functional/messages_controller_test.rb index dcb35c5..3497b93 100644 --- a/test/functional/messages_controller_test.rb +++ b/test/functional/messages_controller_test.rb @@ -238,6 +238,8 @@ class MessagesControllerTest < ActionController::TestCase assert_response 200 assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } assert_equal 0, MembershipMessage.find_all_by_message_id(@request.parameters[:id]).count + assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_ulm),communities(:wuv)).id.to_s, @response["X-EcsSender"] + assert_equal communities(:wuv).id.to_s, @response["X-EcsReceiverCommunities"] end test "delete_none_postrouted_message_as_none_owner_with_last_reference_in_place" do @@ -261,6 +263,8 @@ class MessagesControllerTest < ActionController::TestCase assert_equal $~.to_s, @request.parameters[:id] assert_nothing_raised(ActiveRecord::RecordNotFound) { Message.find(@request.parameters[:id]) } assert_nil MembershipMessage.find_by_message_id(@request.parameters[:id]) + assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_stgt),communities(:public)).id.to_s, @response["X-EcsSender"] + assert_equal communities(:public).id.to_s, @response["X-EcsReceiverCommunities"] end test "delete_none_postrouted_message_as_none_owner_with_references_in_place" do @@ -297,6 +301,8 @@ class MessagesControllerTest < ActionController::TestCase get :fifo assert_response 200 assert_equal "Hallo Ihr da im Radio.", @response.body.strip + assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_stgt),communities(:wuv)).id.to_s, @response["X-EcsSender"] + assert_equal communities(:wuv).id.to_s, @response["X-EcsReceiverCommunities"] end test "fifo get not idempotent" do @@ -305,6 +311,8 @@ class MessagesControllerTest < ActionController::TestCase post :fifo assert_response 200 assert_equal "Hallo Ihr da im Radio.", @response.body.strip + assert_equal Membership.find_by_participant_id_and_community_id(participants(:ilias_stgt),communities(:wuv)).id.to_s, @response["X-EcsSender"] + assert_equal communities(:wuv).id.to_s, @response["X-EcsReceiverCommunities"] get :fifo assert_response 200 assert_not_equal "Hallo Ihr da im Radio.", @response.body.strip |