Commit 5a86933d05bc4c57ac929546a83b772753228b8a

Authored by Aurélio A. Heckert
1 parent 11db1ebe

Translate disable_products_for_enterprises_enabled env setting

The disable_* settings for environment are incoherent with the
user interface and with the code itself. This changes correct
only one incoherent setting as an example how to do with all
others.
app/controllers/my_profile/manage_products_controller.rb
@@ -6,10 +6,10 @@ class ManageProductsController < ApplicationController @@ -6,10 +6,10 @@ class ManageProductsController < ApplicationController
6 before_filter :login_required, :except => [:show] 6 before_filter :login_required, :except => [:show]
7 before_filter :create_product?, :only => [:new] 7 before_filter :create_product?, :only => [:new]
8 8
9 - protected 9 + protected
10 10
11 def check_environment_feature 11 def check_environment_feature
12 - if profile.environment.enabled?('disable_products_for_enterprises') 12 + unless profile.environment.enabled?('products_for_enterprises')
13 render_not_found 13 render_not_found
14 return 14 return
15 end 15 end
app/controllers/my_profile/profile_design_controller.rb
@@ -38,7 +38,7 @@ class ProfileDesignController < BoxOrganizerController @@ -38,7 +38,7 @@ class ProfileDesignController < BoxOrganizerController
38 end 38 end
39 39
40 # product block exclusive for enterprises in environments that permits it 40 # product block exclusive for enterprises in environments that permits it
41 - if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises') 41 + if profile.enterprise? && profile.environment.enabled?('products_for_enterprises')
42 blocks << ProductsBlock 42 blocks << ProductsBlock
43 end 43 end
44 44
app/controllers/public/catalog_controller.rb
@@ -13,7 +13,7 @@ class CatalogController &lt; PublicController @@ -13,7 +13,7 @@ class CatalogController &lt; PublicController
13 protected 13 protected
14 14
15 def check_enterprise_and_environment 15 def check_enterprise_and_environment
16 - unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_products_for_enterprises') 16 + unless @profile.kind_of?(Enterprise) && @profile.environment.enabled?('products_for_enterprises')
17 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' 17 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
18 end 18 end
19 end 19 end
app/models/enterprise.rb
@@ -134,7 +134,7 @@ class Enterprise &lt; Organization @@ -134,7 +134,7 @@ class Enterprise &lt; Organization
134 [ProfileImageBlock.new, LinkListBlock.new(:links => links)], 134 [ProfileImageBlock.new, LinkListBlock.new(:links => links)],
135 [] 135 []
136 ] 136 ]
137 - if !environment.enabled?('disable_products_for_enterprises') 137 + if environment.enabled?('products_for_enterprises')
138 blocks[2].unshift ProductsBlock.new 138 blocks[2].unshift ProductsBlock.new
139 end 139 end
140 blocks 140 blocks
app/models/environment.rb
@@ -94,7 +94,6 @@ class Environment &lt; ActiveRecord::Base @@ -94,7 +94,6 @@ class Environment &lt; ActiveRecord::Base
94 'disable_asset_communities' => __('Disable search for communities'), 94 'disable_asset_communities' => __('Disable search for communities'),
95 'disable_asset_products' => _('Disable search for products'), 95 'disable_asset_products' => _('Disable search for products'),
96 'disable_asset_events' => _('Disable search for events'), 96 'disable_asset_events' => _('Disable search for events'),
97 - 'disable_products_for_enterprises' => __('Disable products for enterprises'),  
98 'disable_categories' => _('Disable categories'), 97 'disable_categories' => _('Disable categories'),
99 'disable_header_and_footer' => _('Disable header/footer editing by users'), 98 'disable_header_and_footer' => _('Disable header/footer editing by users'),
100 'disable_gender_icon' => _('Disable gender icon'), 99 'disable_gender_icon' => _('Disable gender icon'),
@@ -102,9 +101,13 @@ class Environment &lt; ActiveRecord::Base @@ -102,9 +101,13 @@ class Environment &lt; ActiveRecord::Base
102 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), 101 'disable_select_city_for_contact' => _('Disable state/city select for contact form'),
103 'disable_contact_person' => _('Disable contact for people'), 102 'disable_contact_person' => _('Disable contact for people'),
104 'disable_contact_community' => _('Disable contact for groups/communities'), 103 'disable_contact_community' => _('Disable contact for groups/communities'),
105 - 'enterprise_registration' => __('Enterprise registration'),  
106 104
  105 + 'products_for_enterprises' => __('Enable products for enterprises'),
  106 + 'enterprise_registration' => __('Enterprise registration'),
