From 76bdc0dce4922708aaca0583b126a7f6ca3559c2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 13 Aug 2013 15:55:18 +0200 Subject: [PATCH] SONAR-4552 Display a nice error page when requesting a page that tries to display a non-existing project --- .../resources/org/sonar/l10n/core.properties | 1 + .../app/controllers/dashboard_controller.rb | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 21d6117d9e0..eb291c817c1 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -689,6 +689,7 @@ dashboard.shared_dashboards.description=These dashboards can be added to default dashboard.username.default=[SonarQube] dashboard.delete_confirm_title=Delete dashboard dashboard.delete_dashboard=Delete dashboard +dashboard.project_not_found=The requested project does not exist. Either it has never been analyzed successfully or it has been deleted. #------------------------------------------------------------------------------ diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb index 7d096f9931a..93d39dce42b 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboard_controller.rb @@ -181,8 +181,23 @@ class DashboardController < ApplicationController end def load_resource - init_resource_for_user_role unless !params[:id] - @project=@resource # for backward compatibility with old widgets + if params[:id] + @resource=Project.by_key(params[:id]) + return project_not_found unless @resource + @resource=@resource.permanent_resource + + @snapshot=@resource.last_snapshot + return project_not_found unless @snapshot + + access_denied unless has_role?(:user, @resource) + + @project=@resource # for backward compatibility with old widgets + end + end + + def project_not_found + flash[:error] = message('dashboard.project_not_found') + redirect_to :action => :index end def load_authorized_widget_definitions -- 2.39.5