From df9a62b5f9fdfd4f8719761c52d09533288a3b3a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Apr 2023 01:27:46 +0900 Subject: [PATCH] Fix 404 error when leaving the last private org team (#24322) If the user only belongs to one org team and the org is private, leaving the org team will redirect to `ctx.Org.OrgLink + "/teams/"` which is inaccessible. So we need to check whether the user still belongs to the org. --- routers/web/org/teams.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index bae8e5a003..2ce4bf5322 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -86,9 +86,17 @@ func TeamsAction(ctx *context.Context) { return } } + + redirect := ctx.Org.OrgLink + "/teams/" + if isOrgMember, err := org_model.IsOrganizationMember(ctx, ctx.Org.Organization.ID, ctx.Doer.ID); err != nil { + ctx.ServerError("IsOrganizationMember", err) + return + } else if !isOrgMember { + redirect = setting.AppSubURL + "/" + } ctx.JSON(http.StatusOK, map[string]interface{}{ - "redirect": ctx.Org.OrgLink + "/teams/", + "redirect": redirect, }) return case "remove":