107 'enterprise_activation' => __('Enable activation of enterprises'), 107 'enterprise_activation' => __('Enable activation of enterprises'),
  108 + 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),
  109 + 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),
  110 +
108 'media_panel' => _('Media panel in WYSIWYG editor'), 111 'media_panel' => _('Media panel in WYSIWYG editor'),
109 'select_preferred_domain' => _('Select preferred domains per profile'), 112 'select_preferred_domain' => _('Select preferred domains per profile'),
110 'use_portal_community' => _('Use the portal as news source for front page'), 113 'use_portal_community' => _('Use the portal as news source for front page'),
@@ -117,8 +120,6 @@ class Environment &lt; ActiveRecord::Base @@ -117,8 +120,6 @@ class Environment &lt; ActiveRecord::Base
117 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"), 120 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"),
118 'enable_organization_url_change' => _("Allow organizations to change their URL"), 121 'enable_organization_url_change' => _("Allow organizations to change their URL"),
119 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"), 122 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"),
120 - 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),  
121 - 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),  
122 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'), 123 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'),
123 'xmpp_chat' => _('XMPP/Jabber based chat'), 124 'xmpp_chat' => _('XMPP/Jabber based chat'),
124 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), 125 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'),
@@ -273,8 +274,9 @@ class Environment &lt; ActiveRecord::Base @@ -273,8 +274,9 @@ class Environment &lt; ActiveRecord::Base
273 end 274 end
274 275
275 # Enables a feature identified by its name 276 # Enables a feature identified by its name
276 - def enable(feature) 277 + def enable(feature, must_save=true)
277 self.settings["#{feature}_enabled".to_sym] = true 278 self.settings["#{feature}_enabled".to_sym] = true
  279 + self.save! if must_save
278 end 280 end
279 281
280 def enable_plugin(plugin) 282 def enable_plugin(plugin)
@@ -284,8 +286,9 @@ class Environment &lt; ActiveRecord::Base @@ -284,8 +286,9 @@ class Environment &lt; ActiveRecord::Base
284 end 286 end
285 287
286 # Disables a feature identified by its name 288 # Disables a feature identified by its name
287 - def disable(feature) 289 + def disable(feature, must_save=true)
288 self.settings["#{feature}_enabled".to_sym] = false 290 self.settings["#{feature}_enabled".to_sym] = false
  291 + self.save! if must_save
