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