Commit 09061ef2216d98908f340dd18af1a9d2382a9f9c

Authored by MoisesMachado
1 parent e215fbd0

ActionItem630: environment can disable products

  The environment admin can now disable management of products for its
enterprises. It disables together button of control panel, link of
profile info block, link of profile page, access to manage products
controller and catalog controller. Also do not let enterprises create
products blocks and change the initial blocks for an enterprise to not
contain a products block.

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2402 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/manage_products_controller.rb
... ... @@ -2,7 +2,17 @@ class ManageProductsController < ApplicationController
2 2 needs_profile
3 3  
4 4 protect 'manage_products', :profile
  5 + before_filter :check_environment_feature
5 6  
  7 + protected
  8 + def check_environment_feature
  9 + if profile.environment.enabled?('disable_products_for_enterprises')
  10 + render_not_found
  11 + return
  12 + end
  13 + end
  14 +
  15 + public
6 16 def index
7 17 @products = @profile.products
8 18 @consumptions = @profile.consumptions
... ...
app/controllers/my_profile/profile_design_controller.rb
... ... @@ -19,8 +19,8 @@ class ProfileDesignController < BoxOrganizerController
19 19 blocks << MyNetworkBlock
20 20 end
21 21  
22   - # blocks exclusive for enterprises
23   - if profile.enterprise?
  22 + # product block exclusive for enterprises in environments that permits it
  23 + if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises')
24 24 blocks << ProductsBlock
25 25 end
26 26  
... ...
app/controllers/public/catalog_controller.rb
1 1 class CatalogController < ApplicationController
2 2 needs_profile
3   - before_filter :check_enterprise
  3 + before_filter :check_enterprise_and_environment
4 4  
5 5 def index
6 6 @products = @profile.products
... ... @@ -11,8 +11,8 @@ class CatalogController &lt; ApplicationController
11 11 end
12 12  
13 13 protected
14   - def check_enterprise
15   - unless @profile.kind_of? Enterprise
  14 + def check_enterprise_and_environment
  15 + unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_products_for_enterprises')
16 16 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
17 17 end
18 18 end
... ...
app/models/enterprise.rb
... ... @@ -59,11 +59,15 @@ class Enterprise &lt; Organization
59 59  
60 60  
61 61 def default_set_of_blocks
62   - [
  62 + blocks = [
63 63 [MainBlock],
64 64 [ProfileInfoBlock, MembersBlock],
65   - [ProductsBlock, RecentDocumentsBlock]
  65 + [RecentDocumentsBlock]
66 66 ]
  67 + if !environment.enabled?('disable_products_for_enterprises')
  68 + blocks[2].unshift ProductsBlock
  69 + end
  70 + blocks
67 71 end
68 72  
69 73 protected
... ...
app/models/environment.rb
... ... @@ -28,6 +28,7 @@ class Environment &lt; ActiveRecord::Base
28 28 'disable_asset_communities' => __('Disable search for communities'),
29 29 'disable_asset_products' => _('Disable search for products'),
30 30 'disable_asset_events' => _('Disable search for events'),
  31 + 'disable_products_for_enterprises' => _('Disable products for enterprises'),
31 32 }
32 33 end
33 34  
... ...
app/views/blocks/profile_info.rhtml
... ... @@ -19,7 +19,7 @@
19 19 <li><%= _('Since %{year}/%{month}') % { :year => block.owner.created_at.year, :month => block.owner.created_at.month } %></li>
20 20 <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li>
21 21 <li><%= link_to _('View profile'), block.owner.public_profile_url %></li>
22   - <li><%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? %></li>
  22 + <li><%= link_to(_('Products/Services'), :controller => 'catalog', :profile => block.owner.identifier) if block.owner.enterprise? && !block.owner.environment.enabled?('disable_products_for_enterprises') %></li>
23 23 <% if !user.nil? and user.has_permission?('edit_profile', profile) %>
24 24 <li><%= link_to _('Control panel'), :controller => 'profile_editor' %></li>
25 25 <% end %>
... ...
app/views/profile/index.rhtml
... ... @@ -25,7 +25,7 @@
25 25 <% if profile.kind_of? Organization %>
26 26 <li><%= link_to _('Members'), :action => 'members' %></li>
27 27 <% end %>
28   - <% if profile.kind_of? Enterprise %>
  28 + <% if profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises') %>
