Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username check to doctor #20140

Merged
merged 6 commits into from
Jun 27, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions modules/doctor/breaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
return nil
}

// From time to time Gitea makes changes to the reserved usernames and which symbols
// are allowed for various reasons. This check helps with detecting users that are according
// to Gitea don't have a valid username.
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
func checkUserName(ctx context.Context, logger log.Logger, _ bool) error {
var invalidUserCount int64
if err := iterateUserAccounts(ctx, func(u *user.User) error {
if err := user.IsUsableUsername(u.Name); err != nil {
invalidUserCount++
logger.Warn("User[id=%d] have not a valid username: %v", u.ID, err)
Gusted marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}); err != nil {
return fmt.Errorf("iterateUserAccounts: %v", err)
}

if invalidUserCount == 0 {
logger.Info("All users have a valid username.")
} else {
logger.Warn("%d user(s) have a non-valid username.", invalidUserCount)
}
return nil
}

func init() {
Register(&Check{
Title: "Check if users has an valid email address",
Expand All @@ -66,4 +89,11 @@ func init() {
Run: checkUserEmail,
Priority: 9,
})
Register(&Check{
Title: "Check if users has an valid username",
Gusted marked this conversation as resolved.
Show resolved Hide resolved
Name: "check-user-name",
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
IsDefault: false,
Run: checkUserName,
Priority: 9,
})
}