Merge pull request #13611 from grafana/remove-user-from-org-and-system
Remove user form org in single org setup improvement
This commit is contained in:
+15
-9
@@ -102,26 +102,32 @@ func updateOrgUserHelper(cmd m.UpdateOrgUserCommand) Response {
|
||||
|
||||
// DELETE /api/org/users/:userId
|
||||
func RemoveOrgUserForCurrentOrg(c *m.ReqContext) Response {
|
||||
userID := c.ParamsInt64(":userId")
|
||||
return removeOrgUserHelper(c.OrgId, userID)
|
||||
return removeOrgUserHelper(&m.RemoveOrgUserCommand{
|
||||
UserId: c.ParamsInt64(":userId"),
|
||||
OrgId: c.OrgId,
|
||||
ShouldDeleteOrphanedUser: true,
|
||||
})
|
||||
}
|
||||
|
||||
// DELETE /api/orgs/:orgId/users/:userId
|
||||
func RemoveOrgUser(c *m.ReqContext) Response {
|
||||
userID := c.ParamsInt64(":userId")
|
||||
orgID := c.ParamsInt64(":orgId")
|
||||
return removeOrgUserHelper(orgID, userID)
|
||||
return removeOrgUserHelper(&m.RemoveOrgUserCommand{
|
||||
UserId: c.ParamsInt64(":userId"),
|
||||
OrgId: c.ParamsInt64(":orgId"),
|
||||
})
|
||||
}
|
||||
|
||||
func removeOrgUserHelper(orgID int64, userID int64) Response {
|
||||
cmd := m.RemoveOrgUserCommand{OrgId: orgID, UserId: userID}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
func removeOrgUserHelper(cmd *m.RemoveOrgUserCommand) Response {
|
||||
if err := bus.Dispatch(cmd); err != nil {
|
||||
if err == m.ErrLastOrgAdmin {
|
||||
return Error(400, "Cannot remove last organization admin", nil)
|
||||
}
|
||||
return Error(500, "Failed to remove user from organization", err)
|
||||
}
|
||||
|
||||
if cmd.UserWasDeleted {
|
||||
return Success("User deleted")
|
||||
}
|
||||
|
||||
return Success("User removed from organization")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user