From 09061ef2216d98908f340dd18af1a9d2382a9f9c Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 18 Aug 2008 19:31:29 +0000 Subject: [PATCH] ActionItem630: environment can disable products --- app/controllers/my_profile/manage_products_controller.rb | 10 ++++++++++ app/controllers/my_profile/profile_design_controller.rb | 4 ++-- app/controllers/public/catalog_controller.rb | 6 +++--- app/models/enterprise.rb | 8 ++++++-- app/models/environment.rb | 1 + app/views/blocks/profile_info.rhtml | 2 +- app/views/profile/index.rhtml | 2 +- app/views/profile_editor/index.rhtml | 2 +- lib/unifreire_terminology.rb | 32 ++++++++++++++++++++++++++++++++ test/functional/catalog_controller_test.rb | 10 ++++++++++ test/functional/manage_products_controller_test.rb | 11 +++++++++++ test/functional/profile_controller_test.rb | 11 +++++++++++ test/functional/profile_design_controller_test.rb | 15 ++++++++++++++- test/functional/profile_editor_controller_test.rb | 14 ++++++++++++++ test/unit/enterprise_test.rb | 8 ++++++++ 15 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 lib/unifreire_terminology.rb diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 2b0646a..f462c0b 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -2,7 +2,17 @@ class ManageProductsController < ApplicationController needs_profile protect 'manage_products', :profile + before_filter :check_environment_feature + protected + def check_environment_feature + if profile.environment.enabled?('disable_products_for_enterprises') + render_not_found + return + end + end + + public def index @products = @profile.products @consumptions = @profile.consumptions diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 4a2e314..6101709 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -19,8 +19,8 @@ class ProfileDesignController < BoxOrganizerController blocks << MyNetworkBlock end - # blocks exclusive for enterprises - if profile.enterprise? + # product block exclusive for enterprises in environments that permits it + if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises') blocks << ProductsBlock end diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb index 8cdb825..09ec6f7 100644 --- a/app/controllers/public/catalog_controller.rb +++ b/app/controllers/public/catalog_controller.rb @@ -1,6 +1,6 @@ class CatalogController < ApplicationController needs_profile - before_filter :check_enterprise + before_filter :check_enterprise_and_environment def index @products = @profile.products @@ -11,8 +11,8 @@ class CatalogController < ApplicationController end protected - def check_enterprise - unless @profile.kind_of? Enterprise + def check_enterprise_and_environment + unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_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 1e71b7d..877a5f2 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -59,11 +59,15 @@ class Enterprise < Organization def default_set_of_blocks - [ + blocks = [ [MainBlock], [ProfileInfoBlock, MembersBlock], - [ProductsBlock, RecentDocumentsBlock] + [RecentDocumentsBlock] ] + if !environment.enabled?('disable_products_for_enterprises') + blocks[2].unshift ProductsBlock + end + blocks end protected diff --git a/app/models/environment.rb b/app/models/environment.rb index 327ed9c..43d5a37 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -28,6 +28,7 @@ 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'), } end diff --git a/app/views/blocks/profile_info.rhtml b/app/views/blocks/profile_info.rhtml index 639dc84..a01d537 100644 --- a/app/views/blocks/profile_info.rhtml +++ b/app/views/blocks/profile_info.rhtml @@ -19,7 +19,7 @@
  • <%= _('Since %{year}/%{month}') % { :year => block.owner.created_at.year, :month => block.owner.created_at.month } %>
  • <%= link_to __('Homepage'), block.owner.url, :class => 'url' %>
  • <%= link_to _('View profile'), block.owner.public_profile_url %>
  • -
  • <%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? %>
  • +
  • <%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? && !block.owner.environment.enabled?('disable_products_for_enterprises') %>
  • <% if !user.nil? and user.has_permission?('edit_profile', profile) %>
  • <%= link_to _('Control panel'), :controller => 'profile_editor' %>
  • <% end %> diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml index f926eca..83501d6 100644 --- a/app/views/profile/index.rhtml +++ b/app/views/profile/index.rhtml @@ -25,7 +25,7 @@ <% if profile.kind_of? Organization %>
  • <%= link_to _('Members'), :action => 'members' %>
  • <% end %> - <% if profile.kind_of? Enterprise %> + <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %>
  • <%= link_to _('Products/Services'), :controller => 'catalog', :action => 'index' %>
  • <% end %> diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index 6882efa..898bb1e 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -28,7 +28,7 @@ <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %> - <%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %> + <%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? && !environment.enabled?('disable_products_for_enterprises') %> <%= file_manager_button(__('Enterprise Validation'), 'icons-app/validation.png', :controller => 'enterprise_validation') if profile.is_validation_entity? %> diff --git a/lib/unifreire_terminology.rb b/lib/unifreire_terminology.rb new file mode 100644 index 0000000..3ce4b6f --- /dev/null +++ b/lib/unifreire_terminology.rb @@ -0,0 +1,32 @@ +require 'noosfero/terminology' + +class UnifreireTerminology < Noosfero::Terminology::Custom + include GetText + + def initialize + # NOTE: the hash values must be marked for translation!! + super({ + 'Enterprises' => N_('Institutions'), + 'The enterprises where this user works.' => N_('The institution where this user belongs.'), + 'A block that displays your enterprises' => N_('A block that displays your institutions.'), + 'All enterprises' => N_('All institutions'), + 'Disable search for enterprises' => N_('Disable search for institutions'), + 'One enterprise' => N_('One institution'), + '%{num} enterprises' => N_('%{num} institutions'), + 'Favorite Enterprises' => N_('Favorite Institutions'), + 'This user\'s favorite enterprises.' => N_('This user\'s favorite institutions'), + 'A block that displays your favorite enterprises' => N_('A block that displays your favorite institutions'), + 'All favorite enterprises' => N_('All favorite institutions'), + 'A search for enterprises by products selled and local' => N_('A search for institutions by products selled and local'), + 'Edit message for disabled enterprises' => N_('Edit message for disabled institutions'), + 'Add favorite enterprise' => N_('Add favorite institution'), + 'Validation info is the information the enterprises will see about how your organization processes the enterprises validations it receives: validation methodology, restrictions to the types of enterprises the organization validates etc.' => N_('Validation info is the information the institutions will see about how your organization processes the institutions validations it receives: validation methodology, restrictions to the types of institutions the organization validates etc.'), + 'Here are all %s\'s enterprises.' => N_('Here are all %s\'s institutions.'), + 'Here are all %s\'s favorite enterprises.' => N_('Here are all %s\'s favorite institutions.'), + 'Favorite Enterprises' => N_('Favorite Institutions'), + 'Enterprises in "%s"' => N_('Institutions in "%s"'), + 'Register a new Enterprise' => N_('Register a new Institution'), + }) + end + +end diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index 2f9d596..648aeb7 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -65,4 +65,14 @@ class CatalogControllerTest < Test::Unit::TestCase end + should 'not give access if environment do not let' do + env = Environment.default + env.enable('disable_products_for_enterprises') + env.save! + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :environment => env) + get :index, :profile => ent.identifier + + assert_redirected_to :controller => 'profile', :action => 'index', :profile => ent.identifier + end + end diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 563fcd2..0dbbe59 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -253,5 +253,16 @@ class ManageProductsControllerTest < Test::Unit::TestCase get :edit_consumption, :profile => @enterprise.identifier, :id => product assert_no_tag :tag => 'select', :attributes => { :name => 'consumption[product_category_id]' } end + + should 'not let users in if environment do not let' do + env = Environment.default + env.enable('disable_products_for_enterprises') + env.save! + @enterprise.environment = env + @enterprise.save! + get :index, :profile => @enterprise.identifier + + assert_template 'not_found.rhtml' + end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 6dff00f..25da40c 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -233,6 +233,17 @@ class ProfileControllerTest < Test::Unit::TestCase get :index, :profile => 'my-test-enterprise' assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ end + + should 'not display "Products" link for enterprise if environment do not let' do + env = Environment.default + env.enable('disable_products_for_enterprises') + env.save! + ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false, :environment => env) + + get :index, :profile => 'my-test-enterprise' + assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/ + end + should 'not display "Products" link for people' do get :index, :profile => 'ze' diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 1f1d4cb..0ea9823 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -240,6 +240,19 @@ class ProfileDesignControllerTest < Test::Unit::TestCase get :index, :profile => 'designtestuser' assert_tag :tag => 'a', :content => 'Back to control panel' end - + + should 'not allow products block if environment do not let' do + env = Environment.default + env.enable('disable_products_for_enterprises') + env.save! + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :environment => env) + person = create_user_with_permission('test_user', 'edit_profile_design', ent) + login_as(person.user.login) + + get :add_block, :profile => 'test_ent' + + assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'} + end + end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index b17bdcb..f57b38c 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -448,4 +448,18 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/profile_editor/header_footer' } end + should 'not list the manage products button if the environment disabled it' do + env = Environment.default + env.enable('disable_products_for_enterprises') + env.save! + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :environment => env) + + u = create_user_with_permission('test_user', 'edit_profile', ent) + login_as('test_user') + + get :index, :profile => 'test_ent' + + assert_no_tag :tag => 'span', :content => 'Manage Products and Services' + end + end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index aca0e5d..df5ac1b 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -197,4 +197,12 @@ class EnterpriseTest < Test::Unit::TestCase assert_kind_of EnterpriseHomepage, enterprise.home_page end + 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! + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + assert_not_includes ent.blocks.map(&:class), ProductsBlock + end + end -- libgit2 0.21.2