Commit bf6b600731222473cd2013b8ec3735ee3dbc5ebb
1 parent
86f4b04a
Exists in
master
and in
23 other branches
ActionItem502: making it possible to hide stuff from the assets menu
and from the search. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2290 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
70 additions
and
14 deletions
Show diff stats
app/controllers/public/search_controller.rb
| @@ -13,7 +13,7 @@ class SearchController < ApplicationController | @@ -13,7 +13,7 @@ class SearchController < ApplicationController | ||
| 13 | protected | 13 | protected |
| 14 | 14 | ||
| 15 | def load_search_assets | 15 | def load_search_assets |
| 16 | - @search_in = SEARCH_IN | 16 | + @search_in = where_to_search |
| 17 | @searching = {} | 17 | @searching = {} |
| 18 | @search_in.each do |key, name| | 18 | @search_in.each do |key, name| |
| 19 | @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s) | 19 | @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s) |
| @@ -36,7 +36,7 @@ class SearchController < ApplicationController | @@ -36,7 +36,7 @@ class SearchController < ApplicationController | ||
| 36 | 36 | ||
| 37 | def check_valid_assets | 37 | def check_valid_assets |
| 38 | @asset = params[:asset].to_sym | 38 | @asset = params[:asset].to_sym |
| 39 | - if !SEARCH_IN.map(&:first).include?(@asset) | 39 | + if !where_to_search.map(&:first).include?(@asset) |
| 40 | render :text => 'go away', :status => 403 | 40 | render :text => 'go away', :status => 403 |
| 41 | return | 41 | return |
| 42 | end | 42 | end |
| @@ -129,14 +129,16 @@ class SearchController < ApplicationController | @@ -129,14 +129,16 @@ class SearchController < ApplicationController | ||
| 129 | 129 | ||
| 130 | ###################################################### | 130 | ###################################################### |
| 131 | 131 | ||
| 132 | - SEARCH_IN = [ | ||
| 133 | - [ :articles, N_('Articles') ], | ||
| 134 | - [ :enterprises, N_('Enterprises') ], | ||
| 135 | - [ :people, N_('People') ], | ||
| 136 | - [ :communities, N_('Communities') ], | ||
| 137 | - [ :products, N_('Products') ], | ||
| 138 | - [ :events, N_('Events') ] | ||
| 139 | - ] | 132 | + def where_to_search |
| 133 | + [ | ||
| 134 | + [ :articles, N_('Articles') ], | ||
| 135 | + [ :enterprises, N_('Enterprises') ], | ||
| 136 | + [ :people, N_('People') ], | ||
| 137 | + [ :communities, N_('Communities') ], | ||
| 138 | + [ :products, N_('Products') ], | ||
| 139 | + [ :events, N_('Events') ] | ||
| 140 | + ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } | ||
| 141 | + end | ||
| 140 | 142 | ||
| 141 | def cities | 143 | def cities |
| 142 | @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]]) | 144 | @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]]) |
| @@ -163,7 +165,7 @@ class SearchController < ApplicationController | @@ -163,7 +165,7 @@ class SearchController < ApplicationController | ||
| 163 | @order = [] | 165 | @order = [] |
| 164 | @names = {} | 166 | @names = {} |
| 165 | 167 | ||
| 166 | - SEARCH_IN.select { |key,description| @searching[key] }.each do |key, description| | 168 | + where_to_search.select { |key,description| @searching[key] }.each do |key, description| |
| 167 | @order << key | 169 | @order << key |
| 168 | @results[key] = @finder.find(key, @filtered_query, calculate_find_options(key, limit, params[:page], @product_category, @region, params[:radius], params[:year], params[:month])) | 170 | @results[key] = @finder.find(key, @filtered_query, calculate_find_options(key, limit, params[:page], @product_category, @region, params[:radius], params[:year], params[:month])) |
| 169 | @names[key] = gettext(description) | 171 | @names[key] = gettext(description) |
app/helpers/assets_helper.rb
| @@ -11,7 +11,9 @@ module AssetsHelper | @@ -11,7 +11,9 @@ module AssetsHelper | ||
| 11 | [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], | 11 | [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], |
| 12 | [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], | 12 | [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], |
| 13 | 13 | ||
| 14 | - ].map do |target,css_class,name| | 14 | + ].select do |target, css_class, name| |
| 15 | + !environment.enabled?('disable_asset_' + target[:asset]) | ||
| 16 | + end.map do |target,css_class,name| | ||
| 15 | content_tag('li', | 17 | content_tag('li', |
| 16 | link_to( | 18 | link_to( |
| 17 | content_tag('span', '', :class => css_class) + | 19 | content_tag('span', '', :class => css_class) + |
app/models/environment.rb
| @@ -22,8 +22,12 @@ class Environment < ActiveRecord::Base | @@ -22,8 +22,12 @@ class Environment < ActiveRecord::Base | ||
| 22 | # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. | 22 | # hash, with pairs in the form <tt>'feature_name' => 'Feature name'</tt>. |
| 23 | def self.available_features | 23 | def self.available_features |
| 24 | { | 24 | { |
| 25 | - 'some_feature' => _('Some feature'), | ||
| 26 | - 'other_feature' => _('Other feature'), | 25 | + 'disable_asset_articles' => _('Disable search for articles '), |
| 26 | + 'disable_asset_enterprises' => _('Disable search for enterprises'), | ||
| 27 | + 'disable_asset_people' => _('Disable search for people'), | ||
| 28 | + 'disable_asset_communities' => _('Disable search for communities'), | ||
| 29 | + 'disable_asset_products' => _('Disable search for products'), | ||
| 30 | + 'disable_asset_events' => _('Disable search for events'), | ||
| 27 | } | 31 | } |
| 28 | end | 32 | end |
| 29 | 33 |
test/functional/search_controller_test.rb
| @@ -899,6 +899,20 @@ class SearchControllerTest < Test::Unit::TestCase | @@ -899,6 +899,20 @@ class SearchControllerTest < Test::Unit::TestCase | ||
| 899 | assert_includes assigns(:results)[:articles], art | 899 | assert_includes assigns(:results)[:articles], art |
| 900 | end | 900 | end |
| 901 | 901 | ||
| 902 | + should 'know about disabled assets' do | ||
| 903 | + env = mock | ||
| 904 | + %w[ articles enterprises people communities events].each do |item| | ||
| 905 | + env.expects(:enabled?).with('disable_asset_' + item).returns(false).at_least_once | ||
| 906 | + end | ||
| 907 | + env.expects(:enabled?).with('disable_asset_products').returns(true).at_least_once | ||
| 908 | + @controller.stubs(:environment).returns(env) | ||
| 909 | + | ||
| 910 | + %w[ articles enterprises people communities events].each do |item| | ||
| 911 | + assert_includes @controller.where_to_search.map(&:first), item.to_sym | ||
| 912 | + end | ||
| 913 | + assert_not_includes @controller.where_to_search.map(&:first), :products | ||
| 914 | + end | ||
| 915 | + | ||
| 902 | ################################################################## | 916 | ################################################################## |
| 903 | ################################################################## | 917 | ################################################################## |
| 904 | 918 |
test/unit/assets_helper_test.rb
| @@ -5,6 +5,9 @@ class AssetsHelperTest < Test::Unit::TestCase | @@ -5,6 +5,9 @@ class AssetsHelperTest < Test::Unit::TestCase | ||
| 5 | include AssetsHelper | 5 | include AssetsHelper |
| 6 | 6 | ||
| 7 | should 'generate link to assets' do | 7 | should 'generate link to assets' do |
| 8 | + env = mock; env.stubs(:enabled?).with(anything).returns(false) | ||
| 9 | + stubs(:environment).returns(env) | ||
| 10 | + | ||
| 8 | %w[ articles | 11 | %w[ articles |
| 9 | people | 12 | people |
| 10 | products | 13 | products |
| @@ -21,6 +24,9 @@ class AssetsHelperTest < Test::Unit::TestCase | @@ -21,6 +24,9 @@ class AssetsHelperTest < Test::Unit::TestCase | ||
| 21 | end | 24 | end |
| 22 | 25 | ||
| 23 | should 'generate link to assets with current category' do | 26 | should 'generate link to assets with current category' do |
| 27 | + env = mock; env.stubs(:enabled?).with(anything).returns(false) | ||
| 28 | + stubs(:environment).returns(env) | ||
| 29 | + | ||
| 24 | %w[ articles | 30 | %w[ articles |
| 25 | people | 31 | people |
| 26 | products | 32 | products |
| @@ -38,4 +44,32 @@ class AssetsHelperTest < Test::Unit::TestCase | @@ -38,4 +44,32 @@ class AssetsHelperTest < Test::Unit::TestCase | ||
| 38 | generate_assets_menu | 44 | generate_assets_menu |
| 39 | end | 45 | end |
| 40 | 46 | ||
| 47 | + should 'generate link only to non-disabled assets' do | ||
| 48 | + env = mock | ||
| 49 | + env.expects(:enabled?).with('disable_asset_articles').returns(false) | ||
| 50 | + env.expects(:enabled?).with('disable_asset_enterprises').returns(true) | ||
| 51 | + env.expects(:enabled?).with('disable_asset_people').returns(false) | ||
| 52 | + env.expects(:enabled?).with('disable_asset_communities').returns(false) | ||
| 53 | + env.expects(:enabled?).with('disable_asset_products').returns(true) | ||
| 54 | + env.expects(:enabled?).with('disable_asset_events').returns(false) | ||
| 55 | + stubs(:environment).returns(env) | ||
| 56 | + | ||
| 57 | + %w[ articles | ||
| 58 | + people | ||
| 59 | + communities | ||
| 60 | + events | ||
| 61 | + ].each do |asset| | ||
| 62 | + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => asset, :category_path => [ 'my-category' ]}) | ||
| 63 | + end | ||
| 64 | + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => 'products', :category_path => [ 'my-category' ]}).never | ||
| 65 | + expects(:link_to).with(anything, { :controller => 'search', :action => 'assets', :asset => 'enterprises', :category_path => [ 'my-category' ]}).never | ||
| 66 | + | ||
| 67 | + stubs(:_).returns('') | ||
| 68 | + stubs(:content_tag).returns('') | ||
| 69 | + @category = mock | ||
| 70 | + @category.expects(:explode_path).returns(['my-category']).at_least_once | ||
| 71 | + | ||
| 72 | + generate_assets_menu | ||
| 73 | + end | ||
| 74 | + | ||
| 41 | end | 75 | end |