diff options
11 files changed, 164 insertions, 9 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index a0a87406463..a21573326fc 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -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 #------------------------------------------------------------------------------ # diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 576451a88a2..ea4589cf455 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -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), diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index 1b47de87cd9..6e4d283ff16 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -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 index 00000000000..43cebd75465 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/system_measure_filters_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb index 984ecc84b78..cc5e50dc5b2 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb index cc5851e7536..0ab7c92f1a9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/layouts/_layout.html.erb @@ -147,6 +147,8 @@ <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()}") %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb index 48e5a3fc889..a5b6f5ddd2e 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb @@ -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> @@ -106,7 +106,7 @@ <% 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> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb index e27ee1e0307..5e9fe5f1be1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/measures/search.html.erb @@ -106,9 +106,18 @@ </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 index 00000000000..bb87a5bc4a4 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/system_measure_filters/index.html.erb @@ -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> diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/356_create_measure_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/356_create_measure_filters.rb index 30f5210435a..b7066509f5f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/356_create_measure_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/356_create_measure_filters.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb index f0b4b836f90..a1a5b1b8f53 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/357_move_existing_measure_filters.rb @@ -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 |