From 42a087e6ea2f8eac4c87732302166c9f63e0bc4e Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Thu, 22 Jan 2009 16:48:43 -0300 Subject: [PATCH] ActionItem911: internal messaging system --- app/models/enterprise.rb | 4 ++++ app/models/environment.rb | 3 +++ app/models/profile.rb | 4 ++++ app/views/blocks/profile_info_actions/community.rhtml | 16 ++++++++++++++-- app/views/blocks/profile_info_actions/enterprise.rhtml | 2 +- app/views/blocks/profile_info_actions/person.rhtml | 6 ++++++ app/views/contact/new.rhtml | 4 +++- test/functional/contact_controller_test.rb | 10 ++++++++++ test/functional/profile_controller_test.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/contact_sender_test.rb | 7 +++++++ test/unit/enterprise_test.rb | 7 +++++++ test/unit/profile_test.rb | 14 ++++++++++++++ 12 files changed, 136 insertions(+), 4 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 3c6c338..b324b70 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -112,6 +112,10 @@ class Enterprise < Organization settings_items :enable_contact_us, :type => :boolean, :default => true + def enable_contact? + enable_contact_us + end + protected def default_homepage(attrs) diff --git a/app/models/environment.rb b/app/models/environment.rb index 5a71630..601fe7e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -34,6 +34,9 @@ class Environment < ActiveRecord::Base 'disable_header_and_footer' => _('Disable header/footer editing by users'), 'disable_gender_icon' => _('Disable gender icon'), 'disable_categories_menu' => _('Disable the categories menu'), + 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), + 'disable_contact_person' => _('Disable contact for people'), + 'disable_contact_community' => _('Disable contact for groups/communities'), } end diff --git a/app/models/profile.rb b/app/models/profile.rb index 530911d..9e4b60d 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -543,4 +543,8 @@ class Profile < ActiveRecord::Base self.members_by_role(Profile::Roles.admin) end + def enable_contact? + !environment.enabled?('disable_contact_' + self.class.name.downcase) + end + end diff --git a/app/views/blocks/profile_info_actions/community.rhtml b/app/views/blocks/profile_info_actions/community.rhtml index 3ff89ce..422ea07 100644 --- a/app/views/blocks/profile_info_actions/community.rhtml +++ b/app/views/blocks/profile_info_actions/community.rhtml @@ -1,9 +1,21 @@ diff --git a/app/views/blocks/profile_info_actions/enterprise.rhtml b/app/views/blocks/profile_info_actions/enterprise.rhtml index 8ccf7ed..584f2c9 100644 --- a/app/views/blocks/profile_info_actions/enterprise.rhtml +++ b/app/views/blocks/profile_info_actions/enterprise.rhtml @@ -4,7 +4,7 @@
  • <%= 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') %>
  • <% end %> <% end %> - <% if profile.enable_contact_us %> + <% if profile.enable_contact? %>
  • <%= link_to content_tag('span', _('Contact us')), {:profile => profile.identifier, :controller => 'contact', :action => 'new'}, :class => 'button with-text icon-menu-mail' %>
  • <% end %> diff --git a/app/views/blocks/profile_info_actions/person.rhtml b/app/views/blocks/profile_info_actions/person.rhtml index cf7854a..6f47392 100644 --- a/app/views/blocks/profile_info_actions/person.rhtml +++ b/app/views/blocks/profile_info_actions/person.rhtml @@ -1,7 +1,13 @@ diff --git a/app/views/contact/new.rhtml b/app/views/contact/new.rhtml index c315f92..0cbe865 100644 --- a/app/views/contact/new.rhtml +++ b/app/views/contact/new.rhtml @@ -9,7 +9,9 @@ <%= required f.text_field(:name) %> <%= required f.text_field(:email) %> - <%= labelled_form_field _('City and state'), select_city(true) %> + <% unless environment.enabled?('disable_select_city_for_contact') %> + <%= labelled_form_field _('City and state'), select_city(true) %> + <% end %> <%= required f.text_field(:subject) %> <%= required f.text_area(:message, :rows => 10, :cols => 60) %> <%= labelled_form_field check_box(:contact, :receive_a_copy) + _('I want to receive a copy of the message in my e-mail.'), '' %> diff --git a/test/functional/contact_controller_test.rb b/test/functional/contact_controller_test.rb index e8c9159..48929f8 100644 --- a/test/functional/contact_controller_test.rb +++ b/test/functional/contact_controller_test.rb @@ -87,5 +87,15 @@ class ContactControllerTest < Test::Unit::TestCase post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} end end + + should 'not display select/city select when disable it in environment' do + get :new, :profile => profile.identifier + assert_tag :tag => 'select', :attributes => {:name => 'state'} + env = Environment.default + env.enable('disable_select_city_for_contact') + env.save! + get :new, :profile => profile.identifier + assert_no_tag :tag => 'select', :attributes => {:name => 'state'} + end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index ef7a99e..667f113 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -341,4 +341,67 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :attributes => { :href => "/contact/my-test-enterprise/new" }, :content => 'Contact us' end + should 'display contact button only if friends' do + friend = create_user('friend_user').person + @profile.add_friend(friend) + env = Environment.default + env.disable('disable_contact_person') + env.save! + login_as(@profile.identifier) + get :index, :profile => friend.identifier + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } + end + + should 'not display contact button if no friends' do + nofriend = create_user('no_friend').person + login_as(@profile.identifier) + get :index, :profile => nofriend.identifier + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{nofriend.identifier}/new" } + end + + should 'display contact button only if friends and its enable in environment' do + friend = create_user('friend_user').person + env = Environment.default + env.disable('disable_contact_person') + env.save! + @profile.add_friend(friend) + login_as(@profile.identifier) + get :index, :profile => friend.identifier + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } + end + + should 'not display contact button if friends and its disable in environment' do + friend = create_user('friend_user').person + env = Environment.default + env.enable('disable_contact_person') + env.save! + @profile.add_friend(friend) + login_as(@profile.identifier) + get :index, :profile => friend.identifier + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{friend.identifier}/new" } + end + + should 'display contact button for community if its enable in environment' do + friend = create_user('friend_user').person + env = Environment.default + community = Community.create!(:name => 'my test community', :environment => env) + env.disable('disable_contact_community') + env.save! + community.add_member(@profile) + login_as(@profile.identifier) + get :index, :profile => community.identifier + assert_tag :tag => 'a', :attributes => { :href => "/contact/#{community.identifier}/new" } + end + + should 'not display contact button for community if its disable in environment' do + env = Environment.default + community = Community.create!(:name => 'my test community', :environment => env) + env.enable('disable_contact_community') + env.save! + community.add_member(@profile) + login_as(@profile.identifier) + get :index, :profile => community.identifier + assert_no_tag :tag => 'a', :attributes => { :href => "/contact/#{community.identifier}/new" } + end + end diff --git a/test/unit/contact_sender_test.rb b/test/unit/contact_sender_test.rb index 0e313f1..b0cbefe 100644 --- a/test/unit/contact_sender_test.rb +++ b/test/unit/contact_sender_test.rb @@ -55,6 +55,13 @@ class ContactSenderTest < Test::Unit::TestCase assert_nil response.cc end + should 'only deliver mail to email of person' do + person = create_user('contacted_user').person + c = Contact.new(:dest => person) + response = Contact::Sender.deliver_mail(c) + assert_equal [person.email], response.to + end + private def read_fixture(action) diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 73a7909..0462dd4 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -301,4 +301,11 @@ class EnterpriseTest < Test::Unit::TestCase assert ! enterprise.errors.invalid?(:contact_phone) end + should 'enable contact' do + enterprise = Enterprise.new(:enable_contact_us => false) + assert !enterprise.enable_contact? + enterprise.enable_contact_us = true + assert enterprise.enable_contact? + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 8f513b1..4224231 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1184,6 +1184,20 @@ class ProfileTest < Test::Unit::TestCase assert_equal ['my@email.com'], p.notification_emails end + should 'enable contact for person only if its features enabled in environment' do + env = Environment.default + env.disable('disable_contact_person') + person = Person.new(:name => 'Contacted', :environment => env) + assert person.enable_contact? + end + + should 'enable contact for community only if its features enabled in environment' do + env = Environment.default + env.disable('disable_contact_person') + community = Community.new(:name => 'Contacted', :environment => env) + assert community.enable_contact? + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2