From b83367063e71298296555c54e2d3f5032146d350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 31 Mar 2015 14:03:01 +0200 Subject: [PATCH] Small improvement to dashboard loading error handling --- pkg/middleware/auth.go | 3 +-- public/app/routes/dashLoadControllers.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/middleware/auth.go b/pkg/middleware/auth.go index 53b554942a6..3d73b15c7f3 100644 --- a/pkg/middleware/auth.go +++ b/pkg/middleware/auth.go @@ -42,6 +42,7 @@ func authDenied(c *Context) { return } + c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+c.Req.RequestURI), 0, setting.AppSubUrl+"/") c.Redirect(setting.AppSubUrl + "/login") } @@ -63,13 +64,11 @@ func RoleAuth(roles ...m.RoleType) macaron.Handler { func Auth(options *AuthOptions) macaron.Handler { return func(c *Context) { if !c.IsGrafanaAdmin && options.ReqGrafanaAdmin { - c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+c.Req.RequestURI), 0, setting.AppSubUrl+"/") authDenied(c) return } if !c.IsSignedIn && options.ReqSignedIn && !c.AllowAnonymous { - c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubUrl+c.Req.RequestURI), 0, setting.AppSubUrl+"/") authDenied(c) return } diff --git a/public/app/routes/dashLoadControllers.js b/public/app/routes/dashLoadControllers.js index 8e888c07a80..51db273eac0 100644 --- a/public/app/routes/dashLoadControllers.js +++ b/public/app/routes/dashLoadControllers.js @@ -12,12 +12,15 @@ function (angular, _, kbn, moment, $) { module.controller('DashFromDBCtrl', function($scope, $routeParams, backendSrv) { + function dashboardLoadFailed(title) { + $scope.initDashboard({meta: {}, model: {title: title}}, $scope); + } + if (!$routeParams.slug) { backendSrv.get('/api/dashboards/home').then(function(result) { $scope.initDashboard(result, $scope); },function() { - $scope.initDashboard({}, $scope); - $scope.appEvent('alert-error', ['Load dashboard failed', '']); + dashboardLoadFailed('Not found'); }); return; @@ -26,17 +29,15 @@ function (angular, _, kbn, moment, $) { return backendSrv.getDashboard($routeParams.slug).then(function(result) { $scope.initDashboard(result, $scope); }, function() { - $scope.initDashboard({ - meta: {}, - model: { title: 'Not found' } - }, $scope); + dashboardLoadFailed('Not found'); }); + }); module.controller('DashFromSnapshotCtrl', function($scope, $routeParams, backendSrv) { backendSrv.get('/api/snapshots/' + $routeParams.key).then(function(result) { $scope.initDashboard(result, $scope); - },function() { + }, function() { $scope.initDashboard({meta: {isSnapshot: true}, model: {title: 'Snapshot not found'}}, $scope); }); });