Commit d0dff61f4906627caa0c48689999ab6dbe56c4e5
Exists in
master
and in
28 other branches
Merge branch 'stable'
Conflicts: lib/noosfero.rb
Showing
14 changed files
with
95 additions
and
23 deletions
Show diff stats
app/controllers/public/contact_controller.rb
| @@ -10,6 +10,7 @@ class ContactController < PublicController | @@ -10,6 +10,7 @@ class ContactController < PublicController | ||
| 10 | if request.post? && params[self.icaptcha_field].blank? | 10 | if request.post? && params[self.icaptcha_field].blank? |
| 11 | @contact = Contact.new(params[:contact]) | 11 | @contact = Contact.new(params[:contact]) |
| 12 | @contact.dest = profile | 12 | @contact.dest = profile |
| 13 | + @contact.sender = user | ||
| 13 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil | 14 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil |
| 14 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil | 15 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil |
| 15 | if @contact.deliver | 16 | if @contact.deliver |
| @@ -19,11 +20,7 @@ class ContactController < PublicController | @@ -19,11 +20,7 @@ class ContactController < PublicController | ||
| 19 | flash[:notice] = _('Contact not sent') | 20 | flash[:notice] = _('Contact not sent') |
| 20 | end | 21 | end |
| 21 | else | 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 | end | 24 | end |
| 28 | end | 25 | end |
| 29 | 26 |
app/models/communities_block.rb
| @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock | @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | def profile_count | 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 | end | 41 | end |
| 38 | 42 | ||
| 39 | def profile_finder | 43 | def profile_finder |
app/models/contact.rb
| @@ -9,6 +9,7 @@ class Contact < ActiveRecord::Base #WithoutTable | @@ -9,6 +9,7 @@ class Contact < ActiveRecord::Base #WithoutTable | ||
| 9 | [:receive_a_copy, :boolean] | 9 | [:receive_a_copy, :boolean] |
| 10 | ] | 10 | ] |
| 11 | attr_accessor :dest | 11 | attr_accessor :dest |
| 12 | + attr_accessor :sender | ||
| 12 | 13 | ||
| 13 | N_('Subject'); N_('Message'); N_('City and state'); N_('e-Mail'); N_('Name') | 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,6 +26,9 @@ class Contact < ActiveRecord::Base #WithoutTable | ||
| 25 | emails = contact.dest.notification_emails | 26 | emails = contact.dest.notification_emails |
| 26 | recipients emails | 27 | recipients emails |
| 27 | from "#{contact.name} <#{contact.email}>" | 28 | from "#{contact.name} <#{contact.email}>" |
| 29 | + if contact.sender | ||
| 30 | + headers 'X-Noosfero-Sender' => contact.sender.identifier | ||
| 31 | + end | ||
| 28 | if contact.receive_a_copy | 32 | if contact.receive_a_copy |
| 29 | cc "#{contact.name} <#{contact.email}>" | 33 | cc "#{contact.name} <#{contact.email}>" |
| 30 | end | 34 | end |
app/models/enterprises_block.rb
| @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock | @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock | ||
| 29 | end | 29 | end |
| 30 | 30 | ||
| 31 | def profile_count | 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 | end | 38 | end |
| 34 | 39 | ||
| 35 | def profile_finder | 40 | def profile_finder |
app/models/friends_block.rb
| @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock | @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock | ||
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | def profile_count | 32 | def profile_count |
| 33 | - owner.friends.count | 33 | + owner.friends.count(:conditions => { :public_profile => true }) |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | end | 36 | end |
app/models/members_block.rb
| @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock | @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock | ||
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | def profile_count | 22 | def profile_count |
| 23 | - owner.members.count | 23 | + owner.members.select {|member| member.public_profile? }.count |
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | def profile_finder | 26 | def profile_finder |
app/views/contact/new.rhtml
| @@ -8,8 +8,6 @@ | @@ -8,8 +8,6 @@ | ||
| 8 | 8 | ||
| 9 | <%= required_fields_message %> | 9 | <%= required_fields_message %> |
| 10 | 10 | ||
| 11 | - <%= required f.text_field(:name) %> | ||
| 12 | - <%= required f.text_field(:email) %> | ||
| 13 | <% unless environment.enabled?('disable_select_city_for_contact') %> | 11 | <% unless environment.enabled?('disable_select_city_for_contact') %> |
| 14 | <%= labelled_form_field _('City and state'), select_city(true) %> | 12 | <%= labelled_form_field _('City and state'), select_city(true) %> |
| 15 | <% end %> | 13 | <% end %> |
app/views/shared/user_menu.rhtml
| @@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
| 20 | </li> | 20 | </li> |
| 21 | 21 | ||
| 22 | <li> | 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 | </li> | 24 | </li> |
| 25 | 25 | ||
| 26 | <% for enterprise in user.enterprises %> | 26 | <% for enterprise in user.enterprises %> |
test/functional/contact_controller_test.rb
| @@ -35,11 +35,6 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -35,11 +35,6 @@ class ContactControllerTest < Test::Unit::TestCase | ||
| 35 | assert_tag :tag => 'form', :attributes => { :action => "/contact/#{enterprise.identifier}/new", :method => 'post' } | 35 | assert_tag :tag => 'form', :attributes => { :action => "/contact/#{enterprise.identifier}/new", :method => 'post' } |
| 36 | end | 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 | should 'display input for message' do | 38 | should 'display input for message' do |
| 44 | get :new, :profile => enterprise.identifier | 39 | get :new, :profile => enterprise.identifier |
| 45 | assert_tag :tag => 'textarea', :attributes => { :name => 'contact[message]' } | 40 | assert_tag :tag => 'textarea', :attributes => { :name => 'contact[message]' } |
| @@ -51,14 +46,14 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -51,14 +46,14 @@ class ContactControllerTest < Test::Unit::TestCase | ||
| 51 | assert_redirected_to :action => 'new' | 46 | assert_redirected_to :action => 'new' |
| 52 | end | 47 | end |
| 53 | 48 | ||
| 54 | - should 'fill email if user logged in' do | 49 | + should 'have logged user email' do |
| 55 | get :new, :profile => enterprise.identifier | 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 | end | 52 | end |
| 58 | 53 | ||
| 59 | - should 'fill name if user logged in' do | 54 | + should 'have logged user name' do |
| 60 | get :new, :profile => enterprise.identifier | 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 | end | 57 | end |
| 63 | 58 | ||
| 64 | should 'define city and state' do | 59 | should 'define city and state' do |
| @@ -120,4 +115,10 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -120,4 +115,10 @@ class ContactControllerTest < Test::Unit::TestCase | ||
| 120 | assert_response :redirect | 115 | assert_response :redirect |
| 121 | assert_redirected_to :controller => 'account', :action => 'login' | 116 | assert_redirected_to :controller => 'account', :action => 'login' |
| 122 | end | 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 | end | 124 | end |
test/unit/communities_block_test.rb
| @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase | @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase | ||
| 102 | assert_equal 2, block.profile_count | 102 | assert_equal 2, block.profile_count |
| 103 | end | 103 | end |
| 104 | 104 | ||
| 105 | - should 'not count non-public communities' do | 105 | + should 'not count non-public profile communities' do |
| 106 | user = create_user('testuser').person | 106 | user = create_user('testuser').person |
| 107 | 107 | ||
| 108 | community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) | 108 | community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) |
| @@ -117,4 +117,15 @@ class CommunitiesBlockTest < Test::Unit::TestCase | @@ -117,4 +117,15 @@ class CommunitiesBlockTest < Test::Unit::TestCase | ||
| 117 | assert_equal 1, block.profile_count | 117 | assert_equal 1, block.profile_count |
| 118 | end | 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 | end | 131 | end |
test/unit/contact_sender_test.rb
| @@ -60,6 +60,14 @@ class ContactSenderTest < Test::Unit::TestCase | @@ -60,6 +60,14 @@ class ContactSenderTest < Test::Unit::TestCase | ||
| 60 | assert_equal [person.email], response.to | 60 | assert_equal [person.email], response.to |
| 61 | end | 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 | private | 71 | private |
| 64 | 72 | ||
| 65 | def read_fixture(action) | 73 | def read_fixture(action) |
test/unit/enterprises_block_test.rb
| @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase | @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase | ||
| 114 | assert_equal 2, block.profile_count | 114 | assert_equal 2, block.profile_count |
| 115 | end | 115 | end |
| 116 | 116 | ||
| 117 | - should 'not count non-public enterprises' do | 117 | + should 'not count non-public person enterprises' do |
| 118 | user = create_user('testuser').person | 118 | user = create_user('testuser').person |
| 119 | 119 | ||
| 120 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) | 120 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) |
| @@ -131,4 +131,16 @@ class EnterprisesBlockTest < Test::Unit::TestCase | @@ -131,4 +131,16 @@ class EnterprisesBlockTest < Test::Unit::TestCase | ||
| 131 | assert_equal 1, block.profile_count | 131 | assert_equal 1, block.profile_count |
| 132 | end | 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 | end | 146 | end |
test/unit/friends_block_test.rb
| @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase | @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase | ||
| 62 | assert_equal 3, block.profile_count | 62 | assert_equal 3, block.profile_count |
| 63 | end | 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 | end | 78 | end |
test/unit/members_block_test.rb
| @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase | @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase | ||
| 60 | member2 = mock; member2.stubs(:id).returns(2) | 60 | member2 = mock; member2.stubs(:id).returns(2) |
| 61 | member3 = mock; member3.stubs(:id).returns(3) | 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 | owner.expects(:members).returns([member1, member2, member3]) | 67 | owner.expects(:members).returns([member1, member2, member3]) |
| 64 | 68 | ||
| 65 | block = MembersBlock.new | 69 | block = MembersBlock.new |
| 66 | block.expects(:owner).returns(owner) | 70 | block.expects(:owner).returns(owner) |
| 67 | assert_equal 3, block.profile_count | 71 | assert_equal 3, block.profile_count |
| 68 | end | 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 | end | 88 | end |
| 70 | 89 |