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
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
#------------------------------------------------------------------------------
#
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),
@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>
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
--- /dev/null
+#
+# 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
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
<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()}")
%>
<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>
: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>
</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>
--- /dev/null
+<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>
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
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