]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 manage system filters
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 26 Nov 2012 16:27:58 +0000 (17:27 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 26 Nov 2012 16:27:58 +0000 (17:27 +0100)
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/system_measure_filters_controller.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/system_measure_filters/index.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/356_create_measure_filters.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb

index a0a87406463110f11eaf5bbeab90d36287c8188e..a21573326fccd4fe4f560189631a2440a4b1dd48 100644 (file)
@@ -353,6 +353,7 @@ resource_deletion.page={0} Deletion
 update_key.page=Update Key
 project_quality_profiles.page=Quality Profiles
 bulk_deletion.page=Bulk Deletion
+system_measure_filters.page=System Measure Filters
 
 
 # GWT pages
@@ -391,7 +392,13 @@ measure_filter.col.short_name=Name
 measure_filter.col.version=Version
 measure_filter.missing_name=Name is missing
 measure_filter.name_too_long=Name is too long
-
+measure_filter.sharing=Sharing
+measure_filter.delete_confirm_title=Delete Filter
+measure_filter.are_you_sure_want_delete_filter_x=Are you sure that you want to delete the filter "{0}"?
+measure_filter.remove_from_system=Remove from system
+measure_filter.add_to_system=Add to system
+measure_filter.title_shared_filters=Shared Filters
+measure_filter.title_system_filters=System Filters
 
 #------------------------------------------------------------------------------
 #
index 576451a88a2539f163466a2506058b190558b244..ea4589cf455f3cacc83017697c61dd1534426f35 100644 (file)
@@ -517,6 +517,7 @@ CREATE TABLE "SEMAPHORES" (
 CREATE TABLE "MEASURE_FILTERS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "NAME" VARCHAR(100) NOT NULL,
+  "SYSTEM" BOOLEAN,
   "SHARED" BOOLEAN NOT NULL DEFAULT FALSE,
   "USER_ID" INTEGER,
   "DESCRIPTION" VARCHAR(4000),
index 1b47de87cd9fd50931222aecf642fa5dd05016f0..6e4d283ff16f570ee3c6f9590d0b154b6d463359 100644 (file)
@@ -87,8 +87,8 @@ class MeasuresController < ApplicationController
     @shared_filters = MeasureFilter.find(:all,
                                          :include => :user,
                                          :conditions => ['shared=? and user_id<>?', true, current_user.id])
-    @fav_filter_ids = current_user.measure_filter_favourites.map { |fav| fav.measure_filter_id }
     Api::Utils.insensitive_sort!(@shared_filters) { |elt| elt.name }
+    @fav_filter_ids = current_user.measure_filter_favourites.map { |fav| fav.measure_filter_id }
   end
 
   # GET /measures/edit_form/<filter id>
@@ -183,7 +183,7 @@ class MeasuresController < ApplicationController
   end
 
   def owner?(filter)
-    current_user && filter.user_id==current_user.id
+    current_user && (filter.user_id==current_user.id || (filter.user_id==nil && has_role?(:admin)))
   end
 
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/system_measure_filters_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/system_measure_filters_controller.rb
new file mode 100644 (file)
index 0000000..43cebd7
--- /dev/null
@@ -0,0 +1,61 @@
+#
+# Sonar, open source software quality management tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+class SystemMeasureFiltersController < ApplicationController
+  SECTION = Navigation::SECTION_CONFIGURATION
+
+  # GET /system_measure_filters/index
+  def index
+    access_denied unless has_role?(:admin)
+
+    @system_filters = MeasureFilter.find(:all, :include => :user, :conditions => ['system=?', true])
+    Api::Utils.insensitive_sort!(@system_filters) { |f| f.name }
+
+    @shared_filters = MeasureFilter.find(:all, :include => :user, :conditions => ['shared=? and system=?', true, false])
+  end
+
+  # POST /system_measure_filters/add/<filter id>
+  def add
+    verify_post_request
+    access_denied unless has_role?(:admin)
+    require_parameters :id
+
+    filter = MeasureFilter.find(params[:id])
+    filter.system=true
+    unless filter.save
+      flash[:error]=filter.errors.full_messages.join("<br/>")
+    end
+    redirect_to :action => :index
+  end
+
+  # POST /system_measure_filters/remove/<filter id>
+  def remove
+    verify_post_request
+    access_denied unless has_role?(:admin)
+    require_parameters :id
+
+    filter = MeasureFilter.find(params[:id])
+    filter.system=false
+    unless filter.save
+      flash[:error]=filter.errors.full_messages.join("<br/>")
+    end
+    redirect_to :action => :index
+  end
+
+end
index 984ecc84b78ad435f40c34f0137b848475c49940..cc5e50dc5b2c0165f10db8792bee5631bc631b3e 100644 (file)
@@ -362,5 +362,7 @@ class MeasureFilter < ActiveRecord::Base
       count = MeasureFilter.count('id', :conditions => ['name=? and shared=? and user_id!=?', name, true, user_id])
       errors.add_to_base('Other users already shared filters with the same name') if count>0
     end
+
+    errors.add_to_base('Only shared filters can be flagged as system filter') if system && !shared
   end
 end
\ No newline at end of file
index cc5851e7536e78029a93d40d74ff4e41027ca1e2..0ab7c92f1a932b12a66165033c0627d949a4392c 100644 (file)
               <a href="<%= ApplicationController.root_context -%>/manual_rules/index"><%= message('manual_rules.page') -%></a></li>
             <li class="<%= 'selected' if controller.controller_path=='admin_dashboards' -%>">
               <a href="<%= ApplicationController.root_context -%>/admin_dashboards/index"><%= message('default_dashboards.page') -%></a></li>
+            <li class="<%= 'selected' if controller.controller_path=='system_measure_filters' -%>">
+              <a href="<%= ApplicationController.root_context -%>/system_measure_filters"><%= message('system_measure_filters.page') -%></a></li>
             <% controller.java_facade.getPages(Navigation::SECTION_CONFIGURATION, nil, nil, nil, nil).each do |page|
               page_url = (page.isController() ? page.getId() : "/plugins/configuration/#{page.getId()}")
             %>
index 48e5a3fc889fd853af13e22ffccf42ca1db8b0ee..a5b6f5ddd2e1999b1f8362ee0d76968e000fdb28 100644 (file)
@@ -29,7 +29,7 @@
   <tr>
     <th class="thin"></th>
     <th><%= message('name') -%></th>
-    <th><%= message('sharing') -%></th>
+    <th><%= message('measure_filter.sharing') -%></th>
     <th class="right"><%= message('operations') -%></th>
   </tr>
   </thead>
@@ -66,8 +66,8 @@
                              :class => 'link-action link-red',
                              :id => "delete_#{filter.name.parameterize}",
                              :confirm_button => message('delete'),
-                             :confirm_title => 'measure_filters.delete_confirm_title',
-                             :confirm_msg => 'measure_filters.are_you_sure_want_delete_filter_x',
+                             :confirm_title => 'measure_filter.delete_confirm_title',
+                             :confirm_msg => 'measure_filter.are_you_sure_want_delete_filter_x',
                              :confirm_msg_params => [filter.name] -%>
         </td>
       </tr>
           <% end %>
         </td>
         <td>
-          <%= h filter.user.name -%>
+          <%= filter.user ? h(filter.user.name) : '-' -%>
         </td>
         <td class="thin nowrap right">
           <a id="copy-<%= filter.name.parameterize -%>" href="<%= ApplicationController.root_context -%>/measures/copy_form/<%= filter.id -%>" class="link-action open-modal"><%= message('copy') -%></a>
index e27ee1e0307cc827629540237d750f93e5267a74..5e9fe5f1be1e69a6785f88b10abb199c5d80e2e8 100644 (file)
       </table>
     </form>
 
+    <br/>
+    <ul id="system-filters">
+      <% MeasureFilter.find(:all, :select => ['id,name'], :conditions => ['system=?', true]).each do |system_filter| %>
+        <li>
+          <a href="<%= ApplicationController.root_context -%>/measures/filter/<%= system_filter.id -%>"><%= h system_filter.name -%></a>
+        </li>
+      <% end %>
+    </ul>
+
     <% if logged_in? %>
       <br/>
-      <ul id="my-filters">
+      <ul id="fav-filters">
         <% current_user.favourited_measure_filters.each do |my_filter| %>
           <li>
             <a href="<%= ApplicationController.root_context -%>/measures/filter/<%= my_filter.id -%>"><%= h my_filter.name -%></a>
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/system_measure_filters/index.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/system_measure_filters/index.html.erb
new file mode 100644 (file)
index 0000000..bb87a5b
--- /dev/null
@@ -0,0 +1,71 @@
+<h2><%= h message('measure_filter.title_system_filters') %></h2>
+<table class="data marginbottom10" id="system-filters">
+  <thead>
+  <tr>
+    <th><%= message('name') -%></th>
+    <th><%= message('shared_by') -%></th>
+    <th class="right"><%= message('operations') -%></th>
+  </tr>
+  </thead>
+  <tbody>
+  <% if @system_filters.empty? %>
+    <tr class="even">
+      <td colspan="3"><%= message('filters.no_filters') -%></td>
+    </tr>
+  <% else %>
+    <% @system_filters.each do |filter| %>
+      <tr id="system-<%= filter.name.parameterize -%>" class="<%= cycle('even', 'odd', :name => 'system-filters') -%>">
+        <td>
+          <%= link_to h(filter.name), :action => 'filter', :id => filter.id -%>
+          <% if filter.description %>
+            <div><%= h filter.description -%></div>
+          <% end %>
+        </td>
+        <td>
+          <%= filter.user ? h(filter.user.name) : '-' -%>
+        </td>
+        <td class="thin nowrap right">
+          <%=  link_to message('measure_filter.remove_from_system'), {:action => :remove, :id => filter.id}, {:class => 'button', :method => :post} -%>
+        </td>
+      </tr>
+    <% end %>
+  <% end %>
+  </tbody>
+</table>
+
+<br/>
+
+<h2><%= h message('measure_filter.title_shared_filters') %></h2>
+<table class="data" id="shared-filters">
+  <thead>
+  <tr>
+    <th><%= message('name') -%></th>
+    <th><%= message('shared_by') -%></th>
+    <th class="right"><%= message('operations') -%></th>
+  </tr>
+  </thead>
+  <tbody>
+  <% if @shared_filters.empty? %>
+    <tr class="even">
+      <td colspan="4"><%= message('filters.no_filters') -%></td>
+    </tr>
+  <% else %>
+    <% @shared_filters.each do |filter| %>
+      <tr id="shared-<%= filter.name.parameterize -%>" class="<%= cycle('even', 'odd', :name => 'shared-filters') -%>">
+        <td>
+          <%= link_to h(filter.name), :action => 'filter', :id => filter.id -%>
+          <% if filter.description %>
+            <div><%= h filter.description -%></div>
+          <% end %>
+        </td>
+        <td>
+          <%= filter.user ? h(filter.user.name) : '-' -%>
+        </td>
+        <td class="thin nowrap right">
+          <%=  link_to message('measure_filter.add_to_system'), {:action => :add, :id => filter.id}, {:class => 'button', :method => :post} -%>
+        </td>
+      </tr>
+    <% end %>
+  <% end %>
+  </tbody>
+</table>
index 30f5210435a97b1027e1b60039e5eb781f6ce6fe..b7066509f5fd10bf09e8e1836a7003e2a9216872 100644 (file)
@@ -27,6 +27,7 @@ class CreateMeasureFilters < ActiveRecord::Migration
       t.column 'name', :string, :null => false, :limit => 100
       t.column 'user_id', :integer, :null => true
       t.column 'shared', :boolean, :default => false, :null => false
+      t.column 'system', :boolean
       t.column 'description', :string, :null => true, :limit => 4000
       t.column 'data', :text, :null => true
       t.timestamps
index f0b4b836f9000c052f3bc28ace6b2c2666c68885..a1a5b1b8f535f62f3792cd5fe875c55c532103b6 100644 (file)
@@ -57,7 +57,8 @@ class MoveExistingMeasureFilters < ActiveRecord::Migration
     new_filter = MeasureFilter.new
     new_filter.name = old_filter.name
     new_filter.user_id = old_filter.user_id
-    new_filter.shared = old_filter.shared
+    new_filter.system = old_filter.user_id.nil?
+    new_filter.shared = (old_filter.shared || old_filter.user_id.nil?)
     data = []
     data << 'onFavourites=true' if old_filter.favourites
     if old_filter.resource_id