mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-02-23 11:55:48 -05:00
[v10.0/forgejo] fix: load settings for valid user and email check (#6678)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/6674 - 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. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6678 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
6d7bf7369d
commit
553fc3cc42
2 changed files with 10 additions and 0 deletions
|
@ -138,6 +138,11 @@ func CompileEmailGlobList(sec ConfigSection, keys ...string) (globs []glob.Glob)
|
||||||
return globs
|
return globs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadServiceSetting loads the service settings
|
||||||
|
func LoadServiceSetting() {
|
||||||
|
loadServiceFrom(CfgProvider)
|
||||||
|
}
|
||||||
|
|
||||||
func loadServiceFrom(rootCfg ConfigProvider) {
|
func loadServiceFrom(rootCfg ConfigProvider) {
|
||||||
sec := rootCfg.Section("service")
|
sec := rootCfg.Section("service")
|
||||||
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
|
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/user"
|
"code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/validation"
|
"code.gitea.io/gitea/modules/validation"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
@ -30,6 +31,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.
|
// 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
|
// 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 {
|
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
|
// 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
|
// DB provider-specific SQL and only works _now_. So instead we iterate through all user accounts
|
||||||
// and use the validation.ValidateEmail function to be future-proof.
|
// and use the validation.ValidateEmail function to be future-proof.
|
||||||
|
@ -61,6 +64,8 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
|
||||||
// are allowed for various reasons. This check helps with detecting users that, according
|
// are allowed for various reasons. This check helps with detecting users that, according
|
||||||
// to our reserved names, don't have a valid username.
|
// to our reserved names, don't have a valid username.
|
||||||
func checkUserName(ctx context.Context, logger log.Logger, _ bool) error {
|
func checkUserName(ctx context.Context, logger log.Logger, _ bool) error {
|
||||||
|
setting.LoadServiceSetting()
|
||||||
|
|
||||||
var invalidUserCount int64
|
var invalidUserCount int64
|
||||||
if err := iterateUserAccounts(ctx, func(u *user.User) error {
|
if err := iterateUserAccounts(ctx, func(u *user.User) error {
|
||||||
if err := user.IsUsableUsername(u.Name); err != nil {
|
if err := user.IsUsableUsername(u.Name); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue