|
|
|
|
@ -13,7 +13,7 @@ func GetSignedInUser(c *middleware.Context) Response { |
|
|
|
|
return getUserUserProfile(c.UserId) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GET /api/user/:id
|
|
|
|
|
// GET /api/users/:id
|
|
|
|
|
func GetUserById(c *middleware.Context) Response { |
|
|
|
|
return getUserUserProfile(c.ParamsInt64(":id")) |
|
|
|
|
} |
|
|
|
|
@ -22,12 +22,36 @@ func getUserUserProfile(userId int64) Response { |
|
|
|
|
query := m.GetUserProfileQuery{UserId: userId} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
|
if err == m.ErrUserNotFound { |
|
|
|
|
return ApiError(404, m.ErrUserNotFound.Error(), nil) |
|
|
|
|
} |
|
|
|
|
return ApiError(500, "Failed to get user", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Json(200, query.Result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GET /api/users/lookup
|
|
|
|
|
func GetUserByLoginOrEmail(c *middleware.Context) Response { |
|
|
|
|
query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")} |
|
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
|
if err == m.ErrUserNotFound { |
|
|
|
|
return ApiError(404, m.ErrUserNotFound.Error(), nil) |
|
|
|
|
} |
|
|
|
|
return ApiError(500, "Failed to get user", err) |
|
|
|
|
} |
|
|
|
|
user := query.Result |
|
|
|
|
result := m.UserProfileDTO{ |
|
|
|
|
Name: user.Name, |
|
|
|
|
Email: user.Email, |
|
|
|
|
Login: user.Login, |
|
|
|
|
Theme: user.Theme, |
|
|
|
|
IsGrafanaAdmin: user.IsAdmin, |
|
|
|
|
OrgId: user.OrgId, |
|
|
|
|
} |
|
|
|
|
return Json(200, &result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// POST /api/user
|
|
|
|
|
func UpdateSignedInUser(c *middleware.Context, cmd m.UpdateUserCommand) Response { |
|
|
|
|
if setting.AuthProxyEnabled { |
|
|
|
|
@ -60,7 +84,7 @@ func UpdateUserActiveOrg(c *middleware.Context) Response { |
|
|
|
|
cmd := m.SetUsingOrgCommand{UserId: userId, OrgId: orgId} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil { |
|
|
|
|
return ApiError(500, "Failed change active organization", err) |
|
|
|
|
return ApiError(500, "Failed to change active organization", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ApiSuccess("Active organization changed") |
|
|
|
|
@ -70,12 +94,12 @@ func handleUpdateUser(cmd m.UpdateUserCommand) Response { |
|
|
|
|
if len(cmd.Login) == 0 { |
|
|
|
|
cmd.Login = cmd.Email |
|
|
|
|
if len(cmd.Login) == 0 { |
|
|
|
|
return ApiError(400, "Validation error, need specify either username or email", nil) |
|
|
|
|
return ApiError(400, "Validation error, need to specify either username or email", nil) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil { |
|
|
|
|
return ApiError(500, "failed to update user", err) |
|
|
|
|
return ApiError(500, "Failed to update user", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ApiSuccess("User updated") |
|
|
|
|
@ -95,7 +119,7 @@ func getUserOrgList(userId int64) Response { |
|
|
|
|
query := m.GetUserOrgListQuery{UserId: userId} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
|
return ApiError(500, "Faile to get user organziations", err) |
|
|
|
|
return ApiError(500, "Failed to get user organizations", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Json(200, query.Result) |
|
|
|
|
@ -130,7 +154,7 @@ func UserSetUsingOrg(c *middleware.Context) Response { |
|
|
|
|
cmd := m.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgId} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil { |
|
|
|
|
return ApiError(500, "Failed change active organization", err) |
|
|
|
|
return ApiError(500, "Failed to change active organization", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ApiSuccess("Active organization changed") |
|
|
|
|
|