Skip to content

Commit

Permalink
Fix 404 error when remove self from an organization (#26362)
Browse files Browse the repository at this point in the history
Same to #24322 

Not only `leave` action but also `remove` action should check whether
user still belongs to the org.
  • Loading branch information
yp05327 authored Aug 12, 2023
1 parent b937adc commit 9fc68b6
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions routers/web/org/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9fc68b6

Please sign in to comment.