From 04e25fca0e1d2233afa3383103becf2c2f7026ce Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Sat, 16 Nov 2013 17:06:08 +0000 Subject: [PATCH] Add option to disable enterprises list on user menu --- app/helpers/application_helper.rb | 4 ++-- app/models/environment.rb | 3 ++- db/migrate/20131116165327_enable_enterprises_list_on_user_menu.rb | 14 ++++++++++++++ db/schema.rb | 2 +- test/functional/profile_controller_test.rb | 19 ++++++++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20131116165327_enable_enterprises_list_on_user_menu.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 25eee2b..15bac3f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1134,12 +1134,12 @@ module ApplicationHelper end def manage_enterprises - return unless user + return unless user && user.environment.enabled?(:display_my_enterprises_on_user_menu) manage_link(user.enterprises, :enterprises) end def manage_communities - return unless user && user.environment.enabled?('display_my_communities_on_user_menu') + return unless user && user.environment.enabled?(:display_my_communities_on_user_menu) administered_communities = user.communities.more_popular.select {|c| c.admins.include? user} manage_link(administered_communities, :communities) end diff --git a/app/models/environment.rb b/app/models/environment.rb index 3a42c41..f498983 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -128,7 +128,8 @@ class Environment < ActiveRecord::Base 'skip_new_user_email_confirmation' => _('Skip e-mail confirmation for new users'), 'send_welcome_email_to_new_users' => _('Send welcome e-mail to new users'), 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), - 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage') + 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'), + 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage') } end diff --git a/db/migrate/20131116165327_enable_enterprises_list_on_user_menu.rb b/db/migrate/20131116165327_enable_enterprises_list_on_user_menu.rb new file mode 100644 index 0000000..d6fbc15 --- /dev/null +++ b/db/migrate/20131116165327_enable_enterprises_list_on_user_menu.rb @@ -0,0 +1,14 @@ +class EnableEnterprisesListOnUserMenu < ActiveRecord::Migration + def self.up + # The enterprises were always listed on user menu. + # As now it is configured by admin, the running environments should not need to enable it + select_all("select id from environments").each do |environment| + env = Environment.find(environment['id']) + env.enable(:display_my_enterprises_on_user_menu) + end + end + + def self.down + #nothing to be done + end +end diff --git a/db/schema.rb b/db/schema.rb index d26d0a9..2c1ffbf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131011164400) do +ActiveRecord::Schema.define(:version => 20131116165327) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index f4312c4..0acdbf1 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1613,8 +1613,12 @@ class ProfileControllerTest < ActionController::TestCase end end - should 'build menu to the enterprise panel' do + should 'build menu to the enterprise panel if enabled' do u = create_user('other_other_ze').person + + Environment.any_instance.stubs(:enabled?).returns(false) + Environment.any_instance.stubs(:enabled?).with('display_my_enterprises_on_user_menu').returns(true) + Environment.any_instance.stubs(:required_person_fields).returns([]) u.data = { :email => 'test@test.com', :fields_privacy => { } } u.save! @@ -1635,6 +1639,19 @@ class ProfileControllerTest < ActionController::TestCase end end + should 'not build menu to the enterprise panel if not enabled' do + user = create_user('enterprise_admin').person + enterprise = fast_create(Enterprise) + enterprise.add_admin(user) + + Environment.any_instance.stubs(:enabled?).returns(false) + Environment.any_instance.stubs(:enabled?).with('display_my_enterprises_on_user_menu').returns(false) + + login_as(user.identifier) + get :index + assert_no_tag :tag => 'div', :attributes => {:id => 'manage-enterprises'} + end + should 'show enterprises field if enterprises are enabled on environment' do person = fast_create(Person) environment = person.environment -- libgit2 0.21.2