THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

fix not respecting landing page setting (#4209)

* fix not respecting landing page setting

* fmt

* add landing page test
tags/v1.5.0-dev
David Schneiderbauer 11 months ago
parent
commit
adba2ad609
3 changed files with 26 additions and 6 deletions
  1. 22
    0
      integrations/setting_test.go
  2. 0
    6
      modules/context/auth.go
  3. 4
    0
      routers/home.go

+ 22
- 0
integrations/setting_test.go View File

@@ -68,3 +68,25 @@ func TestSettingShowUserEmailProfile(t *testing.T) {
68 68
 
69 69
 	setting.UI.ShowUserEmail = showUserEmail
70 70
 }
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
+}

+ 0
- 6
modules/context/auth.go View File

@@ -37,12 +37,6 @@ func Toggle(options *ToggleOptions) macaron.Handler {
37 37
 			return
38 38
 		}
39 39
 
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
-
46 40
 		// Redirect to dashboard if user tries to visit any non-login page.
47 41
 		if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" {
48 42
 			ctx.Redirect(setting.AppSubURL + "/")

+ 4
- 0
routers/home.go View File

@@ -42,6 +42,10 @@ func Home(ctx *context.Context) {
42 42
 			user.Dashboard(ctx)
43 43
 		}
44 44
 		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
45 49
 	}
46 50
 
47 51
 	// Check auto-login.

Loading…
Cancel
Save