Fix leaving organization bug on user settings -> orgs (#21983)

Fix #21772

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
花墨 2022-11-30 17:00:00 +08:00 committed by GitHub
parent fdfd77f478
commit 7020c4afb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View file

@ -107,13 +107,20 @@ func MembersAction(ctx *context.Context) {
}
case "leave":
err = models.RemoveOrgUser(org.ID, ctx.Doer.ID)
if organization.IsErrLastOrgOwner(err) {
if err == nil {
ctx.Flash.Success(ctx.Tr("form.organization_leave_success", org.DisplayName()))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": "", // keep the user stay on current page, in case they want to do other operations.
})
} else if organization.IsErrLastOrgOwner(err) {
ctx.Flash.Error(ctx.Tr("form.last_org_owner"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Org.OrgLink + "/members",
})
return
} else {
log.Error("RemoveOrgUser(%d,%d): %v", org.ID, ctx.Doer.ID, err)
}
return
}
if err != nil {