From 7d603e52d7e084f93485d50a71227b4c32eff3e8 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 5 Dec 2012 15:48:03 +0100 Subject: [PATCH] SONAR-3825 allow to drop/edit system filters --- .../WEB-INF/app/models/measure_filter.rb | 6 +++++ .../app/views/measures/manage.html.erb | 22 ++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) 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 b2ebe1a5c7e..b4deac57625 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 @@ -174,6 +174,10 @@ class MeasureFilter < ActiveRecord::Base end end + def system? + user_id == nil + end + # ==== Options # :user : the authenticated user def execute(controller, options={}) @@ -279,6 +283,8 @@ class MeasureFilter < ActiveRecord::Base if shared 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 + elsif system? + errors.add_to_base("System filters can't be unshared.") end end end \ No newline at end of file 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 e1c9a1976ae..820f2f55969 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 @@ -5,10 +5,10 @@ var filterId = $j(this).attr('filter-id'); var star = $j(this); $j.ajax({ - type:'POST', - url:baseUrl + "/measures/toggle_fav", - data:{id:filterId}, - success:function (data) { + type: 'POST', + url: baseUrl + "/measures/toggle_fav", + data: {id: filterId}, + success: function (data) { if (data == 'true') { star.removeClass('notfav').addClass('fav'); star.attr('title', '<%= escape_javascript message('click_to_remove_from_favourites') -%>'); @@ -42,7 +42,7 @@ <% if current_user.measure_filters.empty? %> - <%= message('filters.no_filters') -%> + <%= message('measure_filter.no_filters') -%> <% else %> <% current_user.measure_filters.each do |filter| %> @@ -116,6 +116,18 @@ <%= message('copy') -%> + <% if filter.system? && has_role?(:admin) %> +   + <%= message('edit') -%> +   + <%= link_to_action message('delete'), "#{ApplicationController.root_context}/measures/delete/#{filter.id}", + :class => 'link-action link-red', + :id => "delete_system_#{filter.name.parameterize}", + :confirm_button => message('delete'), + :confirm_title => 'measure_filter.delete_confirm_title', + :confirm_msg => 'measure_filter.are_you_sure_want_delete_filter_x', + :confirm_msg_params => [filter.name] -%> + <% end %> <% end %> -- 2.39.5