Chore: Delete duplicate models for user (#60906)

* Delete duplicate models for user

* Use new models in some tests

* Add auth model conversion back
This commit is contained in:
idafurjes
2023-01-03 15:25:35 +01:00
committed by GitHub
parent 355f513718
commit 325f7a789e
7 changed files with 24 additions and 175 deletions
+8 -8
View File
@@ -94,14 +94,14 @@ func (hs *HTTPServer) GetUserByLoginOrEmail(c *models.ReqContext) response.Respo
}
return response.Error(500, "Failed to get user", err)
}
result := models.UserProfileDTO{
Id: usr.ID,
result := user.UserProfileDTO{
ID: usr.ID,
Name: usr.Name,
Email: usr.Email,
Login: usr.Login,
Theme: usr.Theme,
IsGrafanaAdmin: usr.IsAdmin,
OrgId: usr.OrgID,
OrgID: usr.OrgID,
UpdatedAt: usr.Updated,
CreatedAt: usr.Created,
}
@@ -560,7 +560,7 @@ type UpdateSignedInUserParams struct {
// To change the email, name, login, theme, provide another one.
// in:body
// required:true
Body models.UpdateUserCommand `json:"body"`
Body user.UpdateUserCommand `json:"body"`
}
// swagger:parameters userSetUsingOrg
@@ -582,7 +582,7 @@ type ChangeUserPasswordParams struct {
// To change the email, name, login, theme, provide another one.
// in:body
// required:true
Body models.ChangeUserPasswordCommand `json:"body"`
Body user.ChangeUserPasswordCommand `json:"body"`
}
// swagger:parameters getUserByID
@@ -619,7 +619,7 @@ type UpdateUserParams struct {
// To change the email, name, login, theme, provide another one.
// in:body
// required:true
Body models.UpdateUserCommand `json:"body"`
Body user.UpdateUserCommand `json:"body"`
// in:path
// required:true
UserID int64 `json:"user_id"`
@@ -629,14 +629,14 @@ type UpdateUserParams struct {
type SearchUsersResponse struct {
// The response message
// in: body
Body models.SearchUserQueryResult `json:"body"`
Body user.SearchUserQueryResult `json:"body"`
}
// swagger:response userResponse
type UserResponse struct {
// The response message
// in: body
Body models.UserProfileDTO `json:"body"`
Body user.UserProfileDTO `json:"body"`
}
// swagger:response getUserOrgListResponse
+8 -8
View File
@@ -76,7 +76,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
Login: "loginuser",
IsAdmin: true,
}
user, err := userSvc.CreateUserForTests(context.Background(), &createUserCmd)
usr, err := userSvc.CreateUserForTests(context.Background(), &createUserCmd)
require.NoError(t, err)
sc.handlerFunc = hs.GetUserByID
@@ -92,7 +92,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
login := "loginuser"
query := &models.GetUserByAuthInfoQuery{AuthModule: "test", AuthId: "test", UserLookupParams: models.UserLookupParams{Login: &login}}
cmd := &models.UpdateAuthInfoCommand{
UserId: user.ID,
UserId: usr.ID,
AuthId: query.AuthId,
AuthModule: query.AuthModule,
OAuthToken: token,
@@ -100,14 +100,14 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
err = srv.UpdateAuthInfo(context.Background(), cmd)
require.NoError(t, err)
avatarUrl := dtos.GetGravatarUrl("@test.com")
sc.fakeReqWithParams("GET", sc.url, map[string]string{"id": fmt.Sprintf("%v", user.ID)}).exec()
sc.fakeReqWithParams("GET", sc.url, map[string]string{"id": fmt.Sprintf("%v", usr.ID)}).exec()
expected := models.UserProfileDTO{
Id: 1,
expected := user.UserProfileDTO{
ID: 1,
Email: "user@test.com",
Name: "user",
Login: "loginuser",
OrgId: 1,
OrgID: 1,
IsGrafanaAdmin: true,
AuthLabels: []string{},
CreatedAt: fakeNow,
@@ -115,7 +115,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
AvatarUrl: avatarUrl,
}
var resp models.UserProfileDTO
var resp user.UserProfileDTO
require.Equal(t, http.StatusOK, sc.resp.Code)
err = json.Unmarshal(sc.resp.Body.Bytes(), &resp)
require.NoError(t, err)
@@ -147,7 +147,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
hs.userService = userMock
sc.fakeReqWithParams("GET", sc.url, map[string]string{"loginOrEmail": "admin@test.com"}).exec()
var resp models.UserProfileDTO
var resp user.UserProfileDTO
require.Equal(t, http.StatusOK, sc.resp.Code)
err = json.Unmarshal(sc.resp.Body.Bytes(), &resp)
require.NoError(t, err)