From bbfa49753a730cc57831f7de548f5e3625d8a7e4 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 11 Feb 2015 17:11:29 +0100 Subject: [PATCH] SONAR-6132 Dashboard is failing on removed components --- .../app/controllers/dashboard_controller.rb | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 5d4a6cf741e..7c6fdc34a30 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -25,22 +25,27 @@ class DashboardController < ApplicationController def index load_resource() - - if !@resource || @resource.display_dashboard? - load_dashboard() - load_authorized_widget_definitions() - else - # display the layout of the parent without the sidebar, usually the directory, but display the file viewers - @hide_sidebar = true - @file = @resource - @project = @snapshot.parent.project - @metric=params[:metric] - render :action => 'no_dashboard' + if !@resource || @resource.display_dashboard? + redirect_if_bad_component() + load_dashboard() + load_authorized_widget_definitions() + else + if !@resource || !@snapshot + redirect_if_bad_component() + else + # display the layout of the parent without the sidebar, usually the directory, but display the file viewers + @hide_sidebar = true + @file = @resource + @project = @snapshot.parent.project + @metric=params[:metric] + render :action => 'no_dashboard' + end end end def configure load_resource() + redirect_if_bad_component() load_dashboard() @category=params[:category] @@ -136,6 +141,7 @@ class DashboardController < ApplicationController def widget_definitions @category=params[:category] load_resource() + # redirect_if_bad_component() load_dashboard() load_widget_definitions(@category) render :partial => 'widget_definitions', :locals => {:category => @category} @@ -183,12 +189,12 @@ class DashboardController < ApplicationController def load_resource if params[:id] - @resource=Project.by_key(params[:id]) - return project_not_found unless @resource + @resource = Project.by_key(params[:id]) + return unless @resource @resource=@resource.permanent_resource @snapshot=@resource.last_snapshot - return project_not_analyzed unless @snapshot + return unless @snapshot access_denied unless has_role?(:user, @resource) @@ -196,6 +202,17 @@ class DashboardController < ApplicationController end end + def redirect_if_bad_component + if params[:id] + unless @resource + return project_not_found + end + unless @snapshot + project_not_analyzed + end + end + end + def project_not_found flash[:error] = message('dashboard.project_not_found') redirect_to :action => :index -- 2.39.5