]> source.dussan.org Git - gitea.git/commitdiff
fix not respecting landing page setting (#4209)
authorDavid Schneiderbauer <daviian@users.noreply.github.com>
Fri, 15 Jun 2018 03:42:46 +0000 (05:42 +0200)
committerLunny Xiao <xiaolunwen@gmail.com>
Fri, 15 Jun 2018 03:42:46 +0000 (11:42 +0800)
* fix not respecting landing page setting

* fmt

* add landing page test

integrations/setting_test.go
modules/context/auth.go
routers/home.go

index a8d1f01e8f9c67bdc9f6f3bdaded85e24c2d5cdc..2aac8e90ede888f5dc342569c14c47232cd5f272 100644 (file)
@@ -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
+}
index 372bcb187aefe0415420ad5480be95cf28c5361d..c38cc3948d42c4ab003761a8dc5245154e607a33 100644 (file)
@@ -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 + "/")
index 5bb353c7e1765008adcefeab0a9dc763c3b89afd..0aa907658c51ecc94b2848f4876a3ca3c9a3d45c 100644 (file)
@@ -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.