Skip to content

Commit adba2ad

Browse files
daviianlunny
authored andcommitted
fix not respecting landing page setting (#4209)
* fix not respecting landing page setting * fmt * add landing page test
1 parent 6efdcae commit adba2ad

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

integrations/setting_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,25 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
6868

6969
setting.UI.ShowUserEmail = showUserEmail
7070
}
71+
72+
func TestSettingLandingPage(t *testing.T) {
73+
prepareTestEnv(t)
74+
75+
landingPage := setting.LandingPageURL
76+
77+
setting.LandingPageURL = setting.LandingPageHome
78+
req := NewRequest(t, "GET", "/")
79+
MakeRequest(t, req, http.StatusOK)
80+
81+
setting.LandingPageURL = setting.LandingPageExplore
82+
req = NewRequest(t, "GET", "/")
83+
resp := MakeRequest(t, req, http.StatusFound)
84+
assert.Equal(t, "/explore", resp.Header().Get("Location"))
85+
86+
setting.LandingPageURL = setting.LandingPageOrganizations
87+
req = NewRequest(t, "GET", "/")
88+
resp = MakeRequest(t, req, http.StatusFound)
89+
assert.Equal(t, "/explore/organizations", resp.Header().Get("Location"))
90+
91+
setting.LandingPageURL = landingPage
92+
}

modules/context/auth.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ func Toggle(options *ToggleOptions) macaron.Handler {
3737
return
3838
}
3939

40-
// Check non-logged users landing page.
41-
if !ctx.IsSigned && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LandingPageHome {
42-
ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
43-
return
44-
}
45-
4640
// Redirect to dashboard if user tries to visit any non-login page.
4741
if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" {
4842
ctx.Redirect(setting.AppSubURL + "/")

routers/home.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func Home(ctx *context.Context) {
4242
user.Dashboard(ctx)
4343
}
4444
return
45+
// Check non-logged users landing page.
46+
} else if setting.LandingPageURL != setting.LandingPageHome {
47+
ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
48+
return
4549
}
4650

4751
// Check auto-login.

0 commit comments

Comments
 (0)