aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-08-12 16:02:22 +0900
committerGitHub <noreply@github.com>2023-08-12 07:02:22 +0000
commit9fc68b680feb49071c6c348be7701f1c79f5181d (patch)
tree9bfa3796b6585e54d8f9a2f5665b6fc49963527c
parentb937adc54d35b00a9a888052c173b59b7ded8a0f (diff)
downloadgitea-9fc68b680feb49071c6c348be7701f1c79f5181d.tar.gz
gitea-9fc68b680feb49071c6c348be7701f1c79f5181d.zip
Fix 404 error when remove self from an organization (#26362)
Same to #24322 Not only `leave` action but also `remove` action should check whether user still belongs to the org.
-rw-r--r--routers/web/org/teams.go32
1 files changed, 16 insertions, 16 deletions
diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go
index 196d3e9bf0..3b07bba713 100644
--- a/routers/web/org/teams.go
+++ b/routers/web/org/teams.go
@@ -86,18 +86,7 @@ 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]any{
- "redirect": redirect,
- })
+ checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/")
return
case "remove":
if !ctx.Org.IsOwner {
@@ -124,10 +113,7 @@ func TeamsAction(ctx *context.Context) {
return
}
}
- ctx.JSON(http.StatusOK,
- map[string]any{
- "redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName),
- })
+ checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/"+url.PathEscape(ctx.Org.Team.LowerName))
return
case "add":
if !ctx.Org.IsOwner {
@@ -217,6 +203,20 @@ func TeamsAction(ctx *context.Context) {
}
}
+func checkIsOrgMemberAndRedirect(ctx *context.Context, defaultRedirect string) {
+ if isOrgMember, err := org_model.IsOrganizationMember(ctx, ctx.Org.Organization.ID, ctx.Doer.ID); err != nil {
+ ctx.ServerError("IsOrganizationMember", err)
+ return
+ } else if !isOrgMember {
+ if ctx.Org.Organization.Visibility.IsPrivate() {
+ defaultRedirect = setting.AppSubURL + "/"
+ } else {
+ defaultRedirect = ctx.Org.Organization.HomeLink()
+ }
+ }
+ ctx.JSONRedirect(defaultRedirect)
+}
+
// TeamsRepoAction operate team's repository
func TeamsRepoAction(ctx *context.Context) {
if !ctx.Org.IsOwner {