Commit 6bcb3863f6bb553fdb290292b72dce6a857f5cad
1 parent
4585f58a
Exists in
master
and in
22 other branches
ActionItem1175: identifying the sender in header
Showing
4 changed files
with
19 additions
and
0 deletions
Show diff stats
app/controllers/public/contact_controller.rb
| ... | ... | @@ -10,6 +10,7 @@ class ContactController < PublicController |
| 10 | 10 | if request.post? && params[self.icaptcha_field].blank? |
| 11 | 11 | @contact = Contact.new(params[:contact]) |
| 12 | 12 | @contact.dest = profile |
| 13 | + @contact.sender = user | |
| 13 | 14 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil |
| 14 | 15 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil |
| 15 | 16 | if @contact.deliver | ... | ... |
app/models/contact.rb
| ... | ... | @@ -9,6 +9,7 @@ class Contact < ActiveRecord::Base #WithoutTable |
| 9 | 9 | [:receive_a_copy, :boolean] |
| 10 | 10 | ] |
| 11 | 11 | attr_accessor :dest |
| 12 | + attr_accessor :sender | |
| 12 | 13 | |
| 13 | 14 | N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name') |
| 14 | 15 | |
| ... | ... | @@ -25,6 +26,9 @@ class Contact < ActiveRecord::Base #WithoutTable |
| 25 | 26 | emails = contact.dest.notification_emails |
| 26 | 27 | recipients emails |
| 27 | 28 | from "#{contact.name} <#{contact.email}>" |
| 29 | + if contact.sender | |
| 30 | + headers 'X-Noosfero-Sender' => contact.sender.identifier | |
| 31 | + end | |
| 28 | 32 | if contact.receive_a_copy |
| 29 | 33 | cc "#{contact.name} <#{contact.email}>" |
| 30 | 34 | end | ... | ... |
test/functional/contact_controller_test.rb
| ... | ... | @@ -120,4 +120,10 @@ class ContactControllerTest < Test::Unit::TestCase |
| 120 | 120 | assert_response :redirect |
| 121 | 121 | assert_redirected_to :controller => 'account', :action => 'login' |
| 122 | 122 | end |
| 123 | + | |
| 124 | + should 'identify sender' do | |
| 125 | + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | |
| 126 | + assert_equal Person['contact_test_user'], assigns(:contact).sender | |
| 127 | + end | |
| 128 | + | |
| 123 | 129 | end | ... | ... |
test/unit/contact_sender_test.rb
| ... | ... | @@ -60,6 +60,14 @@ class ContactSenderTest < Test::Unit::TestCase |
| 60 | 60 | assert_equal [person.email], response.to |
| 61 | 61 | end |
| 62 | 62 | |
| 63 | + should 'identify the sender in the message headers' do | |
| 64 | + recipient = create_user('contacted_user').person | |
| 65 | + sender = create_user('sender_user').person | |
| 66 | + c = Contact.new(:dest => recipient, :sender => sender) | |
| 67 | + sent_message = Contact::Sender.deliver_mail(c) | |
| 68 | + assert_equal 'sender_user', sent_message['X-Noosfero-Sender'].to_s | |
| 69 | + end | |
| 70 | + | |
| 63 | 71 | private |
| 64 | 72 | |
| 65 | 73 | def read_fixture(action) | ... | ... |