From 2fb3aadd732a1c876f1dc040d4dd9f92eb15ff06 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 7 Aug 2023 05:53:57 +0000 Subject: [PATCH 1/4] fix --- routers/web/org/teams.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 196d3e9bf0403..61ec167f5fa3d 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -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.JSON(http.StatusOK, map[string]any{"redirect": redirect}) return case "remove": if !ctx.Org.IsOwner { @@ -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.JSON(http.StatusOK, map[string]any{"redirect": redirect}) return case "add": if !ctx.Org.IsOwner { From 2c8a1975a065c0566612463d49dd9017dd549449 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 7 Aug 2023 15:55:10 +0900 Subject: [PATCH 2/4] Update routers/web/org/teams.go Co-authored-by: wxiaoguang --- routers/web/org/teams.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 61ec167f5fa3d..7cc8c0d9f8603 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -98,7 +98,7 @@ func TeamsAction(ctx *context.Context) { redirect = ctx.Org.Organization.HomeLink() } } - ctx.JSON(http.StatusOK, map[string]any{"redirect": redirect}) + ctx.JSONRedirect(redirect) return case "remove": if !ctx.Org.IsOwner { From 44ab186e9191dfae36164b7f2f567246168b0fab Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 7 Aug 2023 15:55:17 +0900 Subject: [PATCH 3/4] Update routers/web/org/teams.go Co-authored-by: wxiaoguang --- routers/web/org/teams.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 7cc8c0d9f8603..2af7721ad4a44 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -136,7 +136,7 @@ func TeamsAction(ctx *context.Context) { redirect = ctx.Org.Organization.HomeLink() } } - ctx.JSON(http.StatusOK, map[string]any{"redirect": redirect}) + ctx.JSONRedirect(redirect) return case "add": if !ctx.Org.IsOwner { From 3f874c5913600d699fed01c9b502b2f3a2eb75bf Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 8 Aug 2023 00:04:12 +0000 Subject: [PATCH 4/4] improve --- routers/web/org/teams.go | 41 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/routers/web/org/teams.go b/routers/web/org/teams.go index 2af7721ad4a44..3b07bba713a80 100644 --- a/routers/web/org/teams.go +++ b/routers/web/org/teams.go @@ -86,19 +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 { - if ctx.Org.Organization.Visibility.IsPrivate() { - redirect = setting.AppSubURL + "/" - } else { - redirect = ctx.Org.Organization.HomeLink() - } - } - ctx.JSONRedirect(redirect) + checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/") return case "remove": if !ctx.Org.IsOwner { @@ -125,18 +113,7 @@ func TeamsAction(ctx *context.Context) { return } } - 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) + checkIsOrgMemberAndRedirect(ctx, ctx.Org.OrgLink+"/teams/"+url.PathEscape(ctx.Org.Team.LowerName)) return case "add": if !ctx.Org.IsOwner { @@ -226,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 {