mirror of
https://github.com/grafana/grafana.git
synced 2026-08-11 05:34:53 -05:00
Authn: Prevent empty username and email during sync (#76330)
* Move errors to error file * Move check for both empty username and email to user service * Move check for empty email and username to user service Update * Wrap inner error * Set username in test
This commit is contained in:
@@ -57,13 +57,6 @@ func (hs *HTTPServer) AdminCreateUser(c *contextmodel.ReqContext) response.Respo
|
||||
OrgID: form.OrgId,
|
||||
}
|
||||
|
||||
if len(cmd.Login) == 0 {
|
||||
cmd.Login = cmd.Email
|
||||
if len(cmd.Login) == 0 {
|
||||
return response.Error(400, "Validation error, need specify either username or email", nil)
|
||||
}
|
||||
}
|
||||
|
||||
if len(cmd.Password) < 4 {
|
||||
return response.Error(400, "Password is missing or too short", nil)
|
||||
}
|
||||
@@ -78,7 +71,7 @@ func (hs *HTTPServer) AdminCreateUser(c *contextmodel.ReqContext) response.Respo
|
||||
return response.Error(http.StatusPreconditionFailed, fmt.Sprintf("User with email '%s' or username '%s' already exists", form.Email, form.Login), err)
|
||||
}
|
||||
|
||||
return response.Error(http.StatusInternalServerError, "failed to create user", err)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to create user", err)
|
||||
}
|
||||
|
||||
metrics.MApiAdminUserCreate.Inc()
|
||||
|
||||
+1
-8
@@ -221,18 +221,11 @@ func (hs *HTTPServer) handleUpdateUser(ctx context.Context, cmd user.UpdateUserC
|
||||
return response.Error(http.StatusForbidden, "User info cannot be updated for external Users", nil)
|
||||
}
|
||||
|
||||
if len(cmd.Login) == 0 {
|
||||
cmd.Login = cmd.Email
|
||||
if len(cmd.Login) == 0 {
|
||||
return response.Error(http.StatusBadRequest, "Validation error, need to specify either username or email", nil)
|
||||
}
|
||||
}
|
||||
|
||||
if err := hs.userService.Update(ctx, &cmd); err != nil {
|
||||
if errors.Is(err, user.ErrCaseInsensitive) {
|
||||
return response.Error(http.StatusConflict, "Update would result in user login conflict", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update user", err)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to update user", err)
|
||||
}
|
||||
|
||||
return response.Success("User updated")
|
||||
|
||||
Reference in New Issue
Block a user