From 4ac5412779100a49d2e8768b101656e6bf46bcd8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 28 Dec 2023 23:00:07 +0800 Subject: [PATCH] fix --- models/auth/source.go | 6 +----- models/db/engine.go | 3 --- modules/setting/server.go | 3 +-- modules/web/middleware/data.go | 2 -- routers/common/db.go | 1 - routers/web/auth/auth.go | 10 +++++----- 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/models/auth/source.go b/models/auth/source.go index 8a372c1429b30..1bdde8235cdb4 100644 --- a/models/auth/source.go +++ b/models/auth/source.go @@ -261,16 +261,12 @@ func (opts FindSourcesOptions) ToConds() builder.Cond { // IsSSPIEnabled returns true if there is at least one activated login // source of type LoginSSPI func IsSSPIEnabled(ctx context.Context) bool { - if !db.HasEngine { - return false - } - exist, err := db.Exist[Source](ctx, FindSourcesOptions{ IsActive: util.OptionalBoolTrue, LoginType: SSPI, }.ToConds()) if err != nil { - log.Error("Active SSPI Sources: %v", err) + log.Error("IsSSPIEnabled: failed to query active SSPI sources: %v", err) return false } return exist diff --git a/models/db/engine.go b/models/db/engine.go index 182d8cd993696..99906813ca870 100755 --- a/models/db/engine.go +++ b/models/db/engine.go @@ -27,9 +27,6 @@ var ( x *xorm.Engine tables []any initFuncs []func() error - - // HasEngine specifies if we have a xorm.Engine - HasEngine bool ) // Engine represents a xorm engine or session. diff --git a/modules/setting/server.go b/modules/setting/server.go index 80b85eeebdda7..c09b91612a942 100644 --- a/modules/setting/server.go +++ b/modules/setting/server.go @@ -341,8 +341,7 @@ func loadServerFrom(rootCfg ConfigProvider) { LandingPageURL = LandingPageOrganizations case "login": LandingPageURL = LandingPageLogin - case "": - case "home": + case "", "home": LandingPageURL = LandingPageHome default: LandingPageURL = LandingPage(landingPage) diff --git a/modules/web/middleware/data.go b/modules/web/middleware/data.go index 08d83f94be7f1..9c2cf2a3f0574 100644 --- a/modules/web/middleware/data.go +++ b/modules/web/middleware/data.go @@ -47,8 +47,6 @@ func GetContextData(c context.Context) ContextData { func CommonTemplateContextData() ContextData { return ContextData{ - "IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations, - "ShowRegistrationButton": setting.Service.ShowRegistrationButton, "ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage, "ShowFooterVersion": setting.Other.ShowFooterVersion, diff --git a/routers/common/db.go b/routers/common/db.go index 547f727ce2478..a67c9582fa387 100644 --- a/routers/common/db.go +++ b/routers/common/db.go @@ -37,7 +37,6 @@ func InitDBEngine(ctx context.Context) (err error) { log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second)) time.Sleep(setting.Database.DBConnectBackoff) } - db.HasEngine = true config.SetDynGetter(system_model.NewDatabaseDynKeyGetter()) return nil } diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 8f37d05fda0ef..21a72a9521533 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -45,10 +45,6 @@ const ( // autoSignIn reads cookie and try to auto-login. func autoSignIn(ctx *context.Context) (bool, error) { - if !db.HasEngine { - return false, nil - } - isSucceed := false defer func() { if !isSucceed { @@ -145,7 +141,11 @@ func CheckAutoLogin(ctx *context.Context) bool { if isSucceed { middleware.DeleteRedirectToCookie(ctx.Resp) - ctx.RedirectToFirst(redirectTo, setting.AppSubURL+string(setting.LandingPageURL)) + nextRedirectTo := setting.AppSubURL + string(setting.LandingPageURL) + if setting.LandingPageURL == setting.LandingPageLogin { + nextRedirectTo = setting.AppSubURL + "/" // do not cycle-redirect to the login page + } + ctx.RedirectToFirst(redirectTo, nextRedirectTo) return true }