From: Simon Brandhof Date: Thu, 29 Jan 2015 15:48:57 +0000 (+0100) Subject: SONAR-6128 Should not be possible to delete global default dashboards X-Git-Tag: 4.5.3~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=068a5e511ac0865825f682246ba3a8f8cb9e96a9;p=sonarqube.git SONAR-6128 Should not be possible to delete global default dashboards --- diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb index e262a6c3850..7336c98a363 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/admin_dashboards_controller.rb @@ -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'