Commit cb53ae55c8a50cc8e415dc7c8e00d7ebfd09efeb
Exists in
stable
Merge branch 'master' into stable
Showing
8 changed files
with
67 additions
and
14 deletions
Show diff stats
lib/categories_software_block.rb
@@ -16,10 +16,15 @@ class CategoriesSoftwareBlock < Block | @@ -16,10 +16,15 @@ class CategoriesSoftwareBlock < Block | ||
16 | def content(args={}) | 16 | def content(args={}) |
17 | block = self | 17 | block = self |
18 | s = show_name | 18 | s = show_name |
19 | + | ||
20 | + software_category = Category.find_by_name("Software") | ||
21 | + categories = [] | ||
22 | + categories = software_category.children.sort if software_category | ||
23 | + | ||
19 | lambda do |object| | 24 | lambda do |object| |
20 | render( | 25 | render( |
21 | :file => 'blocks/categories_software', | 26 | :file => 'blocks/categories_software', |
22 | - :locals => { :block => block, :show_name => s } | 27 | + :locals => { :block => block, :show_name => s, :categories => categories } |
23 | ) | 28 | ) |
24 | end | 29 | end |
25 | end | 30 | end |
lib/ext/search_controller.rb
@@ -61,6 +61,7 @@ class SearchController | @@ -61,6 +61,7 @@ class SearchController | ||
61 | 61 | ||
62 | def get_filtered_software_list | 62 | def get_filtered_software_list |
63 | params[:query] ||= "" | 63 | params[:query] ||= "" |
64 | + visible_communities = visible_profiles(Community) | ||
64 | 65 | ||
65 | filtered_software_list = SoftwareInfo.search_by_query(params[:query]) | 66 | filtered_software_list = SoftwareInfo.search_by_query(params[:query]) |
66 | 67 | ||
@@ -70,6 +71,7 @@ class SearchController | @@ -70,6 +71,7 @@ class SearchController | ||
70 | @public_software_selected = false | 71 | @public_software_selected = false |
71 | end | 72 | end |
72 | 73 | ||
74 | + filtered_software_list.select!{ |software| visible_communities.include?(software.community) } | ||
73 | category_ids = get_filter_category_ids | 75 | category_ids = get_filter_category_ids |
74 | 76 | ||
75 | unless category_ids.empty? | 77 | unless category_ids.empty? |
lib/software_info.rb
@@ -13,15 +13,15 @@ class SoftwareInfo < ActiveRecord::Base | @@ -13,15 +13,15 @@ class SoftwareInfo < ActiveRecord::Base | ||
13 | DatabaseDescription | 13 | DatabaseDescription |
14 | ] | 14 | ] |
15 | 15 | ||
16 | - scope :search_by_query, lambda {|query = ""| | 16 | + scope :search_by_query, lambda { |query = ""| |
17 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') | 17 | filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') |
18 | search_fields = SoftwareInfo.pg_search_plugin_fields | 18 | search_fields = SoftwareInfo.pg_search_plugin_fields |
19 | 19 | ||
20 | if query.empty? | 20 | if query.empty? |
21 | - SoftwareInfo.all | 21 | + SoftwareInfo.joins(:community).where("profiles.visible = ?", true) |
22 | else | 22 | else |
23 | searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) | 23 | searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) |
24 | - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')") | 24 | + includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ?", true) |
25 | end | 25 | end |
26 | } | 26 | } |
27 | 27 |
lib/tasks/create_categories.rake
@@ -6,8 +6,12 @@ namespace :software do | @@ -6,8 +6,12 @@ namespace :software do | ||
6 | print 'Creating categories: ' | 6 | print 'Creating categories: ' |
7 | software = Category.create(:name => _("Software"), :environment => env) | 7 | software = Category.create(:name => _("Software"), :environment => env) |
8 | Category::SOFTWARE_CATEGORIES.each do |category_name| | 8 | Category::SOFTWARE_CATEGORIES.each do |category_name| |
9 | - print '.' | ||
10 | - Category.create(:name => category_name, :environment => env, :parent => software) | 9 | + unless Category.find_by_name(category_name) |
10 | + print '.' | ||
11 | + Category.create(:name => category_name, :environment => env, :parent => software) | ||
12 | + else | ||
13 | + print 'F' | ||
14 | + end | ||
11 | end | 15 | end |
12 | puts '' | 16 | puts '' |
13 | end | 17 | end |
test/functional/search_controller_test.rb
@@ -214,6 +214,48 @@ class SearchControllerTest < ActionController::TestCase | @@ -214,6 +214,48 @@ class SearchControllerTest < ActionController::TestCase | ||
214 | assert_not_includes assigns(:searches)[:software_infos][:results], software_one.community | 214 | assert_not_includes assigns(:searches)[:software_infos][:results], software_one.community |
215 | end | 215 | end |
216 | 216 | ||
217 | + should "software_infos search return only enabled softwares" do | ||
218 | + s1 = SoftwareInfo.first | ||
219 | + s2 = SoftwareInfo.last | ||
220 | + | ||
221 | + # First get them all normally | ||
222 | + get( | ||
223 | + :software_infos, | ||
224 | + :query => "software" | ||
225 | + ) | ||
226 | + | ||
227 | + assert_includes assigns(:searches)[:software_infos][:results], s1.community | ||
228 | + assert_includes assigns(:searches)[:software_infos][:results], s2.community | ||
229 | + | ||
230 | + s2.community.disable | ||
231 | + | ||
232 | + # Now it should not contain the disabled community | ||
233 | + get( | ||
234 | + :software_infos, | ||
235 | + :query => "software" | ||
236 | + ) | ||
237 | + | ||
238 | + assert_includes assigns(:searches)[:software_infos][:results], s1.community | ||
239 | + assert_not_includes assigns(:searches)[:software_infos][:results], s2.community | ||
240 | + end | ||
241 | + | ||
242 | + should "software_infos search not return software with secret community" do | ||
243 | + software_one = create_software_info("Software ABC", :acronym => "SFO", :finality => "Help") | ||
244 | + software_two = create_software_info("Python", :acronym => "SFT", :finality => "Task") | ||
245 | + software_three = create_software_info("Software DEF", :acronym => "SFW", :finality => "Java") | ||
246 | + | ||
247 | + software_one.community.secret = true | ||
248 | + software_one.community.save! | ||
249 | + | ||
250 | + get( | ||
251 | + :software_infos, | ||
252 | + ) | ||
253 | + | ||
254 | + assert_includes assigns(:searches)[:software_infos][:results], software_two.community | ||
255 | + assert_includes assigns(:searches)[:software_infos][:results], software_three.community | ||
256 | + assert_not_includes assigns(:searches)[:software_infos][:results], software_one.community | ||
257 | + end | ||
258 | + | ||
217 | private | 259 | private |
218 | 260 | ||
219 | def create_software_categories | 261 | def create_software_categories |
views/blocks/categories_software.html.erb
@@ -8,12 +8,9 @@ | @@ -8,12 +8,9 @@ | ||
8 | <p><%= _("Categories:") %></p> | 8 | <p><%= _("Categories:") %></p> |
9 | <ul class="categories-mais-software"> | 9 | <ul class="categories-mais-software"> |
10 | 10 | ||
11 | - <% categories = Category.where(:name => "Software") %> | ||
12 | - <% unless categories.blank? %> | ||
13 | - <% categories.first.children.each do |category| %> | ||
14 | - <% unless category.software_infos.count < 1 %> | ||
15 | - <li><%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %></li> | ||
16 | - <% end %> | 11 | + <% categories.each do |category| %> |
12 | + <% unless category.software_infos.count < 1 %> | ||
13 | + <li><%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %></li> | ||
17 | <% end %> | 14 | <% end %> |
18 | <% end %> | 15 | <% end %> |
19 | </ul> | 16 | </ul> |
views/profile_editor/edit_software_community.html.erb
@@ -32,6 +32,9 @@ | @@ -32,6 +32,9 @@ | ||
32 | </div> | 32 | </div> |
33 | <% else %> | 33 | <% else %> |
34 | <div> | 34 | <div> |
35 | + <%= labelled_check_box _("Secret — hide the community and all its contents for non members and other people can't join this community unless they are invited to."), 'profile_data[secret]', true, profile.secret, :class => "profile-secret-box" %> | ||
36 | + </div> | ||
37 | + <div> | ||
35 | <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> | 38 | <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> |
36 | </div> | 39 | </div> |
37 | <div> | 40 | <div> |
@@ -84,4 +87,4 @@ | @@ -84,4 +87,4 @@ | ||
84 | <% end %> | 87 | <% end %> |
85 | <% end %> | 88 | <% end %> |
86 | <% end %> | 89 | <% end %> |
87 | -<% end %> | ||
88 | \ No newline at end of file | 90 | \ No newline at end of file |
91 | +<% end %> |
views/search/_full_community.html.erb
@@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
36 | :controller => :search, | 36 | :controller => :search, |
37 | :action => :software_infos, | 37 | :action => :software_infos, |
38 | :selected_categories_id => [category.id], | 38 | :selected_categories_id => [category.id], |
39 | - :include_non_public => !community.software_info.public_software? | 39 | + :software_type => params[:software_type] |
40 | } %> | 40 | } %> |
41 | </li> | 41 | </li> |
42 | <% end %> | 42 | <% end %> |