mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Delete org model duplicates (#60940)
* Delete org model duplicates * Fix lint * Move OrgDetailsDTO to org pkg
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/auth"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
@@ -67,7 +68,7 @@ func (hs *HTTPServer) AdminCreateUser(c *models.ReqContext) response.Response {
|
||||
|
||||
usr, err := hs.userService.Create(c.Req.Context(), &cmd)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
return response.Error(400, err.Error(), nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
Password: testPassword,
|
||||
OrgId: nonExistingOrgID,
|
||||
}
|
||||
usrSvc := &usertest.FakeUserService{ExpectedError: models.ErrOrgNotFound}
|
||||
usrSvc := &usertest.FakeUserService{ExpectedError: org.ErrOrgNotFound}
|
||||
adminCreateUserScenario(t, "Should create the user", "/api/admin/users", "/api/admin/users", createCmd, usrSvc, func(sc *scenarioContext) {
|
||||
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
||||
assert.Equal(t, 400, sc.resp.Code)
|
||||
|
||||
@@ -64,16 +64,16 @@ func (hs *HTTPServer) GetOrgByID(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
|
||||
orga, err := hs.orgService.GetByName(c.Req.Context(), &org.GetOrgByNameQuery{Name: web.Params(c.Req)[":name"]})
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Organization not found", err)
|
||||
}
|
||||
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get organization", err)
|
||||
}
|
||||
result := models.OrgDetailsDTO{
|
||||
Id: orga.ID,
|
||||
result := org.OrgDetailsDTO{
|
||||
ID: orga.ID,
|
||||
Name: orga.Name,
|
||||
Address: models.Address{
|
||||
Address: org.Address{
|
||||
Address1: orga.Address1,
|
||||
Address2: orga.Address2,
|
||||
City: orga.City,
|
||||
@@ -87,21 +87,21 @@ func (hs *HTTPServer) GetOrgByName(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getOrgHelper(ctx context.Context, orgID int64) response.Response {
|
||||
query := org.GetOrgByIdQuery{ID: orgID}
|
||||
query := org.GetOrgByIDQuery{ID: orgID}
|
||||
|
||||
res, err := hs.orgService.GetByID(ctx, &query)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Organization not found", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to get organization", err)
|
||||
}
|
||||
|
||||
orga := res
|
||||
result := models.OrgDetailsDTO{
|
||||
Id: orga.ID,
|
||||
result := org.OrgDetailsDTO{
|
||||
ID: orga.ID,
|
||||
Name: orga.Name,
|
||||
Address: models.Address{
|
||||
Address: org.Address{
|
||||
Address1: orga.Address1,
|
||||
Address2: orga.Address2,
|
||||
City: orga.City,
|
||||
@@ -139,7 +139,7 @@ func (hs *HTTPServer) CreateOrg(c *models.ReqContext) response.Response {
|
||||
cmd.UserID = c.UserID
|
||||
result, err := hs.orgService.CreateWithMember(c.Req.Context(), &cmd)
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrOrgNameTaken) {
|
||||
if errors.Is(err, org.ErrOrgNameTaken) {
|
||||
return response.Error(http.StatusConflict, "Organization name taken", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to create organization", err)
|
||||
@@ -199,7 +199,7 @@ func (hs *HTTPServer) UpdateOrg(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) updateOrgHelper(ctx context.Context, form dtos.UpdateOrgForm, orgID int64) response.Response {
|
||||
cmd := org.UpdateOrgCommand{Name: form.Name, OrgId: orgID}
|
||||
if err := hs.orgService.UpdateOrg(ctx, &cmd); err != nil {
|
||||
if errors.Is(err, models.ErrOrgNameTaken) {
|
||||
if errors.Is(err, org.ErrOrgNameTaken) {
|
||||
return response.Error(http.StatusBadRequest, "Organization name taken", err)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update organization", err)
|
||||
@@ -293,7 +293,7 @@ func (hs *HTTPServer) DeleteOrgByID(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
if err := hs.orgService.Delete(c.Req.Context(), &org.DeleteOrgCommand{ID: orgID}); err != nil {
|
||||
if errors.Is(err, models.ErrOrgNotFound) {
|
||||
if errors.Is(err, org.ErrOrgNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Failed to delete organization. ID not found", nil)
|
||||
}
|
||||
return response.Error(http.StatusInternalServerError, "Failed to update organization", err)
|
||||
@@ -406,7 +406,7 @@ type GetOrgByNameParams struct {
|
||||
type CreateOrgParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.CreateOrgCommand `json:"body"`
|
||||
Body org.CreateOrgCommand `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters searchOrgs
|
||||
@@ -448,26 +448,26 @@ type CreateOrgResponse struct {
|
||||
type SearchOrgsResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body []*models.OrgDTO `json:"body"`
|
||||
Body []*org.OrgDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getCurrentOrgResponse
|
||||
type GetCurrentOrgResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body models.OrgDetailsDTO `json:"body"`
|
||||
Body org.OrgDetailsDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getOrgByIDResponse
|
||||
type GetOrgByIDResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body models.OrgDetailsDTO `json:"body"`
|
||||
Body org.OrgDetailsDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getOrgByNameResponse
|
||||
type GetOrgByNameResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body models.OrgDetailsDTO `json:"body"`
|
||||
Body org.OrgDetailsDTO `json:"body"`
|
||||
}
|
||||
|
||||
@@ -643,14 +643,14 @@ type UserResponse struct {
|
||||
type GetUserOrgListResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body []*models.UserOrgDTO `json:"body"`
|
||||
Body []*org.UserOrgDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getSignedInUserOrgListResponse
|
||||
type GetSignedInUserOrgListResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body []*models.UserOrgDTO `json:"body"`
|
||||
Body []*org.UserOrgDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getUserTeamsResponse
|
||||
|
||||
Reference in New Issue
Block a user