@@ -86,18 +86,7 @@ func TeamsAction(ctx *context.Context) {
8686 return
8787 }
8888 }
89-
90- redirect := ctx .Org .OrgLink + "/teams/"
91- if isOrgMember , err := org_model .IsOrganizationMember (ctx , ctx .Org .Organization .ID , ctx .Doer .ID ); err != nil {
92- ctx .ServerError ("IsOrganizationMember" , err )
93- return
94- } else if ! isOrgMember {
95- redirect = setting .AppSubURL + "/"
96- }
97- ctx .JSON (http .StatusOK ,
98- map [string ]any {
99- "redirect" : redirect ,
100- })
89+ checkIsOrgMemberAndRedirect (ctx , ctx .Org .OrgLink + "/teams/" )
10190 return
10291 case "remove" :
10392 if ! ctx .Org .IsOwner {
@@ -124,10 +113,7 @@ func TeamsAction(ctx *context.Context) {
124113 return
125114 }
126115 }
127- ctx .JSON (http .StatusOK ,
128- map [string ]any {
129- "redirect" : ctx .Org .OrgLink + "/teams/" + url .PathEscape (ctx .Org .Team .LowerName ),
130- })
116+ checkIsOrgMemberAndRedirect (ctx , ctx .Org .OrgLink + "/teams/" + url .PathEscape (ctx .Org .Team .LowerName ))
131117 return
132118 case "add" :
133119 if ! ctx .Org .IsOwner {
@@ -217,6 +203,20 @@ func TeamsAction(ctx *context.Context) {
217203 }
218204}
219205
206+ func checkIsOrgMemberAndRedirect (ctx * context.Context , defaultRedirect string ) {
207+ if isOrgMember , err := org_model .IsOrganizationMember (ctx , ctx .Org .Organization .ID , ctx .Doer .ID ); err != nil {
208+ ctx .ServerError ("IsOrganizationMember" , err )
209+ return
210+ } else if ! isOrgMember {
211+ if ctx .Org .Organization .Visibility .IsPrivate () {
212+ defaultRedirect = setting .AppSubURL + "/"
213+ } else {
214+ defaultRedirect = ctx .Org .Organization .HomeLink ()
215+ }
216+ }
217+ ctx .JSONRedirect (defaultRedirect )
218+ }
219+
220220// TeamsRepoAction operate team's repository
221221func TeamsRepoAction (ctx * context.Context ) {
222222 if ! ctx .Org .IsOwner {
0 commit comments