diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb
index ed181dc..575d510 100644
--- a/app/controllers/my_profile/manage_products_controller.rb
+++ b/app/controllers/my_profile/manage_products_controller.rb
@@ -6,10 +6,10 @@ class ManageProductsController < ApplicationController
before_filter :login_required, :except => [:show]
before_filter :create_product?, :only => [:new]
- protected
+ protected
def check_environment_feature
- if profile.environment.enabled?('disable_products_for_enterprises')
+ unless profile.environment.enabled?('products_for_enterprises')
render_not_found
return
end
diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb
index 69b7a62..5ee727a 100644
--- a/app/controllers/my_profile/profile_design_controller.rb
+++ b/app/controllers/my_profile/profile_design_controller.rb
@@ -38,7 +38,7 @@ class ProfileDesignController < BoxOrganizerController
end
# product block exclusive for enterprises in environments that permits it
- if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises')
+ if profile.enterprise? && profile.environment.enabled?('products_for_enterprises')
blocks << ProductsBlock
end
diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb
index dd0929a..26178b3 100644
--- a/app/controllers/public/catalog_controller.rb
+++ b/app/controllers/public/catalog_controller.rb
@@ -12,7 +12,7 @@ class CatalogController < PublicController
protected
def check_enterprise_and_environment
- unless profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises')
+ unless profile.kind_of?(Enterprise) && @profile.environment.enabled?('products_for_enterprises')
redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
end
end
diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb
index 89e3962..5982444 100644
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -134,7 +134,7 @@ class Enterprise < Organization
[ProfileImageBlock.new, LinkListBlock.new(:links => links)],
[]
]
- if !environment.enabled?('disable_products_for_enterprises')
+ if environment.enabled?('products_for_enterprises')
blocks[2].unshift ProductsBlock.new
end
blocks
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 7ef039e..d736363 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -95,7 +95,6 @@ class Environment < ActiveRecord::Base
'disable_asset_communities' => __('Disable search for communities'),
'disable_asset_products' => _('Disable search for products'),
'disable_asset_events' => _('Disable search for events'),
- 'disable_products_for_enterprises' => __('Disable products for enterprises'),
'disable_categories' => _('Disable categories'),
'disable_header_and_footer' => _('Disable header/footer editing by users'),
'disable_gender_icon' => _('Disable gender icon'),
@@ -103,9 +102,13 @@ class Environment < ActiveRecord::Base
'disable_select_city_for_contact' => _('Disable state/city select for contact form'),
'disable_contact_person' => _('Disable contact for people'),
'disable_contact_community' => _('Disable contact for groups/communities'),
- 'enterprise_registration' => __('Enterprise registration'),
+ 'products_for_enterprises' => __('Enable products for enterprises'),
+ 'enterprise_registration' => __('Enterprise registration'),
'enterprise_activation' => __('Enable activation of enterprises'),
+ 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),
+ 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),
+
'media_panel' => _('Media panel in WYSIWYG editor'),
'select_preferred_domain' => _('Select preferred domains per profile'),
'use_portal_community' => _('Use the portal as news source for front page'),
@@ -118,8 +121,6 @@ class Environment < ActiveRecord::Base
'organizations_are_moderated_by_default' => _("Organizations have moderated publication by default"),
'enable_organization_url_change' => _("Allow organizations to change their URL"),
'admin_must_approve_new_communities' => _("Admin must approve creation of communities"),
- 'enterprises_are_disabled_when_created' => __('Enterprises are disabled when created'),
- 'enterprises_are_validated_when_created' => __('Enterprises are validated when created'),
'show_balloon_with_profile_links_when_clicked' => _('Show a balloon with profile links when a profile image is clicked'),
'xmpp_chat' => _('XMPP/Jabber based chat'),
'show_zoom_button_on_article_images' => _('Show a zoom link on all article images'),
@@ -281,8 +282,9 @@ class Environment < ActiveRecord::Base
end
# Enables a feature identified by its name
- def enable(feature)
+ def enable(feature, must_save=true)
self.settings["#{feature}_enabled".to_sym] = true
+ self.save! if must_save
end
def enable_plugin(plugin)
@@ -292,8 +294,9 @@ class Environment < ActiveRecord::Base
end
# Disables a feature identified by its name
- def disable(feature)
+ def disable(feature, must_save=true)
self.settings["#{feature}_enabled".to_sym] = false
+ self.save! if must_save
end
def disable_plugin(plugin)
@@ -337,7 +340,7 @@ class Environment < ActiveRecord::Base
%w(
disable_asset_products
disable_gender_icon
- disable_products_for_enterprises
+ products_for_enterprises
disable_select_city_for_contact
enterprise_registration
media_panel
@@ -345,7 +348,7 @@ class Environment < ActiveRecord::Base
show_balloon_with_profile_links_when_clicked
use_portal_community
).each do |feature|
- enable(feature)
+ enable(feature, false)
end
end
diff --git a/app/models/price_detail.rb b/app/models/price_detail.rb
index f24fc58..958c1a5 100644
--- a/app/models/price_detail.rb
+++ b/app/models/price_detail.rb
@@ -8,7 +8,7 @@ class PriceDetail < ActiveRecord::Base
validates_uniqueness_of :production_cost_id, :scope => :product_id
def name
- production_cost.nil? ? _('other costs') : production_cost.name
+ production_cost.nil? ? _('Other costs') : production_cost.name
end
def price
diff --git a/app/views/blocks/profile_info.rhtml b/app/views/blocks/profile_info.rhtml
index 012ffc8..b60fb5e 100644
--- a/app/views/blocks/profile_info.rhtml
+++ b/app/views/blocks/profile_info.rhtml
@@ -17,7 +17,7 @@
- <%= link_to __('Homepage'), block.owner.url, :class => 'url' %>
- <%= link_to _('View profile'), block.owner.public_profile_url %>
- <% if block.owner.enterprise? && !block.owner.environment.enabled?('disable_products_for_enterprises') %>
+ <% if block.owner.enterprise? && block.owner.environment.enabled?('products_for_enterprises') %>
- <%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) %>
<% end %>
diff --git a/app/views/content_viewer/_enterprise_homepage.rhtml b/app/views/content_viewer/_enterprise_homepage.rhtml
index 154890e..7e4e6d2 100644
--- a/app/views/content_viewer/_enterprise_homepage.rhtml
+++ b/app/views/content_viewer/_enterprise_homepage.rhtml
@@ -1,3 +1,3 @@
<%= display_profile_info enterprise_homepage.profile %>
<%= enterprise_homepage.body %>
-<%= render :file => 'catalog/index' unless enterprise_homepage.profile.environment.enabled?('disable_products_for_enterprises') %>
+<%= render :file => 'catalog/index' if enterprise_homepage.profile.environment.enabled?('products_for_enterprises') %>
diff --git a/app/views/profile/_organization_profile.rhtml b/app/views/profile/_organization_profile.rhtml
index 1a9315b..04de939 100644
--- a/app/views/profile/_organization_profile.rhtml
+++ b/app/views/profile/_organization_profile.rhtml
@@ -19,7 +19,7 @@
<%= show_date(profile.created_at) %> |
- <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %>
+ <% if profile.kind_of?(Enterprise) && profile.environment.enabled?('products_for_enterprises') %>
|
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 4044a64..0fc6b89 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -45,7 +45,7 @@
<%= control_panel_button(_('Manage Members'), 'members', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %>
- <%= control_panel_button(_('Manage Products and Services'), 'products', :controller => 'manage_products') if profile.enterprise? && !environment.enabled?('disable_products_for_enterprises') %>
+ <%= control_panel_button(_('Manage Products and Services'), 'products', :controller => 'manage_products') if profile.enterprise? && environment.enabled?('products_for_enterprises') %>
<% if !environment.enabled?('disable_asset_enterprises') %>
<% if profile.is_validation_entity? %>
diff --git a/db/migrate/20130529155000_rename_environment_setting_disable_products.rb b/db/migrate/20130529155000_rename_environment_setting_disable_products.rb
new file mode 100644
index 0000000..db66e55
--- /dev/null
+++ b/db/migrate/20130529155000_rename_environment_setting_disable_products.rb
@@ -0,0 +1,21 @@
+class RenameEnvironmentSettingDisableProducts < ActiveRecord::Migration
+ def self.up
+ select_all("select id from environments").each do |environment|
+ env = Environment.find(environment['id'])
+ env.settings[:products_for_enterprises_enabled] =
+ !env.settings[:disable_products_for_enterprises_enabled]
+ env.settings.delete :disable_products_for_enterprises_enabled
+ env.save!
+ end
+ end
+
+ def self.down
+ select_all("select id from environments").each do |environment|
+ env = Environment.find(environment['id'])
+ env.settings[:disable_products_for_enterprises_enabled] =
+ !env.settings[:products_for_enterprises_enabled]
+ env.settings.delete :products_for_enterprises_enabled
+ env.save!
+ end
+ end
+end
diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb
index 6456410..770d669 100644
--- a/test/functional/catalog_controller_test.rb
+++ b/test/functional/catalog_controller_test.rb
@@ -10,6 +10,7 @@ class CatalogControllerTest < ActionController::TestCase
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+ Environment.default.enable('products_for_enterprises')
@enterprise = fast_create(Enterprise, :name => 'My enterprise', :identifier => 'testent')
@product_category = fast_create(ProductCategory)
end
@@ -52,7 +53,7 @@ class CatalogControllerTest < ActionController::TestCase
should 'not give access if environment do not let' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
+ env.disable('products_for_enterprises')
env.save!
ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id)
get :index, :profile => ent.identifier
diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb
index 1395e4d..b6f8893 100644
--- a/test/functional/manage_products_controller_test.rb
+++ b/test/functional/manage_products_controller_test.rb
@@ -13,6 +13,7 @@ class ManageProductsControllerTest < ActionController::TestCase
@enterprise = fast_create(Enterprise, :name => 'teste', :identifier => 'test_ent')
@user = create_user_with_permission('test_user', 'manage_products', @enterprise)
@environment = @enterprise.environment
+ @environment.enable('products_for_enterprises')
@product_category = fast_create(ProductCategory)
login_as :test_user
end
@@ -191,7 +192,7 @@ class ManageProductsControllerTest < ActionController::TestCase
should 'not let users in if environment do not let' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
+ env.disable('products_for_enterprises')
env.save!
@enterprise.environment = env
@enterprise.save!
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index c2ff186..5178911 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -9,7 +9,7 @@ class ProfileControllerTest < ActionController::TestCase
@controller = ProfileController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
-
+ Environment.default.enable('products_for_enterprises')
@profile = create_user('testuser').person
end
attr_reader :profile
@@ -263,8 +263,7 @@ class ProfileControllerTest < ActionController::TestCase
should 'not display "Products" link for enterprise if environment do not let' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
- env.save!
+ env.disable('products_for_enterprises')
ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false, :environment_id => env.id)
get :index, :profile => 'my-test-enterprise'
diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb
index b79ee94..f0104a5 100644
--- a/test/functional/profile_design_controller_test.rb
+++ b/test/functional/profile_design_controller_test.rb
@@ -395,7 +395,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
should 'not allow products block if environment do not let' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
+ env.disable('products_for_enterprises')
env.save!
ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent', :environment_id => env.id)
person = create_user_with_permission('test_user', 'edit_profile_design', ent)
@@ -530,6 +530,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
environment = mock
profile.stubs(:environment).returns(environment)
environment.stubs(:enabled?).returns(true)
+ environment.stubs(:enabled?).with('products_for_enterprises').returns(false)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
@@ -546,7 +547,7 @@ class ProfileDesignControllerTest < ActionController::TestCase
profile.stubs(:is_admin?).with(anything).returns(false)
environment = mock
profile.stubs(:environment).returns(environment)
- environment.stubs(:enabled?).returns(false)
+ environment.stubs(:enabled?).returns(true)
@controller.stubs(:profile).returns(profile)
@controller.stubs(:user).returns(profile)
Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([])
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 3dac0d3..1bd38dc 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -559,7 +559,7 @@ class ProfileEditorControllerTest < ActionController::TestCase
should 'not list the manage products button if the environment disabled it' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
+ env.disable('products_for_enterprises')
env.save!
ent = fast_create(Enterprise)
diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb
index fd8694d..5fe8666 100644
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -5,6 +5,7 @@ class EnterpriseTest < ActiveSupport::TestCase
def setup
super
+ Environment.default.enable('products_for_enterprises')
@product_category = fast_create(ProductCategory, :name => 'Products')
end
@@ -80,9 +81,9 @@ class EnterpriseTest < ActiveSupport::TestCase
should 'create default set of blocks' do
e = Enterprise.create(:name => 'my new community', :identifier => 'mynewcommunity')
- assert !e.boxes[0].blocks.empty?, 'person must have blocks in area 1'
- assert !e.boxes[1].blocks.empty?, 'person must have blocks in area 2'
- assert !e.boxes[2].blocks.empty?, 'person must have blocks in area 3'
+ assert !e.boxes[0].blocks.empty?, 'enterprise must have blocks in area 1'
+ assert !e.boxes[1].blocks.empty?, 'enterprise must have blocks in area 2'
+ assert !e.boxes[2].blocks.empty?, 'enterprise must have blocks in area 3'
end
should 'allow to add new members if has no members' do
@@ -242,8 +243,7 @@ class EnterpriseTest < ActiveSupport::TestCase
should 'not create a products block for enterprise if environment do not let' do
env = Environment.default
- env.enable('disable_products_for_enterprises')
- env.save!
+ env.disable('products_for_enterprises')
ent = fast_create(Enterprise, :name => 'test ent', :identifier => 'test_ent')
assert_not_includes ent.blocks.map(&:class), ProductsBlock
end
--
libgit2 0.21.2 |