Commit d0dff61f4906627caa0c48689999ab6dbe56c4e5

Authored by Antonio Terceiro
2 parents b450a0ce 6211a0da

Merge branch 'stable'

Conflicts:

	lib/noosfero.rb
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
... ... @@ -19,11 +20,7 @@ class ContactController < PublicController
19 20 flash[:notice] = _('Contact not sent')
20 21 end
21 22 else
22   - if logged_in?
23   - @contact = Contact.new(:name => user.name, :email => user.email)
24   - else
25   - @contact = Contact.new
26   - end
  23 + @contact = Contact.new(:name => user.name, :email => user.email)
27 24 end
28 25 end
29 26  
... ...
app/models/communities_block.rb
... ... @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock
33 33 end
34 34  
35 35 def profile_count
36   - owner.communities(:public_profile => true).count
  36 + if owner.kind_of?(Environment)
  37 + owner.communities.count(:conditions => { :public_profile => true })
  38 + else
  39 + owner.communities(:public_profile => true).count
  40 + end
37 41 end
38 42  
39 43 def profile_finder
... ...
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
... ...
app/models/enterprises_block.rb
... ... @@ -29,7 +29,12 @@ class EnterprisesBlock &lt; ProfileListBlock
29 29 end
30 30  
31 31 def profile_count
32   - owner.enterprises(:public_profile => true).count
  32 + if owner.kind_of?(Environment)
  33 + owner.enterprises.count(:conditions => { :public_profile => true })
  34 + else
  35 + owner.enterprises(:public_profile => true).count
  36 + end
  37 +
33 38 end
34 39  
35 40 def profile_finder
... ...
app/models/friends_block.rb
... ... @@ -30,7 +30,7 @@ class FriendsBlock &lt; ProfileListBlock
30 30 end
31 31  
32 32 def profile_count
33   - owner.friends.count
  33 + owner.friends.count(:conditions => { :public_profile => true })
34 34 end
35 35  
36 36 end
... ...
app/models/members_block.rb
... ... @@ -20,7 +20,7 @@ class MembersBlock &lt; ProfileListBlock
20 20 end
21 21  
22 22 def profile_count
23   - owner.members.count
  23 + owner.members.select {|member| member.public_profile? }.count
24 24 end
25 25  
26 26 def profile_finder
... ...
app/views/contact/new.rhtml
... ... @@ -8,8 +8,6 @@
8 8  
9 9 <%= required_fields_message %>
10 10  
11   - <%= required f.text_field(:name) %>
12   - <%= required f.text_field(:email) %>
13 11 <% unless environment.enabled?('disable_select_city_for_contact') %>
14 12 <%= labelled_form_field _('City and state'), select_city(true) %>
15 13 <% end %>
... ...
app/views/shared/user_menu.rhtml
... ... @@ -20,7 +20,7 @@
20 20 </li>
21 21  
22 22 <li>
23   - <%= link_to('<span class="icon-menu-my-groups"></span>' + __('My communities'), { :controller => 'memberships', :profile => user.identifier, :action => 'index' }) %>
  23 + <%= link_to('<span class="icon-menu-my-groups"></span>' + _('My groups'), { :controller => 'memberships', :profile => user.identifier, :action => 'index' }) %>
24 24 </li>
25 25  
26 26 <% for enterprise in user.enterprises %>
... ...
test/functional/contact_controller_test.rb
... ... @@ -35,11 +35,6 @@ class ContactControllerTest &lt; Test::Unit::TestCase
35 35 assert_tag :tag => 'form', :attributes => { :action => "/contact/#{enterprise.identifier}/new", :method => 'post' }
36 36 end
37 37  
38   - should 'display input for destinatary email' do
39   - get :new, :profile => enterprise.identifier
40   - assert_tag :tag => 'input', :attributes => { :name => 'contact[email]', :type => 'text' }
41   - end
42   -
43 38 should 'display input for message' do
44 39 get :new, :profile => enterprise.identifier
45 40 assert_tag :tag => 'textarea', :attributes => { :name => 'contact[message]' }
... ... @@ -51,14 +46,14 @@ class ContactControllerTest &lt; Test::Unit::TestCase
51 46 assert_redirected_to :action => 'new'
52 47 end
53 48  
54   - should 'fill email if user logged in' do
  49 + should 'have logged user email' do
55 50 get :new, :profile => enterprise.identifier
56   - assert_tag :tag => 'input', :attributes => {:name => 'contact[email]', :value => profile.email}
  51 + assert_equal profile.email, assigns(:contact).email
