mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 05:21:50 +08:00
fix(org switch): fixed issue with switching orgs, fixes #4614
This commit is contained in:
@ -30,6 +30,7 @@ func Register(r *macaron.Macaron) {
|
|||||||
// authed views
|
// authed views
|
||||||
r.Get("/profile/", reqSignedIn, Index)
|
r.Get("/profile/", reqSignedIn, Index)
|
||||||
r.Get("/profile/password", reqSignedIn, Index)
|
r.Get("/profile/password", reqSignedIn, Index)
|
||||||
|
r.Get("/profile/switch-org/:id", reqSignedIn, ChangeActiveOrgAndRedirectToHome)
|
||||||
r.Get("/org/", reqSignedIn, Index)
|
r.Get("/org/", reqSignedIn, Index)
|
||||||
r.Get("/org/new", reqSignedIn, Index)
|
r.Get("/org/new", reqSignedIn, Index)
|
||||||
r.Get("/datasources/", reqSignedIn, Index)
|
r.Get("/datasources/", reqSignedIn, Index)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/middleware"
|
"github.com/grafana/grafana/pkg/middleware"
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
m "github.com/grafana/grafana/pkg/models"
|
||||||
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/grafana/grafana/pkg/util"
|
"github.com/grafana/grafana/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,6 +110,23 @@ func UserSetUsingOrg(c *middleware.Context) Response {
|
|||||||
return ApiSuccess("Active organization changed")
|
return ApiSuccess("Active organization changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET /profile/switch-org/:id
|
||||||
|
func ChangeActiveOrgAndRedirectToHome(c *middleware.Context) {
|
||||||
|
orgId := c.ParamsInt64(":id")
|
||||||
|
|
||||||
|
if !validateUsingOrg(c.UserId, orgId) {
|
||||||
|
NotFoundHandler(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := m.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgId}
|
||||||
|
|
||||||
|
if err := bus.Dispatch(&cmd); err != nil {
|
||||||
|
NotFoundHandler(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Redirect(setting.AppSubUrl + "/")
|
||||||
|
}
|
||||||
|
|
||||||
func ChangeUserPassword(c *middleware.Context, cmd m.ChangeUserPasswordCommand) Response {
|
func ChangeUserPassword(c *middleware.Context, cmd m.ChangeUserPasswordCommand) Response {
|
||||||
userQuery := m.GetUserByIdQuery{Id: c.UserId}
|
userQuery := m.GetUserByIdQuery{Id: c.UserId}
|
||||||
|
|
||||||
|
@ -72,9 +72,8 @@ export class SideMenuCtrl {
|
|||||||
this.orgMenu.push({
|
this.orgMenu.push({
|
||||||
text: "Switch to " + org.name,
|
text: "Switch to " + org.name,
|
||||||
icon: "fa fa-fw fa-random",
|
icon: "fa fa-fw fa-random",
|
||||||
click: () => {
|
url: this.getUrl('/profile/switch-org/' + org.orgId),
|
||||||
this.switchOrg(org.orgId);
|
target: '_self'
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user