From f430050d244f8bbefc0726b786d49b70bf6a8234 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 15 Jan 2023 23:29:27 +0000 Subject: Fix leaving organization bug on user settings -> orgs (#21983) (#22438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backport #21983 Fix #21772 Co-authored-by: wxiaoguang Co-authored-by: 花墨 Co-authored-by: wxiaoguang Co-authored-by: Lunny Xiao Co-authored-by: KN4CK3R --- routers/web/org/members.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'routers') diff --git a/routers/web/org/members.go b/routers/web/org/members.go index ec5a98fc6a..6aeff57071 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -108,13 +108,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 { -- cgit v1.2.3