From 51e0b34fa8b092efe1bac3d117b92418d45e7193 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 24 Jan 2025 12:23:15 +0000 Subject: [PATCH] [v7.0/forgejo] fix: load settings for valid user and email check - The doctor commands to check the validity of existing usernames and email addresses depend on functionality that have configurable behavior depending on the values of the `[service]` settings, so load them when running the doctor command. - Resolves #6664 - No unit test due to the architecture of doctor commands. (cherry picked from commit 46e60ce966f6799205f80c0cf8a3186bd8097a61) --- modules/setting/service.go | 5 +++++ services/doctor/breaking.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/modules/setting/service.go b/modules/setting/service.go index afaee18101..b088bc59c5 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -133,6 +133,11 @@ func CompileEmailGlobList(sec ConfigSection, keys ...string) (globs []glob.Glob) return globs } +// LoadServiceSetting loads the service settings +func LoadServiceSetting() { + loadServiceFrom(CfgProvider) +} + func loadServiceFrom(rootCfg ConfigProvider) { sec := rootCfg.Section("service") Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180) diff --git a/services/doctor/breaking.go b/services/doctor/breaking.go index 77e3d4e8ef..8945e8c2a3 100644 --- a/services/doctor/breaking.go +++ b/services/doctor/breaking.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" "xorm.io/builder" ) @@ -29,6 +30,8 @@ func iterateUserAccounts(ctx context.Context, each func(*user.User) error) error // addresses would be currently facing a error due to their invalid email address. // Ref: https://github.com/go-gitea/gitea/pull/19085 & https://github.com/go-gitea/gitea/pull/17688 func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error { + setting.LoadServiceSetting() + // We could use quirky SQL to get all users that start without a [a-zA-Z0-9], but that would mean // DB provider-specific SQL and only works _now_. So instead we iterate through all user accounts // and use the user.ValidateEmail function to be future-proof. @@ -60,6 +63,8 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error { // are allowed for various reasons. This check helps with detecting users that, according // to our reserved names, don't have a valid username. func checkUserName(ctx context.Context, logger log.Logger, _ bool) error { + setting.LoadServiceSetting() + var invalidUserCount int64 if err := iterateUserAccounts(ctx, func(u *user.User) error { if err := user.IsUsableUsername(u.Name); err != nil {