57 52 end
58 53  
59   - should 'fill name if user logged in' do
  54 + should 'have logged user name' do
60 55 get :new, :profile => enterprise.identifier
61   - assert_tag :tag => 'input', :attributes => {:name => 'contact[name]', :value => profile.name}
  56 + assert_equal profile.name, assigns(:contact).name
62 57 end
63 58  
64 59 should 'define city and state' do
... ... @@ -120,4 +115,10 @@ class ContactControllerTest &lt; Test::Unit::TestCase
120 115 assert_response :redirect
121 116 assert_redirected_to :controller => 'account', :action => 'login'
122 117 end
  118 +
  119 + should 'identify sender' do
  120 + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''}
  121 + assert_equal Person['contact_test_user'], assigns(:contact).sender
  122 + end
  123 +
123 124 end
... ...
test/unit/communities_block_test.rb
... ... @@ -102,7 +102,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
102 102 assert_equal 2, block.profile_count
103 103 end
104 104  
105   - should 'not count non-public communities' do
  105 + should 'not count non-public profile communities' do
106 106 user = create_user('testuser').person
107 107  
108 108 community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
... ... @@ -117,4 +117,15 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
117 117 assert_equal 1, block.profile_count
118 118 end
119 119  
  120 + should 'not count non-public environment communities' do
  121 + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
  122 +
  123 + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
  124 +
  125 + block = CommunitiesBlock.new
  126 + block.expects(:owner).at_least_once.returns(Environment.default)
  127 +
  128 + assert_equal 1, block.profile_count
  129 + end
  130 +
120 131 end
... ...
test/unit/contact_sender_test.rb
... ... @@ -60,6 +60,14 @@ class ContactSenderTest &lt; 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)
... ...
test/unit/enterprises_block_test.rb
... ... @@ -114,7 +114,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
114 114 assert_equal 2, block.profile_count
115 115 end
116 116  
117   - should 'not count non-public enterprises' do
  117 + should 'not count non-public person enterprises' do
118 118 user = create_user('testuser').person
119 119  
120 120 ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true)
... ... @@ -131,4 +131,16 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
131 131 assert_equal 1, block.profile_count
132 132 end
133 133  
  134 + should 'not count non-public environment enterprises' do
  135 + env = Environment.create!(:name => 'test_env')
  136 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :public_profile => true)
  137 +
  138 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :public_profile => false)
  139 +
  140 + block = EnterprisesBlock.new
  141 + block.expects(:owner).at_least_once.returns(env)
  142 +
  143 + assert_equal 1, block.profile_count
  144 + end
  145 +
134 146 end
... ...
test/unit/friends_block_test.rb
... ... @@ -62,4 +62,17 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase
62 62 assert_equal 3, block.profile_count
63 63 end
64 64  
  65 + should 'count number of public people' do
  66 + owner = create_user('testuser1').person
  67 + private_p = create_user('private', {}, {:public_profile => false}).person
  68 + public_p = create_user('public', {}, {:public_profile => true}).person
  69 +
  70 + owner.add_friend(private_p)
  71 + owner.add_friend(public_p)
  72 +
  73 + block = FriendsBlock.new
  74 + block.expects(:owner).returns(owner)
  75 +
  76 + assert_equal 1, block.profile_count
  77 + end
65 78 end
... ...
test/unit/members_block_test.rb
... ... @@ -60,11 +60,30 @@ class MembersBlockTest &lt; Test::Unit::TestCase
60 60 member2 = mock; member2.stubs(:id).returns(2)
61 61 member3 = mock; member3.stubs(:id).returns(3)
62 62  
  63 + member1.stubs(:public_profile?).returns(true)
  64 + member2.stubs(:public_profile?).returns(true)
  65 + member3.stubs(:public_profile?).returns(true)
  66 +
63 67 owner.expects(:members).returns([member1, member2, member3])
64 68  
65 69 block = MembersBlock.new
66 70 block.expects(:owner).returns(owner)
67 71 assert_equal 3, block.profile_count
68 72 end
  73 +
  74 + should 'not count non-public community members' do
  75 + community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default)
  76 +
  77 + private_p = create_user('private', {}, {:public_profile => false}).person
  78 + public_p = create_user('public', {}, {:public_profile => true}).person
  79 +
  80 + community.add_member(private_p)
  81 + community.add_member(public_p)
  82 +
  83 + block = MembersBlock.new
  84 + block.expects(:owner).at_least_once.returns(community)
  85 +
  86 + assert_equal 1, block.profile_count
  87 + end
69 88 end
70 89  
... ...