mirror of
https://github.com/grafana/grafana.git
synced 2026-08-12 06:05:02 -05:00
Big Backend Refatoring: Renamed Account -> Org
This commit is contained in:
+20
-20
@@ -11,7 +11,7 @@ func GetUser(c *middleware.Context) {
|
||||
query := m.GetUserInfoQuery{UserId: c.UserId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
c.JsonApiErr(500, "Failed to get account", err)
|
||||
c.JsonApiErr(500, "Failed to get user", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@ func UpdateUser(c *middleware.Context, cmd m.UpdateUserCommand) {
|
||||
cmd.UserId = c.UserId
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
c.JsonApiErr(400, "Failed to update account", err)
|
||||
c.JsonApiErr(400, "Failed to update user", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JsonOK("Account updated")
|
||||
c.JsonOK("User updated")
|
||||
}
|
||||
|
||||
func GetUserAccounts(c *middleware.Context) {
|
||||
query := m.GetUserAccountsQuery{UserId: c.UserId}
|
||||
func GetUserOrgList(c *middleware.Context) {
|
||||
query := m.GetUserOrgListQuery{UserId: c.UserId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
c.JsonApiErr(500, "Failed to get user accounts", err)
|
||||
c.JsonApiErr(500, "Failed to get user organizations", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, ac := range query.Result {
|
||||
if ac.AccountId == c.AccountId {
|
||||
if ac.OrgId == c.OrgId {
|
||||
ac.IsUsing = true
|
||||
break
|
||||
}
|
||||
@@ -47,17 +47,17 @@ func GetUserAccounts(c *middleware.Context) {
|
||||
c.JSON(200, query.Result)
|
||||
}
|
||||
|
||||
func validateUsingAccount(userId int64, accountId int64) bool {
|
||||
query := m.GetUserAccountsQuery{UserId: userId}
|
||||
func validateUsingOrg(userId int64, orgId int64) bool {
|
||||
query := m.GetUserOrgListQuery{UserId: userId}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// validate that the account id in the list
|
||||
// validate that the org id in the list
|
||||
valid := false
|
||||
for _, other := range query.Result {
|
||||
if other.AccountId == accountId {
|
||||
if other.OrgId == orgId {
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
@@ -65,25 +65,25 @@ func validateUsingAccount(userId int64, accountId int64) bool {
|
||||
return valid
|
||||
}
|
||||
|
||||
func SetUsingAccount(c *middleware.Context) {
|
||||
usingAccountId := c.ParamsInt64(":id")
|
||||
func UserSetUsingOrg(c *middleware.Context) {
|
||||
orgId := c.ParamsInt64(":id")
|
||||
|
||||
if !validateUsingAccount(c.UserId, usingAccountId) {
|
||||
c.JsonApiErr(401, "Not a valid account", nil)
|
||||
if !validateUsingOrg(c.UserId, orgId) {
|
||||
c.JsonApiErr(401, "Not a valid organization", nil)
|
||||
return
|
||||
}
|
||||
|
||||
cmd := m.SetUsingAccountCommand{
|
||||
UserId: c.UserId,
|
||||
AccountId: usingAccountId,
|
||||
cmd := m.SetUsingOrgCommand{
|
||||
UserId: c.UserId,
|
||||
OrgId: orgId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
c.JsonApiErr(500, "Failed change active account", err)
|
||||
c.JsonApiErr(500, "Failed change active organization", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JsonOK("Active account changed")
|
||||
c.JsonOK("Active organization changed")
|
||||
}
|
||||
|
||||
func ChangeUserPassword(c *middleware.Context, cmd m.ChangeUserPasswordCommand) {
|
||||
|
||||
Reference in New Issue
Block a user