From adba2ad609ca3f1612463a4ac6af22fd30b9e75f Mon Sep 17 00:00:00 2001 From: David Schneiderbauer Date: Fri, 15 Jun 2018 05:42:46 +0200 Subject: [PATCH] fix not respecting landing page setting (#4209) * fix not respecting landing page setting * fmt * add landing page test --- integrations/setting_test.go | 22 ++++++++++++++++++++++ modules/context/auth.go | 6 ------ routers/home.go | 4 ++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/integrations/setting_test.go b/integrations/setting_test.go index a8d1f01e8..2aac8e90e 100644 --- a/integrations/setting_test.go +++ b/integrations/setting_test.go @@ -68,3 +68,25 @@ func TestSettingShowUserEmailProfile(t *testing.T) { setting.UI.ShowUserEmail = showUserEmail } + +func TestSettingLandingPage(t *testing.T) { + prepareTestEnv(t) + + landingPage := setting.LandingPageURL + + setting.LandingPageURL = setting.LandingPageHome + req := NewRequest(t, "GET", "/") + MakeRequest(t, req, http.StatusOK) + + setting.LandingPageURL = setting.LandingPageExplore + req = NewRequest(t, "GET", "/") + resp := MakeRequest(t, req, http.StatusFound) + assert.Equal(t, "/explore", resp.Header().Get("Location")) + + setting.LandingPageURL = setting.LandingPageOrganizations + req = NewRequest(t, "GET", "/") + resp = MakeRequest(t, req, http.StatusFound) + assert.Equal(t, "/explore/organizations", resp.Header().Get("Location")) + + setting.LandingPageURL = landingPage +} diff --git a/modules/context/auth.go b/modules/context/auth.go index 372bcb187..c38cc3948 100644 --- a/modules/context/auth.go +++ b/modules/context/auth.go @@ -37,12 +37,6 @@ func Toggle(options *ToggleOptions) macaron.Handler { return } - // Check non-logged users landing page. - if !ctx.IsSigned && ctx.Req.RequestURI == "/" && setting.LandingPageURL != setting.LandingPageHome { - ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL)) - return - } - // Redirect to dashboard if user tries to visit any non-login page. if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" { ctx.Redirect(setting.AppSubURL + "/") diff --git a/routers/home.go b/routers/home.go index 5bb353c7e..0aa907658 100644 --- a/routers/home.go +++ b/routers/home.go @@ -42,6 +42,10 @@ func Home(ctx *context.Context) { user.Dashboard(ctx) } return + // Check non-logged users landing page. + } else if setting.LandingPageURL != setting.LandingPageHome { + ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL)) + return } // Check auto-login.