]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6128 Should not be possible to delete global default dashboards
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 29 Jan 2015 15:48:57 +0000 (16:48 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 29 Jan 2015 15:49:57 +0000 (16:49 +0100)
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb

index e262a6c385076cdb915feaaecd15fa09bef39038..7336c98a36345bf71385dfa3432e8663f38f55a8 100644 (file)
@@ -57,14 +57,16 @@ class AdminDashboardsController < ApplicationController
 
   def remove
     verify_post_request
-    if @actives.size<=1
+
+    to_be_removed = ActiveDashboard.find(params[:id])
+    not_found unless to_be_removed
+
+    remaining_defaults = @actives.select { |a| (a.global? == to_be_removed.global? && a.id != to_be_removed.id) }
+    if remaining_defaults.size == 0
       flash[:error]='At least one dashboard must be defined as default.'
     else
-      active=@actives.find { |a| a.id==params[:id].to_i }
-      if active
-        active.destroy
-        flash[:notice]='Dashboard removed from default dashboards.'
-      end
+      to_be_removed.destroy
+      flash[:notice]='Dashboard removed from default dashboards.'
     end
 
     redirect_to :action => 'index'