Chore: Delete password and search from models package (#62482)
* Chore: Delete password and search from models package * Rename model to AdminCreateUserResponse
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
@@ -83,9 +82,9 @@ func (hs *HTTPServer) AdminCreateUser(c *contextmodel.ReqContext) response.Respo
|
||||
|
||||
metrics.MApiAdminUserCreate.Inc()
|
||||
|
||||
result := models.UserIdDTO{
|
||||
result := user.AdminCreateUserResponse{
|
||||
Message: "User created",
|
||||
Id: usr.ID,
|
||||
ID: usr.ID,
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, result)
|
||||
@@ -506,7 +505,7 @@ type AdminUpdateUserPermissionsParams struct {
|
||||
// swagger:response adminCreateUserResponse
|
||||
type AdminCreateUserResponseResponse struct {
|
||||
// in:body
|
||||
Body models.UserIdDTO `json:"body"`
|
||||
Body user.AdminCreateUserResponse `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response adminGetUserAuthTokensResponse
|
||||
|
||||
+1
-2
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
@@ -83,7 +82,7 @@ func (hs *HTTPServer) ResetPassword(c *contextmodel.ReqContext) response.Respons
|
||||
return response.Error(400, "Passwords do not match", nil)
|
||||
}
|
||||
|
||||
password := models.Password(form.NewPassword)
|
||||
password := user.Password(form.NewPassword)
|
||||
if password.IsWeak() {
|
||||
return response.Error(400, "New password is too short", nil)
|
||||
}
|
||||
|
||||
+7
-8
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
@@ -72,7 +71,7 @@ func (hs *HTTPServer) getUserUserProfile(c *contextmodel.ReqContext, userID int6
|
||||
}
|
||||
|
||||
userProfile.AccessControl = hs.getAccessControlMetadata(c, c.OrgID, "global.users:id:", strconv.FormatInt(userID, 10))
|
||||
userProfile.AvatarUrl = dtos.GetGravatarUrl(userProfile.Email)
|
||||
userProfile.AvatarURL = dtos.GetGravatarUrl(userProfile.Email)
|
||||
|
||||
return response.JSON(http.StatusOK, userProfile)
|
||||
}
|
||||
@@ -429,12 +428,12 @@ func (hs *HTTPServer) ChangeUserPassword(c *contextmodel.ReqContext) response.Re
|
||||
|
||||
userQuery := user.GetUserByIDQuery{ID: c.UserID}
|
||||
|
||||
user, err := hs.userService.GetByID(c.Req.Context(), &userQuery)
|
||||
usr, err := hs.userService.GetByID(c.Req.Context(), &userQuery)
|
||||
if err != nil {
|
||||
return response.Error(500, "Could not read user from database", err)
|
||||
}
|
||||
|
||||
getAuthQuery := login.GetAuthInfoQuery{UserId: user.ID}
|
||||
getAuthQuery := login.GetAuthInfoQuery{UserId: usr.ID}
|
||||
if err := hs.authInfoService.GetAuthInfo(c.Req.Context(), &getAuthQuery); err == nil {
|
||||
authModule := getAuthQuery.Result.AuthModule
|
||||
if authModule == login.LDAPAuthModule || authModule == login.AuthProxyAuthModule {
|
||||
@@ -442,21 +441,21 @@ func (hs *HTTPServer) ChangeUserPassword(c *contextmodel.ReqContext) response.Re
|
||||
}
|
||||
}
|
||||
|
||||
passwordHashed, err := util.EncodePassword(cmd.OldPassword, user.Salt)
|
||||
passwordHashed, err := util.EncodePassword(cmd.OldPassword, usr.Salt)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to encode password", err)
|
||||
}
|
||||
if passwordHashed != user.Password {
|
||||
if passwordHashed != usr.Password {
|
||||
return response.Error(401, "Invalid old password", nil)
|
||||
}
|
||||
|
||||
password := models.Password(cmd.NewPassword)
|
||||
password := user.Password(cmd.NewPassword)
|
||||
if password.IsWeak() {
|
||||
return response.Error(400, "New password is too short", nil)
|
||||
}
|
||||
|
||||
cmd.UserID = c.UserID
|
||||
cmd.NewPassword, err = util.EncodePassword(cmd.NewPassword, user.Salt)
|
||||
cmd.NewPassword, err = util.EncodePassword(cmd.NewPassword, usr.Salt)
|
||||
if err != nil {
|
||||
return response.Error(500, "Failed to encode password", err)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
AuthLabels: []string{},
|
||||
CreatedAt: fakeNow,
|
||||
UpdatedAt: fakeNow,
|
||||
AvatarUrl: avatarUrl,
|
||||
AvatarURL: avatarUrl,
|
||||
}
|
||||
|
||||
var resp user.UserProfileDTO
|
||||
@@ -122,7 +122,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
resp.CreatedAt = fakeNow
|
||||
resp.UpdatedAt = fakeNow
|
||||
resp.AvatarUrl = avatarUrl
|
||||
resp.AvatarURL = avatarUrl
|
||||
require.EqualValues(t, expected, resp)
|
||||
}, mock)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user