From f90406be988c0a4139463b66fbc13979a275c0f8 Mon Sep 17 00:00:00 2001 From: ShaneShek Date: Wed, 30 Nov 2022 11:00:49 +0800 Subject: [PATCH 1/3] fix leaving organization bug on user settings -> orgs --- options/locale/locale_en-US.ini | 1 + routers/web/org/members.go | 11 +++++++++-- templates/user/settings/organization.tmpl | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index eb2a1c86dbbf1..94f58e483338b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -501,6 +501,7 @@ team_not_exist = The team does not exist. last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization. cannot_add_org_to_team = An organization cannot be added as a team member. duplicate_invite_to_team = The user was already invited as a team member. +organization_leave_success=You have successfully left the organization %s. invalid_ssh_key = Can not verify your SSH key: %s invalid_gpg_key = Can not verify your GPG key: %s diff --git a/routers/web/org/members.go b/routers/web/org/members.go index ec5a98fc6a240..a2def2ae34406 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": "", + }) + } 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 { diff --git a/templates/user/settings/organization.tmpl b/templates/user/settings/organization.tmpl index e25d5e7fa6766..703ac8ad8edbe 100644 --- a/templates/user/settings/organization.tmpl +++ b/templates/user/settings/organization.tmpl @@ -17,9 +17,13 @@ {{range .Orgs}}
-
+ {{$.CsrfTokenHtml}} - +
{{avatar . 28 "mini"}} @@ -36,4 +40,14 @@
+ {{template "base/footer" .}} From 0cd204e7570b3dfb4ed1bcdb4232fc0eb21a82cd Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 30 Nov 2022 15:33:14 +0800 Subject: [PATCH 2/3] Update routers/web/org/members.go --- routers/web/org/members.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/org/members.go b/routers/web/org/members.go index a2def2ae34406..6aeff570710e2 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -111,7 +111,7 @@ func MembersAction(ctx *context.Context) { if err == nil { ctx.Flash.Success(ctx.Tr("form.organization_leave_success", org.DisplayName())) ctx.JSON(http.StatusOK, map[string]interface{}{ - "redirect": "", + "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")) From 90d63c85224bcbc63440546fb000e9ad5cefc736 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 30 Nov 2022 15:33:46 +0800 Subject: [PATCH 3/3] Update options/locale/locale_en-US.ini --- options/locale/locale_en-US.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 94f58e483338b..4d02edb6fe9a0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -501,7 +501,7 @@ team_not_exist = The team does not exist. last_org_owner = You cannot remove the last user from the 'owners' team. There must be at least one owner for an organization. cannot_add_org_to_team = An organization cannot be added as a team member. duplicate_invite_to_team = The user was already invited as a team member. -organization_leave_success=You have successfully left the organization %s. +organization_leave_success = You have successfully left the organization %s. invalid_ssh_key = Can not verify your SSH key: %s invalid_gpg_key = Can not verify your GPG key: %s