diff --git a/app/controllers/public/contact_controller.rb b/app/controllers/public/contact_controller.rb index 6ca8773..53defde 100644 --- a/app/controllers/public/contact_controller.rb +++ b/app/controllers/public/contact_controller.rb @@ -10,6 +10,7 @@ class ContactController < PublicController if request.post? && params[self.icaptcha_field].blank? @contact = Contact.new(params[:contact]) @contact.dest = profile + @contact.sender = user @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil if @contact.deliver diff --git a/app/models/contact.rb b/app/models/contact.rb index 03a65a0..ee2b891 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -9,6 +9,7 @@ class Contact < ActiveRecord::Base #WithoutTable [:receive_a_copy, :boolean] ] attr_accessor :dest + attr_accessor :sender N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name') @@ -25,6 +26,9 @@ class Contact < ActiveRecord::Base #WithoutTable emails = contact.dest.notification_emails recipients emails from "#{contact.name} <#{contact.email}>" + if contact.sender + headers 'X-Noosfero-Sender' => contact.sender.identifier + end if contact.receive_a_copy cc "#{contact.name} <#{contact.email}>" end diff --git a/test/functional/contact_controller_test.rb b/test/functional/contact_controller_test.rb index bf8c196..2724efb 100644 --- a/test/functional/contact_controller_test.rb +++ b/test/functional/contact_controller_test.rb @@ -120,4 +120,10 @@ class ContactControllerTest < Test::Unit::TestCase assert_response :redirect assert_redirected_to :controller => 'account', :action => 'login' end + + should 'identify sender' do + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} + assert_equal Person['contact_test_user'], assigns(:contact).sender + end + end diff --git a/test/unit/contact_sender_test.rb b/test/unit/contact_sender_test.rb index 74f0658..ff1a711 100644 --- a/test/unit/contact_sender_test.rb +++ b/test/unit/contact_sender_test.rb @@ -60,6 +60,14 @@ class ContactSenderTest < Test::Unit::TestCase assert_equal [person.email], response.to end + should 'identify the sender in the message headers' do + recipient = create_user('contacted_user').person + sender = create_user('sender_user').person + c = Contact.new(:dest => recipient, :sender => sender) + sent_message = Contact::Sender.deliver_mail(c) + assert_equal 'sender_user', sent_message['X-Noosfero-Sender'].to_s + end + private def read_fixture(action) -- libgit2 0.21.2