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