29 29 <li><%= link_to _('Products/Services'), :controller => 'catalog', :action => 'index' %></li>
30 30 <% end %>
31 31  
... ...
app/views/profile_editor/index.rhtml
... ... @@ -28,7 +28,7 @@
28 28  
29 29 <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') if profile.organization? && user.has_permission?(:manage_memberships, profile) %>
30 30  
31   - <%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %>
  31 + <%= file_manager_button(_('Manage Products and Services'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? && !environment.enabled?('disable_products_for_enterprises') %>
32 32  
33 33 <%= file_manager_button(__('Enterprise Validation'), 'icons-app/validation.png', :controller => 'enterprise_validation') if profile.is_validation_entity? %>
34 34  
... ...
lib/unifreire_terminology.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require 'noosfero/terminology'
  2 +
  3 +class UnifreireTerminology < Noosfero::Terminology::Custom
  4 + include GetText
  5 +
  6 + def initialize
  7 + # NOTE: the hash values must be marked for translation!!
  8 + super({
  9 + 'Enterprises' => N_('Institutions'),
  10 + 'The enterprises where this user works.' => N_('The institution where this user belongs.'),
  11 + 'A block that displays your enterprises' => N_('A block that displays your institutions.'),
  12 + 'All enterprises' => N_('All institutions'),
  13 + 'Disable search for enterprises' => N_('Disable search for institutions'),
  14 + 'One enterprise' => N_('One institution'),
  15 + '%{num} enterprises' => N_('%{num} institutions'),
  16 + 'Favorite Enterprises' => N_('Favorite Institutions'),
  17 + 'This user\'s favorite enterprises.' => N_('This user\'s favorite institutions'),
  18 + 'A block that displays your favorite enterprises' => N_('A block that displays your favorite institutions'),
  19 + 'All favorite enterprises' => N_('All favorite institutions'),
  20 + 'A search for enterprises by products selled and local' => N_('A search for institutions by products selled and local'),
  21 + 'Edit message for disabled enterprises' => N_('Edit message for disabled institutions'),
  22 + 'Add favorite enterprise' => N_('Add favorite institution'),
  23 + '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.'),
  24 + 'Here are all <b>%s</b>\'s enterprises.' => N_('Here are all <b>%s</b>\'s institutions.'),
  25 + 'Here are all <b>%s</b>\'s favorite enterprises.' => N_('Here are all <b>%s</b>\'s favorite institutions.'),
  26 + 'Favorite Enterprises' => N_('Favorite Institutions'),
  27 + 'Enterprises in "%s"' => N_('Institutions in "%s"'),
  28 + 'Register a new Enterprise' => N_('Register a new Institution'),
  29 + })
  30 + end
  31 +
  32 +end
... ...
test/functional/catalog_controller_test.rb
... ... @@ -65,4 +65,14 @@ class CatalogControllerTest &lt; Test::Unit::TestCase
65 65  
66 66 end
67 67  
  68 + should 'not give access if environment do not let' do
  69 + env = Environment.default
  70 + env.enable('disable_products_for_enterprises')
  71 + env.save!
  72 + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :environment => env)
  73 + get :index, :profile => ent.identifier
  74 +
  75 + assert_redirected_to :controller => 'profile', :action => 'index', :profile => ent.identifier
  76 + end
  77 +
68 78 end
... ...
test/functional/manage_products_controller_test.rb
... ... @@ -253,5 +253,16 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
253 253 get :edit_consumption, :profile => @enterprise.identifier, :id => product
254 254 assert_no_tag :tag => 'select', :attributes => { :name => 'consumption[product_category_id]' }
255 255 end
  256 +
  257 + should 'not let users in if environment do not let' do
  258 + env = Environment.default
  259 + env.enable('disable_products_for_enterprises')
  260 + env.save!
  261 + @enterprise.environment = env
  262 + @enterprise.save!
  263 + get :index, :profile => @enterprise.identifier
  264 +
  265 + assert_template 'not_found.rhtml'
  266 + end
256 267  
257 268 end
... ...
test/functional/profile_controller_test.rb
... ... @@ -233,6 +233,17 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
233 233 get :index, :profile => 'my-test-enterprise'
234 234 assert_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
235 235 end
  236 +
  237 + should 'not display "Products" link for enterprise if environment do not let' do
  238 + env = Environment.default
  239 + env.enable('disable_products_for_enterprises')
  240 + env.save!
  241 + ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false, :environment => env)
  242 +
  243 + get :index, :profile => 'my-test-enterprise'
  244 + assert_no_tag :tag => 'a', :attributes => { :href => '/catalog/my-test-enterprise'}, :content => /Products\/Services/
  245 + end
  246 +
236 247  
237 248 should 'not display "Products" link for people' do
238 249 get :index, :profile => 'ze'
... ...
test/functional/profile_design_controller_test.rb
... ... @@ -240,6 +240,19 @@ class ProfileDesignControllerTest &lt; Test::Unit::TestCase
240 240 get :index, :profile => 'designtestuser'
241 241 assert_tag :tag => 'a', :content => 'Back to control panel'
242 242 end
243   -
  243 +
  244 + should 'not allow products block if environment do not let' do
  245 + env = Environment.default
  246 + env.enable('disable_products_for_enterprises')
  247 + env.save!
  248 + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :environment => env)
  249 + person = create_user_with_permission('test_user', 'edit_profile_design', ent)
  250 + login_as(person.user.login)
  251 +
  252 + get :add_block, :profile => 'test_ent'
  253 +
  254 + assert_no_tag :tag => 'input', :attributes => {:type => 'radio', :value => 'ProductsBlock'}
  255 + end
  256 +
244 257 end
245 258  
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -448,4 +448,18 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
448 448 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/profile_editor/header_footer' }
449 449 end
450 450  
  451 + should 'not list the manage products button if the environment disabled it' do
  452 + env = Environment.default
  453 + env.enable('disable_products_for_enterprises')
  454 + env.save!
  455 + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :environment => env)
  456 +
  457 + u = create_user_with_permission('test_user', 'edit_profile', ent)
  458 + login_as('test_user')
  459 +
  460 + get :index, :profile => 'test_ent'
  461 +
  462 + assert_no_tag :tag => 'span', :content => 'Manage Products and Services'
  463 + end
  464 +
451 465 end
... ...
test/unit/enterprise_test.rb
... ... @@ -197,4 +197,12 @@ class EnterpriseTest &lt; Test::Unit::TestCase
197 197 assert_kind_of EnterpriseHomepage, enterprise.home_page
198 198 end
199 199  
  200 + should 'not create a products block for enterprise if environment do not let' do
  201 + env = Environment.default
  202 + env.enable('disable_products_for_enterprises')
  203 + env.save!
  204 + ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent')
  205 + assert_not_includes ent.blocks.map(&:class), ProductsBlock
  206 + end
  207 +
200 208 end
... ...