diff --git a/app/models/message.rb b/app/models/message.rb index 9ebc262d6..5f95f30d9 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -25,6 +25,8 @@ class Message < ActiveRecord::Base self end + validate :participant_of_parent_conversation + def diaspora_handle self.author.diaspora_handle end @@ -54,4 +56,13 @@ class Message < ActiveRecord::Base def parent= parent self.conversation = parent end + + private + def participant_of_parent_conversation + if self.parent && !self.parent.participants.include?(self.author) + errors[:base] << "Author is not participating in the conversation" + else + true + end + end end diff --git a/config/routes.rb b/config/routes.rb index 6d8298244..1be26b55b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,7 +26,9 @@ Diaspora::Application.routes.draw do resources :contacts resources :aspect_memberships, :only => [:destroy, :create] + resources :conversations do + resources :messages, :only => [:create, :show] resource :conversation_visibility, :only => [:destroy], :path => '/visibility/' end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 7c09921fb..faf2bda98 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -18,6 +18,11 @@ describe Message do @xml = @message.to_diaspora_xml end + it 'validates that the author is a participant in the conversation' do + msg = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @cnv.id) + pp msg.valid? + end + describe '#before_create' do it 'signs the message' do @message.author_signature.should_not be_blank