Make golint happier

This commit is contained in:
Julian Kornberger
2018-03-22 22:38:44 +01:00
parent 63465fd556
commit 0a415c50d0
44 changed files with 553 additions and 546 deletions
+33 -33
View File
@@ -23,12 +23,12 @@ func getUserUserProfile(userID int64) Response {
if err := bus.Dispatch(&query); err != nil {
if err == m.ErrUserNotFound {
return ApiError(404, m.ErrUserNotFound.Error(), nil)
return Error(404, m.ErrUserNotFound.Error(), nil)
}
return ApiError(500, "Failed to get user", err)
return Error(500, "Failed to get user", err)
}
return Json(200, query.Result)
return JSON(200, query.Result)
}
// GET /api/users/lookup
@@ -36,9 +36,9 @@ func GetUserByLoginOrEmail(c *m.ReqContext) 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 Error(404, m.ErrUserNotFound.Error(), nil)
}
return ApiError(500, "Failed to get user", err)
return Error(500, "Failed to get user", err)
}
user := query.Result
result := m.UserProfileDTO{
@@ -50,17 +50,17 @@ func GetUserByLoginOrEmail(c *m.ReqContext) Response {
IsGrafanaAdmin: user.IsAdmin,
OrgId: user.OrgId,
}
return Json(200, &result)
return JSON(200, &result)
}
// POST /api/user
func UpdateSignedInUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
if setting.AuthProxyEnabled {
if setting.AuthProxyHeaderProperty == "email" && cmd.Email != c.Email {
return ApiError(400, "Not allowed to change email when auth proxy is using email property", nil)
return Error(400, "Not allowed to change email when auth proxy is using email property", nil)
}
if setting.AuthProxyHeaderProperty == "username" && cmd.Login != c.Login {
return ApiError(400, "Not allowed to change username when auth proxy is using username property", nil)
return Error(400, "Not allowed to change username when auth proxy is using username property", nil)
}
}
cmd.UserId = c.UserId
@@ -79,31 +79,31 @@ func UpdateUserActiveOrg(c *m.ReqContext) Response {
orgID := c.ParamsInt64(":orgId")
if !validateUsingOrg(userID, orgID) {
return ApiError(401, "Not a valid organization", nil)
return Error(401, "Not a valid organization", nil)
}
cmd := m.SetUsingOrgCommand{UserId: userID, OrgId: orgID}
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to change active organization", err)
return Error(500, "Failed to change active organization", err)
}
return ApiSuccess("Active organization changed")
return Success("Active organization changed")
}
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 to specify either username or email", nil)
return Error(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 Error(500, "Failed to update user", err)
}
return ApiSuccess("User updated")
return Success("User updated")
}
// GET /api/user/orgs
@@ -120,10 +120,10 @@ func getUserOrgList(userID int64) Response {
query := m.GetUserOrgListQuery{UserId: userID}
if err := bus.Dispatch(&query); err != nil {
return ApiError(500, "Failed to get user organizations", err)
return Error(500, "Failed to get user organizations", err)
}
return Json(200, query.Result)
return JSON(200, query.Result)
}
func validateUsingOrg(userID int64, orgID int64) bool {
@@ -149,16 +149,16 @@ func UserSetUsingOrg(c *m.ReqContext) Response {
orgID := c.ParamsInt64(":id")
if !validateUsingOrg(c.UserId, orgID) {
return ApiError(401, "Not a valid organization", nil)
return Error(401, "Not a valid organization", nil)
}
cmd := m.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID}
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to change active organization", err)
return Error(500, "Failed to change active organization", err)
}
return ApiSuccess("Active organization changed")
return Success("Active organization changed")
}
// GET /profile/switch-org/:id
@@ -180,53 +180,53 @@ func ChangeActiveOrgAndRedirectToHome(c *m.ReqContext) {
func ChangeUserPassword(c *m.ReqContext, cmd m.ChangeUserPasswordCommand) Response {
if setting.LdapEnabled || setting.AuthProxyEnabled {
return ApiError(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
return Error(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
}
userQuery := m.GetUserByIdQuery{Id: c.UserId}
if err := bus.Dispatch(&userQuery); err != nil {
return ApiError(500, "Could not read user from database", err)
return Error(500, "Could not read user from database", err)
}
passwordHashed := util.EncodePassword(cmd.OldPassword, userQuery.Result.Salt)
if passwordHashed != userQuery.Result.Password {
return ApiError(401, "Invalid old password", nil)
return Error(401, "Invalid old password", nil)
}
password := m.Password(cmd.NewPassword)
if password.IsWeak() {
return ApiError(400, "New password is too short", nil)
return Error(400, "New password is too short", nil)
}
cmd.UserId = c.UserId
cmd.NewPassword = util.EncodePassword(cmd.NewPassword, userQuery.Result.Salt)
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to change user password", err)
return Error(500, "Failed to change user password", err)
}
return ApiSuccess("User password changed")
return Success("User password changed")
}
// GET /api/users
func SearchUsers(c *m.ReqContext) Response {
query, err := searchUser(c)
if err != nil {
return ApiError(500, "Failed to fetch users", err)
return Error(500, "Failed to fetch users", err)
}
return Json(200, query.Result.Users)
return JSON(200, query.Result.Users)
}
// GET /api/users/search
func SearchUsersWithPaging(c *m.ReqContext) Response {
query, err := searchUser(c)
if err != nil {
return ApiError(500, "Failed to fetch users", err)
return Error(500, "Failed to fetch users", err)
}
return Json(200, query.Result)
return JSON(200, query.Result)
}
func searchUser(c *m.ReqContext) (*m.SearchUsersQuery, error) {
@@ -269,10 +269,10 @@ func SetHelpFlag(c *m.ReqContext) Response {
}
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to update help flag", err)
return Error(500, "Failed to update help flag", err)
}
return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
return JSON(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
}
func ClearHelpFlags(c *m.ReqContext) Response {
@@ -282,8 +282,8 @@ func ClearHelpFlags(c *m.ReqContext) Response {
}
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to update help flag", err)
return Error(500, "Failed to update help flag", err)
}
return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
return JSON(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
}