mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-04 01:10:49 +01:00
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.
This commit is contained in:
parent
b937adc54d
commit
9fc68b680f
1 changed files with 16 additions and 16 deletions
|
@ -86,18 +86,7 @@ func TeamsAction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/")
|
||||||
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,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
case "remove":
|
case "remove":
|
||||||
if !ctx.Org.IsOwner {
|
if !ctx.Org.IsOwner {
|
||||||
|
@ -124,10 +113,7 @@ func TeamsAction(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK,
|
checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/"+url.PathEscape(ctx.Org.Team.LowerName))
|
||||||
map[string]any{
|
|
||||||
"redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName),
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
case "add":
|
case "add":
|
||||||
if !ctx.Org.IsOwner {
|
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
|
// TeamsRepoAction operate team's repository
|
||||||
func TeamsRepoAction(ctx *context.Context) {
|
func TeamsRepoAction(ctx *context.Context) {
|
||||||
if !ctx.Org.IsOwner {
|
if !ctx.Org.IsOwner {
|
||||||
|
|
Loading…
Reference in a new issue