289 end 292 end
290 293
291 def disable_plugin(plugin) 294 def disable_plugin(plugin)
@@ -329,7 +332,7 @@ class Environment &lt; ActiveRecord::Base @@ -329,7 +332,7 @@ class Environment &lt; ActiveRecord::Base
329 %w( 332 %w(
330 disable_asset_products 333 disable_asset_products
331 disable_gender_icon 334 disable_gender_icon
332 - disable_products_for_enterprises 335 + products_for_enterprises
333 disable_select_city_for_contact 336 disable_select_city_for_contact
334 enterprise_registration 337 enterprise_registration
335 media_panel 338 media_panel
@@ -337,7 +340,7 @@ class Environment &lt; ActiveRecord::Base @@ -337,7 +340,7 @@ class Environment &lt; ActiveRecord::Base
337 show_balloon_with_profile_links_when_clicked 340 show_balloon_with_profile_links_when_clicked
338 use_portal_community 341 use_portal_community
339 ).each do |feature| 342 ).each do |feature|
340 - enable(feature) 343 + enable(feature, false)
341 end 344 end
342 end 345 end
343 346
app/views/blocks/profile_info.rhtml
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 <ul class="profile-info-data" id="profile-info-data-<%= block.id %>"> 17 <ul class="profile-info-data" id="profile-info-data-<%= block.id %>">
18 <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li> 18 <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li>
19 <li><%= link_to _('View profile'), block.owner.public_profile_url %></li> 19 <li><%= link_to _('View profile'), block.owner.public_profile_url %></li>
20 - <% if block.owner.enterprise? && !block.owner.environment.enabled?('disable_products_for_enterprises') %> 20 + <% if block.owner.enterprise? && block.owner.environment.enabled?('products_for_enterprises') %>
21 <li><%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) %></li> 21 <li><%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) %></li>
22 <% end %> 22 <% end %>
23 <li id="profile-admin-url-<%= block.id %>"></li> 23 <li id="profile-admin-url-<%= block.id %>"></li>
app/views/content_viewer/_enterprise_homepage.rhtml
1 <%= display_profile_info enterprise_homepage.profile %> 1 <%= display_profile_info enterprise_homepage.profile %>
2 <div><%= enterprise_homepage.body %></div> 2 <div><%= enterprise_homepage.body %></div>
3 -<%= render :file => 'catalog/index' unless enterprise_homepage.profile.environment.enabled?('disable_products_for_enterprises') %> 3 +<%= render :file => 'catalog/index' if enterprise_homepage.profile.environment.enabled?('products_for_enterprises') %>
app/views/profile/_organization_profile.rhtml
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 <td><%= show_date(profile.created_at) %></td> 19 <td><%= show_date(profile.created_at) %></td>
20 </tr> 20 </tr>
21 21
22 - <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %> 22 + <% if profile.kind_of?(Enterprise) && profile.environment.enabled?('products_for_enterprises') %>
23 <tr> 23 <tr>
24 <td></td> 24 <td></td>
25 <td> 25 <td>
app/views/profile_editor/index.rhtml
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 45
46 <%= control_panel_button(_('Manage Members'), 'members', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %> 46 <%= control_panel_button(_('Manage Members'), 'members', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %>
47 47
48 - <%= control_panel_button(_('Manage Products and Services'), 'products', :controller => 'manage_products') if profile.enterprise? && !environment.enabled?('disable_products_for_enterprises') %> 48 + <%= control_panel_button(_('Manage Products and Services'), 'products', :controller => 'manage_products') if profile.enterprise? && environment.enabled?('products_for_enterprises') %>
49 49
50 <% if !environment.enabled?('disable_asset_enterprises') %> 50 <% if !environment.enabled?('disable_asset_enterprises') %>
51 <% if profile.is_validation_entity? %> 51 <% if profile.is_validation_entity? %>
db/migrate/20130529155000_rename_environment_setting_disable_products.rb 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +class RenameEnvironmentSettingDisableProducts < ActiveRecord::Migration
  2 + def self.up
  3 + select_all("select id from environments").each do |environment|
  4 + env = Environment.find(environment['id'])
  5 + env.settings[:products_for_enterprises_enabled] =
  6 + !env.settings[:disable_products_for_enterprises_enabled]
  7 + env.settings.delete :disable_products_for_enterprises_enabled
  8 + env.save!
  9 + end
  10 + end
  11 +
  12 + def self.down
  13 + select_all("select id from environments").each do |environment|
  14 + env = Environment.find(environment['id'])
  15 + env.settings[:disable_products_for_enterprises_enabled] =
  16 + !env.settings[:products_for_enterprises_enabled]
  17 + env.settings.delete :products_for_enterprises_enabled
  18 + env.save!
  19 + end
  20 + end
  21 +end
test/functional/catalog_controller_test.rb
@@ -10,6 +10,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -10,6 +10,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
10 @request = ActionController::TestRequest.new 10 @request = ActionController::TestRequest.new
11 @response = ActionController::TestResponse.new 11 @response = ActionController::TestResponse.new
12 12
  13 + Environment.default.enable('products_for_enterprises')
13 @enterprise = fast_create(Enterprise, :name => 'My enterprise', :identifier => 'testent') 14 @enterprise = fast_create(Enterprise, :name => 'My enterprise', :identifier => 'testent')
14 @product_category = fast_create(ProductCategory) 15 @product_category = fast_create(ProductCategory)
15 end 16 end
@@ -52,7 +53,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -52,7 +53,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
52 53
53 should 'not give access if environment do not let' do 54 should 'not give access if environment do not let' do
54 env = Environment.default 55 env = Environment.default
55 - env.enable('disable_products_for_enterprises') 56 + env.disable('products_for_enterprises')
56 env.save! 57 env.save!
57 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id) 58 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id)
58 get :index, :profile => ent.identifier 59 get :index, :profile => ent.identifier
test/functional/manage_products_controller_test.rb
@@ -13,6 +13,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -13,6 +13,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
13 @enterprise = fast_create(Enterprise, :name => 'teste', :identifier => 'test_ent') 13 @enterprise = fast_create(Enterprise, :name => 'teste', :identifier => 'test_ent')
14 @user = create_user_with_permission('test_user', 'manage_products', @enterprise) 14 @user = create_user_with_permission('test_user', 'manage_products', @enterprise)
15 @environment = @enterprise.environment 15 @environment = @enterprise.environment
  16 + @environment.enable('products_for_enterprises')
