]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3825 allow to drop/edit system filters
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Dec 2012 14:48:03 +0000 (15:48 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 5 Dec 2012 14:48:13 +0000 (15:48 +0100)
sonar-server/src/main/webapp/WEB-INF/app/models/measure_filter.rb
sonar-server/src/main/webapp/WEB-INF/app/views/measures/manage.html.erb

index b2ebe1a5c7e4eefaeb7e9b7ddc7b99b2b17d5278..b4deac5762547693b16a78019fd47e526423ecfe 100644 (file)
@@ -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
index e1c9a1976aee55dc7b95a622e74b1fb7d0a1f837..820f2f55969f73fb9401e3303317ea881f817ab2 100644 (file)
@@ -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 @@
         <tbody>
         <% if current_user.measure_filters.empty? %>
           <tr class="even">
-            <td colspan="4"><%= message('filters.no_filters') -%></td>
+            <td colspan="4"><%= message('measure_filter.no_filters') -%></td>
           </tr>
         <% else %>
           <% current_user.measure_filters.each do |filter| %>
               </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>
+                <% if filter.system? && has_role?(:admin) %>
+                  &nbsp;
+                  <a id="edit_system_<%= filter.name.parameterize -%>" href="<%= ApplicationController.root_context -%>/measures/edit_form/<%= filter.id -%>" class="link-action open-modal"><%= message('edit') -%></a>
+                  &nbsp;
+                  <%= 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 %>
               </td>
             </tr>
           <% end %>