fix not respecting landing page setting (#4209)
* fix not respecting landing page setting * fmt * add landing page test
This commit is contained in:
		
							parent
							
								
									6efdcaed86
								
							
						
					
					
						commit
						adba2ad609
					
				
					 3 changed files with 26 additions and 6 deletions
				
			
		|  | @ -68,3 +68,25 @@ func TestSettingShowUserEmailProfile(t *testing.T) { | ||||||
| 
 | 
 | ||||||
| 	setting.UI.ShowUserEmail = showUserEmail | 	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 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -37,12 +37,6 @@ func Toggle(options *ToggleOptions) macaron.Handler { | ||||||
| 			return | 			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.
 | 		// Redirect to dashboard if user tries to visit any non-login page.
 | ||||||
| 		if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" { | 		if options.SignOutRequired && ctx.IsSigned && ctx.Req.RequestURI != "/" { | ||||||
| 			ctx.Redirect(setting.AppSubURL + "/") | 			ctx.Redirect(setting.AppSubURL + "/") | ||||||
|  |  | ||||||
|  | @ -42,6 +42,10 @@ func Home(ctx *context.Context) { | ||||||
| 			user.Dashboard(ctx) | 			user.Dashboard(ctx) | ||||||
| 		} | 		} | ||||||
| 		return | 		return | ||||||
|  | 		// Check non-logged users landing page.
 | ||||||
|  | 	} else if setting.LandingPageURL != setting.LandingPageHome { | ||||||
|  | 		ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL)) | ||||||
|  | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Check auto-login.
 | 	// Check auto-login.
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue