Commit c95a33e7d55d59ffdf167deba2834cd7fcfb5b19

Authored by Aurélio A. Heckert
Committed by Rodrigo Souto
1 parent f6596bf9

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.

Conflicts:
	app/controllers/public/catalog_controller.rb
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
@@ -12,7 +12,7 @@ class CatalogController &lt; PublicController @@ -12,7 +12,7 @@ class CatalogController &lt; PublicController
12 protected 12 protected
13 13
14 def check_enterprise_and_environment 14 def check_enterprise_and_environment
15 - unless profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') 15 + unless profile.kind_of?(Enterprise) && @profile.environment.enabled?('products_for_enterprises')
16 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' 16 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
17 end 17 end
18 end 18 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
@@ -95,7 +95,6 @@ class Environment &lt; ActiveRecord::Base @@ -95,7 +95,6 @@ class Environment &lt; ActiveRecord::Base
95 'disable_asset_communities' => __('Disable search for communities'), 95 'disable_asset_communities' => __('Disable search for communities'),
96 'disable_asset_products' => _('Disable search for products'), 96 'disable_asset_products' => _('Disable search for products'),
97 'disable_asset_events' => _('Disable search for events'), 97 'disable_asset_events' => _('Disable search for events'),
98 - 'disable_products_for_enterprises' => __('Disable products for enterprises'),  
99 'disable_categories' => _('Disable categories'), 98 'disable_categories' => _('Disable categories'),
100 'disable_header_and_footer' => _('Disable header/footer editing by users'), 99 'disable_header_and_footer' => _('Disable header/footer editing by users'),
101 'disable_gender_icon' => _('Disable gender icon'), 100 'disable_gender_icon' => _('Disable gender icon'),
@@ -103,9 +102,13 @@ class Environment &lt; ActiveRecord::Base @@ -103,9 +102,13 @@ class Environment &lt; ActiveRecord::Base
103 'disable_select_city_for_contact' => _('Disable state/city select for contact form'), 102 'disable_select_city_for_contact' => _('Disable state/city select for contact form'),
104 'disable_contact_person' => _('Disable contact for people'), 103 'disable_contact_person' => _('Disable contact for people'),
105 'disable_contact_community' => _('Disable contact for groups/communities'), 104 'disable_contact_community' => _('Disable contact for groups/communities'),
106 - 'enterprise_registration' => __('Enterprise registration'),  
107 105
  106 + 'products_for_enterprises' => __('Enable products for enterprises'),
  107 + 'enterprise_registration' => __('Enterprise registration'),
108 'enterprise_activation' => __('Enable activation of enterprises'), 108 'enterprise_activation' => __('Enable activation of enterprises'),
  109 + 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),
  110 + 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),
  111 +
109 'media_panel' => _('Media panel in WYSIWYG editor'), 112 'media_panel' => _('Media panel in WYSIWYG editor'),
110 'select_preferred_domain' => _('Select preferred domains per profile'), 113 'select_preferred_domain' => _('Select preferred domains per profile'),
111 'use_portal_community' => _('Use the portal as news source for front page'), 114 'use_portal_community' => _('Use the portal as news source for front page'),
@@ -118,8 +121,6 @@ class Environment &lt; ActiveRecord::Base @@ -118,8 +121,6 @@ class Environment &lt; ActiveRecord::Base
118 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"), 121 'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"),
119 'enable_organization_url_change' => _("Allow organizations to change their URL"), 122 'enable_organization_url_change' => _("Allow organizations to change their URL"),
120 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"), 123 'admin_must_approve_new_communities' => _("Admin must approve creation of communities"),
121 - 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),  
122 - 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),  
123 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'), 124 'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'),
124 'xmpp_chat' => _('XMPP/Jabber based chat'), 125 'xmpp_chat' => _('XMPP/Jabber based chat'),
125 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'), 126 'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'),
@@ -281,8 +282,9 @@ class Environment &lt; ActiveRecord::Base @@ -281,8 +282,9 @@ class Environment &lt; ActiveRecord::Base
281 end 282 end
282 283
283 # Enables a feature identified by its name 284 # Enables a feature identified by its name
284 - def enable(feature) 285 + def enable(feature, must_save=true)
285 self.settings["#{feature}_enabled".to_sym] = true 286 self.settings["#{feature}_enabled".to_sym] = true
  287 + self.save! if must_save
286 end 288 end
287 289
288 def enable_plugin(plugin) 290 def enable_plugin(plugin)
@@ -292,8 +294,9 @@ class Environment &lt; ActiveRecord::Base @@ -292,8 +294,9 @@ class Environment &lt; ActiveRecord::Base
292 end 294 end
293 295
294 # Disables a feature identified by its name 296 # Disables a feature identified by its name
295 - def disable(feature) 297 + def disable(feature, must_save=true)
296 self.settings["#{feature}_enabled".to_sym] = false 298 self.settings["#{feature}_enabled".to_sym] = false
  299 + self.save! if must_save
297 end 300 end
298 301
299 def disable_plugin(plugin) 302 def disable_plugin(plugin)
@@ -337,7 +340,7 @@ class Environment &lt; ActiveRecord::Base @@ -337,7 +340,7 @@ class Environment &lt; ActiveRecord::Base
337 %w( 340 %w(
338 disable_asset_products 341 disable_asset_products
339 disable_gender_icon 342 disable_gender_icon
340 - disable_products_for_enterprises 343 + products_for_enterprises
341 disable_select_city_for_contact 344 disable_select_city_for_contact
342 enterprise_registration 345 enterprise_registration
343 media_panel 346 media_panel
@@ -345,7 +348,7 @@ class Environment &lt; ActiveRecord::Base @@ -345,7 +348,7 @@ class Environment &lt; ActiveRecord::Base
345 show_balloon_with_profile_links_when_clicked 348 show_balloon_with_profile_links_when_clicked
346 use_portal_community 349 use_portal_community
347 ).each do |feature| 350 ).each do |feature|
348 - enable(feature) 351 + enable(feature, false)
349 end 352 end
350 end 353 end
351 354
app/models/price_detail.rb
@@ -8,7 +8,7 @@ class PriceDetail &lt; ActiveRecord::Base @@ -8,7 +8,7 @@ class PriceDetail &lt; ActiveRecord::Base
8 validates_uniqueness_of :production_cost_id, :scope => :product_id 8 validates_uniqueness_of :production_cost_id, :scope => :product_id
9 9
10 def name 10 def name
11 - production_cost.nil? ? _('other costs') : production_cost.name 11 + production_cost.nil? ? _('Other costs') : production_cost.name
12 end 12 end
13 13
14 def price 14 def price
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