Commit 42a087e6ea2f8eac4c87732302166c9f63e0bc4e
Committed by
Antonio Terceiro
1 parent
c2782255
Exists in
master
and in
28 other branches
ActionItem911: internal messaging system
- show or hide state/city selects according to a configuration - this must work for both person and group - display contact button only for friends - add contact button to communities/groups
Showing
12 changed files
with
136 additions
and
4 deletions
Show diff stats
app/models/enterprise.rb
| @@ -112,6 +112,10 @@ class Enterprise < Organization | @@ -112,6 +112,10 @@ class Enterprise < Organization | ||
| 112 | 112 | ||
| 113 | settings_items :enable_contact_us, :type => :boolean, :default => true | 113 | settings_items :enable_contact_us, :type => :boolean, :default => true |
| 114 | 114 | ||
| 115 | + def enable_contact? | ||
| 116 | + enable_contact_us | ||
| 117 | + end | ||
| 118 | + | ||
| 115 | protected | 119 | protected |
| 116 | 120 | ||
| 117 | def default_homepage(attrs) | 121 | def default_homepage(attrs) |
app/models/environment.rb
| @@ -34,6 +34,9 @@ class Environment < ActiveRecord::Base | @@ -34,6 +34,9 @@ class Environment < ActiveRecord::Base | ||
| 34 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), | 34 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), |
| 35 | 'disable_gender_icon' => _('Disable gender icon'), | 35 | 'disable_gender_icon' => _('Disable gender icon'), |
| 36 | 'disable_categories_menu' => _('Disable the categories menu'), | 36 | 'disable_categories_menu' => _('Disable the categories menu'), |
| 37 | + 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), | ||
| 38 | + 'disable_contact_person' => _('Disable contact for people'), | ||
| 39 | + 'disable_contact_community' => _('Disable contact for groups/communities'), | ||
| 37 | } | 40 | } |
| 38 | end | 41 | end |
| 39 | 42 |
app/models/profile.rb
| @@ -543,4 +543,8 @@ class Profile < ActiveRecord::Base | @@ -543,4 +543,8 @@ class Profile < ActiveRecord::Base | ||
| 543 | self.members_by_role(Profile::Roles.admin) | 543 | self.members_by_role(Profile::Roles.admin) |
| 544 | end | 544 | end |
| 545 | 545 | ||
| 546 | + def enable_contact? | ||
| 547 | + !environment.enabled?('disable_contact_' + self.class.name.downcase) | ||
| 548 | + end | ||
| 549 | + | ||
| 546 | end | 550 | end |
app/views/blocks/profile_info_actions/community.rhtml
| 1 | <ul> | 1 | <ul> |
| 2 | <% if logged_in? %> | 2 | <% if logged_in? %> |
| 3 | + | ||
| 3 | <% if profile.members.include?(user) %> | 4 | <% if profile.members.include?(user) %> |
| 4 | - <li><%= link_to content_tag('span', _('Leave')), { :profile => user.identifier, :controller => 'memberships', :action => 'leave', :id => profile.id }, :class => 'button with-text icon-delete', :title => _('Leave this community') %></li> | 5 | + <li> |
| 6 | + <%= link_to content_tag('span', _('Leave')), { :profile => user.identifier, :controller => 'memberships', :action => 'leave', :id => profile.id }, :class => 'button with-text icon-delete', :title => _('Leave this community') %> | ||
| 7 | + </li> | ||
| 5 | <% else %> | 8 | <% else %> |
| 6 | - <li><%= link_to content_tag('span', _('Join')), { :profile => user.identifier, :controller => 'memberships', :action => 'join', :id => profile.id }, :class => 'button with-text icon-add', :title => _('Join this community') %></li> | 9 | + <li> |
| 10 | + <%= link_to content_tag('span', _('Join')), { :profile => user.identifier, :controller => 'memberships', :action => 'join', :id => profile.id }, :class => 'button with-text icon-add', :title => _('Join this community') %> | ||
| 11 | + </li> | ||
| 7 | <% end %> | 12 | <% end %> |
| 13 | + | ||
| 14 | + <% if profile.enable_contact? %> | ||
| 15 | + <li> | ||
| 16 | + <%= link_to content_tag('span', _('Contact us')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %> | ||
| 17 | + </li> | ||
| 18 | + <% end %> | ||
| 19 | + | ||
| 8 | <% end %> | 20 | <% end %> |
| 9 | </ul> | 21 | </ul> |
app/views/blocks/profile_info_actions/enterprise.rhtml
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | <li><%= link_to content_tag('span', _('Add as favorite')), { :profile => user.identifier, :controller => 'favorite_enterprises', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add', :title => __('Add enterprise as favorite') %></li> | 4 | <li><%= link_to content_tag('span', _('Add as favorite')), { :profile => user.identifier, :controller => 'favorite_enterprises', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add', :title => __('Add enterprise as favorite') %></li> |
| 5 | <% end %> | 5 | <% end %> |
| 6 | <% end %> | 6 | <% end %> |
| 7 | - <% if profile.enable_contact_us %> | 7 | + <% if profile.enable_contact? %> |
| 8 | <li> <%= link_to content_tag('span', _('Contact us')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %> </li> | 8 | <li> <%= link_to content_tag('span', _('Contact us')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %> </li> |
| 9 | <% end %> | 9 | <% end %> |
| 10 | </ul> | 10 | </ul> |
app/views/blocks/profile_info_actions/person.rhtml
| 1 | <ul> | 1 | <ul> |
| 2 | <%if logged_in? && (user != profile) %> | 2 | <%if logged_in? && (user != profile) %> |
| 3 | + | ||
| 3 | <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> | 4 | <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> |
| 4 | <li><%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %></li> | 5 | <li><%= link_to content_tag('span', __('Add friend')), { :profile => user.identifier, :controller => 'friends', :action => 'add', :id => profile.id }, :class => 'button with-text icon-add' %></li> |
| 5 | <% end %> | 6 | <% end %> |
| 7 | + | ||
| 8 | + <% if user.is_a_friend?(profile) && profile.enable_contact? %> | ||
| 9 | + <li> <%= link_to content_tag('span', _('Contact')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %> </li> | ||
| 10 | + <% end %> | ||
| 11 | + | ||
| 6 | <% end %> | 12 | <% end %> |
| 7 | </ul> | 13 | </ul> |
app/views/contact/new.rhtml
| @@ -9,7 +9,9 @@ | @@ -9,7 +9,9 @@ | ||
| 9 | 9 | ||
| 10 | <%= required f.text_field(:name) %> | 10 | <%= required f.text_field(:name) %> |
| 11 | <%= required f.text_field(:email) %> | 11 | <%= required f.text_field(:email) %> |
| 12 | - <%= labelled_form_field _('City and state'), select_city(true) %> | 12 | + <% unless environment.enabled?('disable_select_city_for_contact') %> |
| 13 | + <%= labelled_form_field _('City and state'), select_city(true) %> | ||
| 14 | + <% end %> | ||
| 13 | <%= required f.text_field(:subject) %> | 15 | <%= required f.text_field(:subject) %> |
| 14 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> | 16 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> |
| 15 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> | 17 | <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> |
test/functional/contact_controller_test.rb
| @@ -87,5 +87,15 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -87,5 +87,15 @@ class ContactControllerTest < Test::Unit::TestCase | ||
| 87 | post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | 87 | post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} |
| 88 | end | 88 | end |
| 89 | end | 89 | end |
| 90 | + | ||
| 91 | + should 'not display select/city select when disable it in environment' do | ||
| 92 | + get :new, :profile => profile.identifier | ||
| 93 | + assert_tag :tag => 'select', :attributes => {:name => 'state'} | ||
| 94 | + env = Environment.default | ||
| 95 | + env.enable('disable_select_city_for_contact') | ||
| 96 | + env.save! | ||
| 97 | + get :new, :profile => profile.identifier | ||
| 98 | + assert_no_tag :tag => 'select', :attributes => {:name => 'state'} | ||
| 99 | + end | ||
| 90 | 100 | ||
| 91 | end | 101 | end |
test/functional/profile_controller_test.rb
| @@ -341,4 +341,67 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -341,4 +341,67 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 341 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/my-test-enterprise/new" }, :content => 'Contact us' | 341 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/my-test-enterprise/new" }, :content => 'Contact us' |
| 342 | end | 342 | end |
| 343 | 343 | ||
| 344 | + should 'display contact button only if friends' do | ||
| 345 | + friend = create_user('friend_user').person | ||
| 346 | + @profile.add_friend(friend) | ||
| 347 | + env = Environment.default | ||
| 348 | + env.disable('disable_contact_person') | ||
| 349 | + env.save! | ||
| 350 | + login_as(@profile.identifier) | ||
| 351 | + get :index, :profile => friend.identifier | ||
| 352 | + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } | ||
| 353 | + end | ||
| 354 | + | ||
| 355 | + should 'not display contact button if no friends' do | ||
| 356 | + nofriend = create_user('no_friend').person | ||
| 357 | + login_as(@profile.identifier) | ||
| 358 | + get :index, :profile => nofriend.identifier | ||
| 359 | + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{nofriend.identifier}/new" } | ||
| 360 | + end | ||
| 361 | + | ||
| 362 | + should 'display contact button only if friends and its enable in environment' do | ||
| 363 | + friend = create_user('friend_user').person | ||
| 364 | + env = Environment.default | ||
| 365 | + env.disable('disable_contact_person') | ||
| 366 | + env.save! | ||
| 367 | + @profile.add_friend(friend) | ||
| 368 | + login_as(@profile.identifier) | ||
| 369 | + get :index, :profile => friend.identifier | ||
| 370 | + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } | ||
| 371 | + end | ||
| 372 | + | ||
| 373 | + should 'not display contact button if friends and its disable in environment' do | ||
| 374 | + friend = create_user('friend_user').person | ||
| 375 | + env = Environment.default | ||
| 376 | + env.enable('disable_contact_person') | ||
| 377 | + env.save! | ||
| 378 | + @profile.add_friend(friend) | ||
| 379 | + login_as(@profile.identifier) | ||
| 380 | + get :index, :profile => friend.identifier | ||
| 381 | + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } | ||
| 382 | + end | ||
| 383 | + | ||
| 384 | + should 'display contact button for community if its enable in environment' do | ||
| 385 | + friend = create_user('friend_user').person | ||
| 386 | + env = Environment.default | ||
| 387 | + community = Community.create!(:name => 'my test community', :environment => env) | ||
| 388 | + env.disable('disable_contact_community') | ||
| 389 | + env.save! | ||
| 390 | + community.add_member(@profile) | ||
| 391 | + login_as(@profile.identifier) | ||
| 392 | + get :index, :profile => community.identifier | ||
| 393 | + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{community.identifier}/new" } | ||
| 394 | + end | ||
| 395 | + | ||
| 396 | + should 'not display contact button for community if its disable in environment' do | ||
| 397 | + env = Environment.default | ||
| 398 | + community = Community.create!(:name => 'my test community', :environment => env) | ||
| 399 | + env.enable('disable_contact_community') | ||
| 400 | + env.save! | ||
| 401 | + community.add_member(@profile) | ||
| 402 | + login_as(@profile.identifier) | ||
| 403 | + get :index, :profile => community.identifier | ||
| 404 | + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{community.identifier}/new" } | ||
| 405 | + end | ||
| 406 | + | ||
| 344 | end | 407 | end |
test/unit/contact_sender_test.rb
| @@ -55,6 +55,13 @@ class ContactSenderTest < Test::Unit::TestCase | @@ -55,6 +55,13 @@ class ContactSenderTest < Test::Unit::TestCase | ||
| 55 | assert_nil response.cc | 55 | assert_nil response.cc |
| 56 | end | 56 | end |
| 57 | 57 | ||
| 58 | + should 'only deliver mail to email of person' do | ||
| 59 | + person = create_user('contacted_user').person | ||
| 60 | + c = Contact.new(:dest => person) | ||
| 61 | + response = Contact::Sender.deliver_mail(c) | ||
| 62 | + assert_equal [person.email], response.to | ||
| 63 | + end | ||
| 64 | + | ||
| 58 | private | 65 | private |
| 59 | 66 | ||
| 60 | def read_fixture(action) | 67 | def read_fixture(action) |
test/unit/enterprise_test.rb
| @@ -301,4 +301,11 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -301,4 +301,11 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 301 | assert ! enterprise.errors.invalid?(:contact_phone) | 301 | assert ! enterprise.errors.invalid?(:contact_phone) |
| 302 | end | 302 | end |
| 303 | 303 | ||
| 304 | + should 'enable contact' do | ||
| 305 | + enterprise = Enterprise.new(:enable_contact_us => false) | ||
| 306 | + assert !enterprise.enable_contact? | ||
| 307 | + enterprise.enable_contact_us = true | ||
| 308 | + assert enterprise.enable_contact? | ||
| 309 | + end | ||
| 310 | + | ||
| 304 | end | 311 | end |
test/unit/profile_test.rb
| @@ -1184,6 +1184,20 @@ class ProfileTest < Test::Unit::TestCase | @@ -1184,6 +1184,20 @@ class ProfileTest < Test::Unit::TestCase | ||
| 1184 | assert_equal ['my@email.com'], p.notification_emails | 1184 | assert_equal ['my@email.com'], p.notification_emails |
| 1185 | end | 1185 | end |
| 1186 | 1186 | ||
| 1187 | + should 'enable contact for person only if its features enabled in environment' do | ||
| 1188 | + env = Environment.default | ||
| 1189 | + env.disable('disable_contact_person') | ||
| 1190 | + person = Person.new(:name => 'Contacted', :environment => env) | ||
| 1191 | + assert person.enable_contact? | ||
| 1192 | + end | ||
| 1193 | + | ||
| 1194 | + should 'enable contact for community only if its features enabled in environment' do | ||
| 1195 | + env = Environment.default | ||
| 1196 | + env.disable('disable_contact_person') | ||
| 1197 | + community = Community.new(:name => 'Contacted', :environment => env) | ||
| 1198 | + assert community.enable_contact? | ||
| 1199 | + end | ||
| 1200 | + | ||
| 1187 | private | 1201 | private |
| 1188 | 1202 | ||
| 1189 | def assert_invalid_identifier(id) | 1203 | def assert_invalid_identifier(id) |