Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions routers/web/org/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ func TeamsAction(ctx *context.Context) {
ctx.ServerError("IsOrganizationMember", err)
return
} else if !isOrgMember {
redirect = setting.AppSubURL + "/"
if ctx.Org.Organization.Visibility.IsPrivate() {
redirect = setting.AppSubURL + "/"
} else {
redirect = ctx.Org.Organization.HomeLink()
}
}
ctx.JSON(http.StatusOK,
map[string]any{
"redirect": redirect,
})
ctx.JSONRedirect(redirect)
return
case "remove":
if !ctx.Org.IsOwner {
Expand All @@ -124,10 +125,18 @@ func TeamsAction(ctx *context.Context) {
return
}
}
ctx.JSON(http.StatusOK,
map[string]any{
"redirect": ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName),
})
redirect := ctx.Org.OrgLink + "/teams/" + url.PathEscape(ctx.Org.Team.LowerName)
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() {
redirect = setting.AppSubURL + "/"
} else {
redirect = ctx.Org.Organization.HomeLink()
}
}
ctx.JSONRedirect(redirect)
Copy link
Member

@delvh delvh Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about extracting this check into a separate method and giving it a parameter defaultRedirect?
You call it twice at the moment (90-101 and 128-139).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return
case "add":
if !ctx.Org.IsOwner {
Expand Down