| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 	"errors" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 14:17:35 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/dtos" | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/response" | 
					
						
							| 
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/bus" | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/models" | 
					
						
							| 
									
										
										
										
											2020-09-14 14:58:23 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/util" | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | // POST /api/org/users
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func AddOrgUserToCurrentOrg(c *models.ReqContext, cmd models.AddOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 	cmd.OrgId = c.OrgId | 
					
						
							|  |  |  | 	return addOrgUserHelper(cmd) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // POST /api/orgs/:orgId/users
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func AddOrgUser(c *models.ReqContext, cmd models.AddOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 	cmd.OrgId = c.ParamsInt64(":orgId") | 
					
						
							|  |  |  | 	return addOrgUserHelper(cmd) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func addOrgUserHelper(cmd models.AddOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	if !cmd.Role.IsValid() { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(400, "Invalid role specified", nil) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	userQuery := models.GetUserByLoginQuery{LoginOrEmail: cmd.LoginOrEmail} | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	err := bus.Dispatch(&userQuery) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(404, "User not found", nil) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	userToAdd := userQuery.Result | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cmd.UserId = userToAdd.Id | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&cmd); err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 		if errors.Is(err, models.ErrOrgUserAlreadyAdded) { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.JSON(409, util.DynMap{ | 
					
						
							| 
									
										
										
										
											2020-09-14 14:58:23 +08:00
										 |  |  | 				"message": "User is already member of this organization", | 
					
						
							|  |  |  | 				"userId":  cmd.UserId, | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2016-11-23 21:38:44 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Could not add user to organization", err) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.JSON(200, util.DynMap{ | 
					
						
							| 
									
										
										
										
											2020-09-14 14:58:23 +08:00
										 |  |  | 		"message": "User added to organization", | 
					
						
							|  |  |  | 		"userId":  cmd.UserId, | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GET /api/org/users
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func (hs *HTTPServer) GetOrgUsersForCurrentOrg(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 	result, err := hs.getOrgUsersHelper(&models.GetOrgUsersQuery{ | 
					
						
							|  |  |  | 		OrgId: c.OrgId, | 
					
						
							|  |  |  | 		Query: c.Query("query"), | 
					
						
							|  |  |  | 		Limit: c.QueryInt("limit"), | 
					
						
							|  |  |  | 	}, c.SignedInUser) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to get users for current organization", err) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.JSON(200, result) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GET /api/org/users/lookup
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func (hs *HTTPServer) GetOrgUsersForCurrentOrgLookup(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	isAdmin, err := isOrgAdminFolderAdminOrTeamAdmin(c) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to get users for current organization", err) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !isAdmin { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(403, "Permission denied", nil) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 	orgUsers, err := hs.getOrgUsersHelper(&models.GetOrgUsersQuery{ | 
					
						
							|  |  |  | 		OrgId: c.OrgId, | 
					
						
							|  |  |  | 		Query: c.Query("query"), | 
					
						
							|  |  |  | 		Limit: c.QueryInt("limit"), | 
					
						
							|  |  |  | 	}, c.SignedInUser) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to get users for current organization", err) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result := make([]*dtos.UserLookupDTO, 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, u := range orgUsers { | 
					
						
							|  |  |  | 		result = append(result, &dtos.UserLookupDTO{ | 
					
						
							|  |  |  | 			UserID:    u.UserId, | 
					
						
							|  |  |  | 			Login:     u.Login, | 
					
						
							|  |  |  | 			AvatarURL: u.AvatarUrl, | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.JSON(200, result) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func isOrgAdminFolderAdminOrTeamAdmin(c *models.ReqContext) (bool, error) { | 
					
						
							|  |  |  | 	if c.OrgRole == models.ROLE_ADMIN { | 
					
						
							|  |  |  | 		return true, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hasAdminPermissionInFoldersQuery := models.HasAdminPermissionInFoldersQuery{SignedInUser: c.SignedInUser} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&hasAdminPermissionInFoldersQuery); err != nil { | 
					
						
							|  |  |  | 		return false, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if hasAdminPermissionInFoldersQuery.Result { | 
					
						
							|  |  |  | 		return true, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	isAdminOfTeamsQuery := models.IsAdminOfTeamsQuery{SignedInUser: c.SignedInUser} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&isAdminOfTeamsQuery); err != nil { | 
					
						
							|  |  |  | 		return false, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return isAdminOfTeamsQuery.Result, nil | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // GET /api/orgs/:orgId/users
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func (hs *HTTPServer) GetOrgUsers(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 	result, err := hs.getOrgUsersHelper(&models.GetOrgUsersQuery{ | 
					
						
							|  |  |  | 		OrgId: c.ParamsInt64(":orgId"), | 
					
						
							|  |  |  | 		Query: "", | 
					
						
							|  |  |  | 		Limit: 0, | 
					
						
							|  |  |  | 	}, c.SignedInUser) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to get users for organization", err) | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.JSON(200, result) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | func (hs *HTTPServer) getOrgUsersHelper(query *models.GetOrgUsersQuery, signedInUser *models.SignedInUser) ([]*models.OrgUserDTO, error) { | 
					
						
							|  |  |  | 	if err := bus.Dispatch(query); err != nil { | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 		return nil, err | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 	filteredUsers := make([]*models.OrgUserDTO, 0, len(query.Result)) | 
					
						
							|  |  |  | 	for _, user := range query.Result { | 
					
						
							|  |  |  | 		if dtos.IsHiddenUser(user.Login, signedInUser, hs.Cfg) { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-18 14:17:35 +08:00
										 |  |  | 		user.AvatarUrl = dtos.GetGravatarUrl(user.Email) | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		filteredUsers = append(filteredUsers, user) | 
					
						
							| 
									
										
										
										
											2017-08-18 14:17:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-24 19:10:32 +08:00
										 |  |  | 	return filteredUsers, nil | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 20:10:35 +08:00
										 |  |  | // SearchOrgUsersWithPaging is an HTTP handler to search for org users with paging.
 | 
					
						
							|  |  |  | // GET /api/org/users/search
 | 
					
						
							|  |  |  | func (hs *HTTPServer) SearchOrgUsersWithPaging(c *models.ReqContext) response.Response { | 
					
						
							|  |  |  | 	perPage := c.QueryInt("perpage") | 
					
						
							|  |  |  | 	if perPage <= 0 { | 
					
						
							|  |  |  | 		perPage = 1000 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	page := c.QueryInt("page") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if page < 1 { | 
					
						
							|  |  |  | 		page = 1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	query := &models.SearchOrgUsersQuery{ | 
					
						
							|  |  |  | 		OrgID: c.OrgId, | 
					
						
							|  |  |  | 		Query: c.Query("query"), | 
					
						
							|  |  |  | 		Limit: perPage, | 
					
						
							|  |  |  | 		Page:  page, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err := hs.SQLStore.SearchOrgUsers(query); err != nil { | 
					
						
							|  |  |  | 		return response.Error(500, "Failed to get users for current organization", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	filteredUsers := make([]*models.OrgUserDTO, 0, len(query.Result.OrgUsers)) | 
					
						
							|  |  |  | 	for _, user := range query.Result.OrgUsers { | 
					
						
							|  |  |  | 		if dtos.IsHiddenUser(user.Login, c.SignedInUser, hs.Cfg) { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		user.AvatarUrl = dtos.GetGravatarUrl(user.Email) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		filteredUsers = append(filteredUsers, user) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	query.Result.OrgUsers = filteredUsers | 
					
						
							|  |  |  | 	query.Result.Page = page | 
					
						
							|  |  |  | 	query.Result.PerPage = perPage | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return response.JSON(200, query.Result) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | // PATCH /api/org/users/:userId
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func UpdateOrgUserForCurrentOrg(c *models.ReqContext, cmd models.UpdateOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 	cmd.OrgId = c.OrgId | 
					
						
							|  |  |  | 	cmd.UserId = c.ParamsInt64(":userId") | 
					
						
							|  |  |  | 	return updateOrgUserHelper(cmd) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // PATCH /api/orgs/:orgId/users/:userId
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func UpdateOrgUser(c *models.ReqContext, cmd models.UpdateOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | 	cmd.OrgId = c.ParamsInt64(":orgId") | 
					
						
							|  |  |  | 	cmd.UserId = c.ParamsInt64(":userId") | 
					
						
							|  |  |  | 	return updateOrgUserHelper(cmd) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func updateOrgUserHelper(cmd models.UpdateOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2015-05-01 15:48:07 +08:00
										 |  |  | 	if !cmd.Role.IsValid() { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(400, "Invalid role specified", nil) | 
					
						
							| 
									
										
										
										
											2015-05-01 15:48:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if err := bus.Dispatch(&cmd); err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 		if errors.Is(err, models.ErrLastOrgAdmin) { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(400, "Cannot change role so that there is no organization admin left", nil) | 
					
						
							| 
									
										
										
										
											2015-05-19 17:47:14 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed update org user", err) | 
					
						
							| 
									
										
										
										
											2015-05-01 15:48:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.Success("Organization user updated") | 
					
						
							| 
									
										
										
										
											2015-05-01 15:48:07 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | // DELETE /api/org/users/:userId
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func RemoveOrgUserForCurrentOrg(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	return removeOrgUserHelper(&models.RemoveOrgUserCommand{ | 
					
						
							| 
									
										
										
										
											2018-10-12 03:26:06 +08:00
										 |  |  | 		UserId:                   c.ParamsInt64(":userId"), | 
					
						
							|  |  |  | 		OrgId:                    c.OrgId, | 
					
						
							| 
									
										
										
										
											2018-10-11 13:48:35 +08:00
										 |  |  | 		ShouldDeleteOrphanedUser: true, | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // DELETE /api/orgs/:orgId/users/:userId
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func RemoveOrgUser(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2019-08-13 02:03:48 +08:00
										 |  |  | 	return removeOrgUserHelper(&models.RemoveOrgUserCommand{ | 
					
						
							| 
									
										
										
										
											2018-10-11 13:48:35 +08:00
										 |  |  | 		UserId: c.ParamsInt64(":userId"), | 
					
						
							|  |  |  | 		OrgId:  c.ParamsInt64(":orgId"), | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2015-05-19 16:16:32 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func removeOrgUserHelper(cmd *models.RemoveOrgUserCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2018-10-11 13:48:35 +08:00
										 |  |  | 	if err := bus.Dispatch(cmd); err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 		if errors.Is(err, models.ErrLastOrgAdmin) { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(400, "Cannot remove last organization admin", nil) | 
					
						
							| 
									
										
										
										
											2015-01-20 22:48:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to remove user from organization", err) | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 03:20:53 +08:00
										 |  |  | 	if cmd.UserWasDeleted { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Success("User deleted") | 
					
						
							| 
									
										
										
										
											2018-10-11 13:58:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.Success("User removed from organization") | 
					
						
							| 
									
										
										
										
											2015-01-20 01:01:04 +08:00
										 |  |  | } |