16 @product_category = fast_create(ProductCategory) 17 @product_category = fast_create(ProductCategory)
17 login_as :test_user 18 login_as :test_user
18 end 19 end
@@ -191,7 +192,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -191,7 +192,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
191 192
192 should 'not let users in if environment do not let' do 193 should 'not let users in if environment do not let' do
193 env = Environment.default 194 env = Environment.default
194 - env.enable('disable_products_for_enterprises') 195 + env.disable('products_for_enterprises')
195 env.save! 196 env.save!
196 @enterprise.environment = env 197 @enterprise.environment = env
197 @enterprise.save! 198 @enterprise.save!
test/functional/profile_controller_test.rb
@@ -9,7 +9,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -9,7 +9,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
9 @controller = ProfileController.new 9 @controller = ProfileController.new
10 @request = ActionController::TestRequest.new 10 @request = ActionController::TestRequest.new
11 @response = ActionController::TestResponse.new 11 @response = ActionController::TestResponse.new
12 - 12 + Environment.default.enable('products_for_enterprises')
13 @profile = create_user('testuser').person 13 @profile = create_user('testuser').person
14 end 14 end
15 attr_reader :profile 15 attr_reader :profile
@@ -263,8 +263,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -263,8 +263,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
263 263
264 should 'not display "Products" link for enterprise if environment do not let' do 264 should 'not display "Products" link for enterprise if environment do not let' do
265 env = Environment.default 265 env = Environment.default
266 - env.enable('disable_products_for_enterprises')  
267 - env.save! 266 + env.disable('products_for_enterprises')
268 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false, :environment_id => env.id) 267 ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false, :environment_id => env.id)
269 268
270 get :index, :profile => 'my-test-enterprise' 269 get :index, :profile => 'my-test-enterprise'
test/functional/profile_design_controller_test.rb
@@ -395,7 +395,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -395,7 +395,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
395 395
396 should 'not allow products block if environment do not let' do 396 should 'not allow products block if environment do not let' do
397 env = Environment.default 397 env = Environment.default
398 - env.enable('disable_products_for_enterprises') 398 + env.disable('products_for_enterprises')
399 env.save! 399 env.save!
400 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id) 400 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id)
401 person = create_user_with_permission('test_user', 'edit_profile_design', ent) 401 person = create_user_with_permission('test_user', 'edit_profile_design', ent)
@@ -530,6 +530,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -530,6 +530,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
530 environment = mock 530 environment = mock
531 profile.stubs(:environment).returns(environment) 531 profile.stubs(:environment).returns(environment)
532 environment.stubs(:enabled?).returns(true) 532 environment.stubs(:enabled?).returns(true)
  533 + environment.stubs(:enabled?).with('products_for_enterprises').returns(false)
