From 4038b4d17e47684c1aaa05ea432c52123f24dcf1 Mon Sep 17 00:00:00 2001 From: Mukesh Date: Thu, 26 May 2016 10:21:23 +0530 Subject: [PATCH 1/3] Set active org through admin api (#5179) --- pkg/api/api.go | 1 + pkg/api/user.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/api/api.go b/pkg/api/api.go index f4b096f0b04..070f400aaad 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -115,6 +115,7 @@ func Register(r *macaron.Macaron) { r.Get("/:id", wrap(GetUserById)) r.Get("/:id/orgs", wrap(GetUserOrgList)) r.Put("/:id", bind(m.UpdateUserCommand{}), wrap(UpdateUser)) + r.Post("/:id/using/:orgId", wrap(UpdateUserActiveOrg)) }, reqGrafanaAdmin) // org information available to all users. diff --git a/pkg/api/user.go b/pkg/api/user.go index 8f54feaf6a0..f98eec02c40 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -40,6 +40,24 @@ func UpdateUser(c *middleware.Context, cmd m.UpdateUserCommand) Response { return handleUpdateUser(cmd) } +//POST /api/users/:id/using/:orgId +func UpdateUserActiveOrg(c *middleware.Context) Response { + userId := c.ParamsInt64(":id") + orgId := c.ParamsInt64(":orgId") + + if !validateUsingOrg(userId, orgId) { + return ApiError(401, "Not a valid organization", nil) + } + + cmd := m.SetUsingOrgCommand{UserId: userId, OrgId: orgId} + + if err := bus.Dispatch(&cmd); err != nil { + return ApiError(500, "Failed change active organization", err) + } + + return ApiSuccess("Active organization changed") +} + func handleUpdateUser(cmd m.UpdateUserCommand) Response { if len(cmd.Login) == 0 { cmd.Login = cmd.Email From c9d6321f382cd7a30f0faa927b43cd5b97d03b06 Mon Sep 17 00:00:00 2001 From: Jared Wiltshire Date: Thu, 26 May 2016 15:13:29 +1000 Subject: [PATCH 2/3] Allow for proxying Authorization header and automatically convert (#4832) Authorization header to X-DS-Authorization in backend_srv.js --- pkg/api/dataproxy.go | 7 +++++++ public/app/core/services/backend_srv.js | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/pkg/api/dataproxy.go b/pkg/api/dataproxy.go index b00ef595161..9a062ddfd2d 100644 --- a/pkg/api/dataproxy.go +++ b/pkg/api/dataproxy.go @@ -55,6 +55,13 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string, targetUrl *url.URL) *ht req.Header.Add("Authorization", util.GetBasicAuthHeader(ds.BasicAuthUser, ds.BasicAuthPassword)) } + dsAuth := req.Header.Get("X-DS-Authorization") + if len(dsAuth) > 0 { + req.Header.Del("X-DS-Authorization") + req.Header.Del("Authorization") + req.Header.Add("Authorization", dsAuth) + } + // clear cookie headers req.Header.Del("Cookie") req.Header.Del("Set-Cookie") diff --git a/public/app/core/services/backend_srv.js b/public/app/core/services/backend_srv.js index ff3784ab45e..f27e427c70b 100644 --- a/public/app/core/services/backend_srv.js +++ b/public/app/core/services/backend_srv.js @@ -96,6 +96,11 @@ function (angular, _, coreModule, config) { var requestIsLocal = options.url.indexOf('/') === 0; var firstAttempt = options.retry === 0; + if (requestIsLocal && options.headers && options.headers.Authorization) { + options.headers['X-DS-Authorization'] = options.headers.Authorization; + delete options.headers.Authorization; + } + return $http(options).then(null, function(err) { // handle unauthorized for backend requests if (requestIsLocal && firstAttempt && err.status === 401) { From dd494e648a5c05dc0eba2e8a82f9f81bf43e5188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 26 May 2016 07:45:53 +0200 Subject: [PATCH 3/3] fix(rendering): fixed issue with phantomjs panel rendering --- public/app/features/panel/partials/soloPanel.html | 12 ++++-------- vendor/phantomjs/render.js | 4 +++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/public/app/features/panel/partials/soloPanel.html b/public/app/features/panel/partials/soloPanel.html index e76ad724343..131d99d4389 100644 --- a/public/app/features/panel/partials/soloPanel.html +++ b/public/app/features/panel/partials/soloPanel.html @@ -1,9 +1,5 @@ -
-
-
-
- - -
-
+
+ +
+
diff --git a/vendor/phantomjs/render.js b/vendor/phantomjs/render.js index 0de97273c5c..f40a42380ad 100644 --- a/vendor/phantomjs/render.js +++ b/vendor/phantomjs/render.js @@ -39,7 +39,8 @@ var canvas = page.evaluate(function() { if (!window.angular) { return false; } var body = window.angular.element(document.body); - if (!body.scope) { return false; } + if (!body.injector) { return false; } + if (!body.injector()) { return false; } var rootScope = body.injector().get('$rootScope'); if (!rootScope) {return false;} @@ -59,6 +60,7 @@ width: bb.width, height: bb.height }; + page.render(params.png); phantom.exit(); }