]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2073 - Fix which filters are visible and group them by category.
authorDavid Gageot <david@gageot.net>
Mon, 14 May 2012 13:12:08 +0000 (15:12 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 14 May 2012 13:13:00 +0000 (15:13 +0200)
In a filter widget you shouldn't access to a filter created by another user but not shared by this user.

Moreover, in the dropdown list to select a filter to be displayed it would be valuable to display to different sections : one for "my own filters" and the other one for the "shared filters".

sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/widget_properties_helper.rb

index 32f1b4a0ae22e14f4539bc10b9625f28f51f875c..c876475584327016ab98175ab0af9618a6f0f866 100644 (file)
@@ -28,7 +28,7 @@ class FiltersController < ApplicationController
   before_filter :login_required, :except => ['index', 'treemap']
 
   def manage
-    @filters = ::Filter.find(:all, :conditions => ['user_id=? or user_id is null', current_user.id])
+    @filters = ::Filter.find(:all, :conditions => ['user_id=? or shared is true', current_user.id])
   end
 
   def new
index 165b68b22c13ebe3c474db8cf5d4a41a7051d3d8..cdca2e2d28287a03a93094e6e7f18dd649d56bd1 100644 (file)
@@ -37,7 +37,11 @@ module WidgetPropertiesHelper
       text_field_tag definition.key(), val, :size => 10
 
     elsif definition.type.name()==WidgetProperty::TYPE_FILTER
-      select_tag definition.key(), ::Filter.all.sort_by(&:id).collect { |f| "<option value='#{f.id}'" + (value == f.id.to_s ? " selected='selected'" : "") + ">#{f.name}</option>" }
+      user_filters = ::Filter.find(:all, :conditions => ['user_id=?', current_user.id]).sort_by(&:id).collect { |f| "<option value='#{f.id}'" + (value == f.id.to_s ? " selected='selected'" : "") + ">#{f.name}</option>" }
+      shared_filters = ::Filter.find(:all, :conditions => ['(user_id<>? or user_id is null) and shared is true', current_user.id]).sort_by(&:id).collect { |f| "<option value='#{f.id}'" + (value == f.id.to_s ? " selected='selected'" : "") + ">#{f.name}</option>" }
+      all_filters = '<optgroup label="My Filters">' + user_filters.to_s + '</optgroup>' + '<optgroup label="Shared Filters">' + shared_filters.to_s + '</optgroup>'
+
+      select_tag definition.key(), all_filters
 
     else
       hidden_field_tag definition.key()