533 @controller.stubs(:profile).returns(profile) 534 @controller.stubs(:profile).returns(profile)
534 @controller.stubs(:user).returns(profile) 535 @controller.stubs(:user).returns(profile)
535 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) 536 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
@@ -546,7 +547,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase @@ -546,7 +547,7 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
546 profile.stubs(:is_admin?).with(anything).returns(false) 547 profile.stubs(:is_admin?).with(anything).returns(false)
547 environment = mock 548 environment = mock
548 profile.stubs(:environment).returns(environment) 549 profile.stubs(:environment).returns(environment)
549 - environment.stubs(:enabled?).returns(false) 550 + environment.stubs(:enabled?).returns(true)
550 @controller.stubs(:profile).returns(profile) 551 @controller.stubs(:profile).returns(profile)
551 @controller.stubs(:user).returns(profile) 552 @controller.stubs(:user).returns(profile)
552 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) 553 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
test/functional/profile_editor_controller_test.rb
@@ -559,7 +559,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -559,7 +559,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
559 559
560 should 'not list the manage products button if the environment disabled it' do 560 should 'not list the manage products button if the environment disabled it' do
561 env = Environment.default 561 env = Environment.default
562 - env.enable('disable_products_for_enterprises') 562 + env.disable('products_for_enterprises')
563 env.save! 563 env.save!
564 ent = fast_create(Enterprise) 564 ent = fast_create(Enterprise)
565 565
test/unit/enterprise_test.rb
@@ -5,6 +5,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -5,6 +5,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
5 5
6 def setup 6 def setup
7 super 7 super
  8 + Environment.default.enable('products_for_enterprises')
8 @product_category = fast_create(ProductCategory, :name => 'Products') 9 @product_category = fast_create(ProductCategory, :name => 'Products')
9 end 10 end
10 11
@@ -80,9 +81,9 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -80,9 +81,9 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
80 should 'create default set of blocks' do 81 should 'create default set of blocks' do
81 e = Enterprise.create(:name => 'my new community', :identifier => 'mynewcommunity') 82 e = Enterprise.create(:name => 'my new community', :identifier => 'mynewcommunity')
82 83
83 - assert !e.boxes[0].blocks.empty?, 'person must have blocks in area 1'  
84 - assert !e.boxes[1].blocks.empty?, 'person must have blocks in area 2'  
85 - assert !e.boxes[2].blocks.empty?, 'person must have blocks in area 3' 84 + assert !e.boxes[0].blocks.empty?, 'enterprise must have blocks in area 1'
  85 + assert !e.boxes[1].blocks.empty?, 'enterprise must have blocks in area 2'
  86 + assert !e.boxes[2].blocks.empty?, 'enterprise must have blocks in area 3'
86 end 87 end
87 88
88 should 'allow to add new members if has no members' do 89 should 'allow to add new members if has no members' do
@@ -242,8 +243,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -242,8 +243,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
242 243
243 should 'not create a products block for enterprise if environment do not let' do 244 should 'not create a products block for enterprise if environment do not let' do
244 env = Environment.default 245 env = Environment.default
245 - env.enable('disable_products_for_enterprises')  
246 - env.save! 246 + env.disable('products_for_enterprises')
247 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent') 247 ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent')
248 assert_not_includes ent.blocks.map(&:class), ProductsBlock 248 assert_not_includes ent.blocks.map(&:class), ProductsBlock
249 end 249 end