Commit 42a087e6ea2f8eac4c87732302166c9f63e0bc4e
Committed by
Antonio Terceiro
1 parent
c2782255
Exists in
master
and in
22 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
app/models/environment.rb
| ... | ... | @@ -34,6 +34,9 @@ class Environment < ActiveRecord::Base |
| 34 | 34 | 'disable_header_and_footer' => _('Disable header/footer editing by users'), |
| 35 | 35 | 'disable_gender_icon' => _('Disable gender icon'), |
| 36 | 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 | 41 | end |
| 39 | 42 | ... | ... |
app/models/profile.rb
app/views/blocks/profile_info_actions/community.rhtml
| 1 | 1 | <ul> |
| 2 | 2 | <% if logged_in? %> |
| 3 | + | |
| 3 | 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 | 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 | 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 | 20 | <% end %> |
| 9 | 21 | </ul> | ... | ... |
app/views/blocks/profile_info_actions/enterprise.rhtml
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 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 | 5 | <% end %> |
| 6 | 6 | <% end %> |
| 7 | - <% if profile.enable_contact_us %> | |
| 7 | + <% if profile.enable_contact? %> | |
| 8 | 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 | 9 | <% end %> |
| 10 | 10 | </ul> | ... | ... |
app/views/blocks/profile_info_actions/person.rhtml
| 1 | 1 | <ul> |
| 2 | 2 | <%if logged_in? && (user != profile) %> |
| 3 | + | |
| 3 | 4 | <% if !user.already_request_friendship?(profile) and !user.is_a_friend?(profile) %> |
| 4 | 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 | 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 | 12 | <% end %> |
| 7 | 13 | </ul> | ... | ... |
app/views/contact/new.rhtml
| ... | ... | @@ -9,7 +9,9 @@ |
| 9 | 9 | |
| 10 | 10 | <%= required f.text_field(:name) %> |
| 11 | 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 | 15 | <%= required f.text_field(:subject) %> |
| 14 | 16 | <%= required f.text_area(:message, :rows => 10, :cols => 60) %> |
| 15 | 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 | 87 | post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} |
| 88 | 88 | end |
| 89 | 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 | 101 | end | ... | ... |
test/functional/profile_controller_test.rb
| ... | ... | @@ -341,4 +341,67 @@ class ProfileControllerTest < Test::Unit::TestCase |
| 341 | 341 | assert_no_tag :tag => 'a', :attributes => { :href => "/contact/my-test-enterprise/new" }, :content => 'Contact us' |
| 342 | 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 | 407 | end | ... | ... |
test/unit/contact_sender_test.rb
| ... | ... | @@ -55,6 +55,13 @@ class ContactSenderTest < Test::Unit::TestCase |
| 55 | 55 | assert_nil response.cc |
| 56 | 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 | 65 | private |
| 59 | 66 | |
| 60 | 67 | def read_fixture(action) | ... | ... |
test/unit/enterprise_test.rb
| ... | ... | @@ -301,4 +301,11 @@ class EnterpriseTest < Test::Unit::TestCase |
| 301 | 301 | assert ! enterprise.errors.invalid?(:contact_phone) |
| 302 | 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 | 311 | end | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -1184,6 +1184,20 @@ class ProfileTest < Test::Unit::TestCase |
| 1184 | 1184 | assert_equal ['my@email.com'], p.notification_emails |
| 1185 | 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 | 1201 | private |
| 1188 | 1202 | |
| 1189 | 1203 | def assert_invalid_identifier(id) | ... | ... |