mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove org model duplicates (#61025)
Remove org model duplicates
This commit is contained in:
@@ -348,7 +348,7 @@ type UpdateCurrentOrgAddressParams struct {
|
||||
type UpdateCurrentOrgUserParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.UpdateOrgUserCommand `json:"body"`
|
||||
Body org.UpdateOrgUserCommand `json:"body"`
|
||||
// in:path
|
||||
// required:true
|
||||
UserID int64 `json:"user_id"`
|
||||
|
||||
@@ -148,7 +148,7 @@ func (hs *HTTPServer) inviteExistingUserToOrg(c *models.ReqContext, user *user.U
|
||||
// user exists, add org role
|
||||
createOrgUserCmd := org.AddOrgUserCommand{OrgID: c.OrgID, UserID: user.ID, Role: inviteDto.Role}
|
||||
if err := hs.orgService.AddOrgUser(c.Req.Context(), &createOrgUserCmd); err != nil {
|
||||
if errors.Is(err, models.ErrOrgUserAlreadyAdded) {
|
||||
if errors.Is(err, org.ErrOrgUserAlreadyAdded) {
|
||||
return response.Error(412, fmt.Sprintf("User %s is already added to organization", inviteDto.LoginOrEmail), err)
|
||||
}
|
||||
return response.Error(500, "Error while trying to create org user", err)
|
||||
@@ -312,7 +312,7 @@ func (hs *HTTPServer) applyUserInvite(ctx context.Context, usr *user.User, invit
|
||||
// add to org
|
||||
addOrgUserCmd := org.AddOrgUserCommand{OrgID: invite.OrgID, UserID: usr.ID, Role: invite.Role}
|
||||
if err := hs.orgService.AddOrgUser(ctx, &addOrgUserCmd); err != nil {
|
||||
if !errors.Is(err, models.ErrOrgUserAlreadyAdded) {
|
||||
if !errors.Is(err, org.ErrOrgUserAlreadyAdded) {
|
||||
return false, response.Error(500, "Error while trying to create org user", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (hs *HTTPServer) addOrgUserHelper(c *models.ReqContext, cmd org.AddOrgUserC
|
||||
cmd.UserID = userToAdd.ID
|
||||
|
||||
if err := hs.orgService.AddOrgUser(c.Req.Context(), &cmd); err != nil {
|
||||
if errors.Is(err, models.ErrOrgUserAlreadyAdded) {
|
||||
if errors.Is(err, org.ErrOrgUserAlreadyAdded) {
|
||||
return response.JSON(409, util.DynMap{
|
||||
"message": "User is already member of this organization",
|
||||
"userId": cmd.UserID,
|
||||
@@ -387,7 +387,7 @@ func (hs *HTTPServer) updateOrgUserHelper(c *models.ReqContext, cmd org.UpdateOr
|
||||
return response.Error(http.StatusForbidden, "Cannot assign a role higher than user's role", nil)
|
||||
}
|
||||
if err := hs.orgService.UpdateOrgUser(c.Req.Context(), &cmd); err != nil {
|
||||
if errors.Is(err, models.ErrLastOrgAdmin) {
|
||||
if errors.Is(err, org.ErrLastOrgAdmin) {
|
||||
return response.Error(400, "Cannot change role so that there is no organization admin left", nil)
|
||||
}
|
||||
return response.Error(500, "Failed update org user", err)
|
||||
@@ -452,7 +452,7 @@ func (hs *HTTPServer) RemoveOrgUser(c *models.ReqContext) response.Response {
|
||||
|
||||
func (hs *HTTPServer) removeOrgUserHelper(ctx context.Context, cmd *org.RemoveOrgUserCommand) response.Response {
|
||||
if err := hs.orgService.RemoveOrgUser(ctx, cmd); err != nil {
|
||||
if errors.Is(err, models.ErrLastOrgAdmin) {
|
||||
if errors.Is(err, org.ErrLastOrgAdmin) {
|
||||
return response.Error(400, "Cannot remove last organization admin", nil)
|
||||
}
|
||||
return response.Error(500, "Failed to remove user from organization", err)
|
||||
@@ -478,14 +478,14 @@ func (hs *HTTPServer) removeOrgUserHelper(ctx context.Context, cmd *org.RemoveOr
|
||||
type AddOrgUserToCurrentOrgParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.AddOrgUserCommand `json:"body"`
|
||||
Body org.AddOrgUserCommand `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters addOrgUser
|
||||
type AddOrgUserParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.AddOrgUserCommand `json:"body"`
|
||||
Body org.AddOrgUserCommand `json:"body"`
|
||||
// in:path
|
||||
// required:true
|
||||
OrgID int64 `json:"org_id"`
|
||||
@@ -512,7 +512,7 @@ type GetOrgUsersParams struct {
|
||||
type UpdateOrgUserForCurrentOrgParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.UpdateOrgUserCommand `json:"body"`
|
||||
Body org.UpdateOrgUserCommand `json:"body"`
|
||||
// in:path
|
||||
// required:true
|
||||
UserID int64 `json:"user_id"`
|
||||
@@ -522,7 +522,7 @@ type UpdateOrgUserForCurrentOrgParams struct {
|
||||
type UpdateOrgUserParams struct {
|
||||
// in:body
|
||||
// required:true
|
||||
Body models.UpdateOrgUserCommand `json:"body"`
|
||||
Body org.UpdateOrgUserCommand `json:"body"`
|
||||
// in:path
|
||||
// required:true
|
||||
OrgID int64 `json:"org_id"`
|
||||
@@ -559,12 +559,12 @@ type GetOrgUsersForCurrentOrgLookupResponse struct {
|
||||
type GetOrgUsersForCurrentOrgResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body []*models.OrgUserDTO `json:"body"`
|
||||
Body []*org.OrgUserDTO `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:response getOrgUsersResponse
|
||||
type GetOrgUsersResponse struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body []*models.OrgUserDTO `json:"body"`
|
||||
Body []*org.OrgUserDTO `json:"body"`
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestOrgUsersAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
require.Equal(t, http.StatusOK, sc.resp.Code)
|
||||
|
||||
var resp []models.OrgUserDTO
|
||||
var resp []org.OrgUserDTO
|
||||
err := json.Unmarshal(sc.resp.Body.Bytes(), &resp)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, resp, 3)
|
||||
@@ -169,7 +169,7 @@ func TestOrgUsersAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
require.Equal(t, http.StatusOK, sc.resp.Code)
|
||||
|
||||
var resp []models.OrgUserDTO
|
||||
var resp []org.OrgUserDTO
|
||||
err := json.Unmarshal(sc.resp.Body.Bytes(), &resp)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, resp, 2)
|
||||
@@ -425,7 +425,7 @@ func TestGetOrgUsersAPIEndpoint_AccessControlMetadata(t *testing.T) {
|
||||
response := callAPI(sc.server, http.MethodGet, fmt.Sprintf(url, tc.targetOrg), nil, t)
|
||||
require.Equal(t, tc.expectedCode, response.Code)
|
||||
|
||||
var userList []*models.OrgUserDTO
|
||||
var userList []*org.OrgUserDTO
|
||||
err = json.NewDecoder(response.Body).Decode(&userList)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -533,7 +533,7 @@ func TestGetOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
require.Equal(t, tc.expectedCode, response.Code)
|
||||
|
||||
if tc.expectedCode != http.StatusForbidden {
|
||||
var userList []*models.OrgUserDTO
|
||||
var userList []*org.OrgUserDTO
|
||||
err := json.NewDecoder(response.Body).Decode(&userList)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user