From 068a5e511ac0865825f682246ba3a8f8cb9e96a9 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 29 Jan 2015 16:48:57 +0100 Subject: [PATCH] SONAR-6128 Should not be possible to delete global default dashboards --- .../app/controllers/admin_dashboards_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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' -- 2.39.5