mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-28 04:36:11 +01:00
* Add username check to doctor - Add a new breaking change detector to Gitea's doctor, which checks if all users still have a valid username according to Gitea. Given from time-to-time we need to make changes, either due to new routes or due to security, it's for a instance's admin to check if all users still have a valid username. * Fix extra argument * Apply suggestions from code review * Apply suggestions from code review
This commit is contained in:
parent
5ce8fdbc37
commit
aac905dcfb
|
@ -58,6 +58,29 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
|
||||||
return nil
|
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, according
|
||||||
|
// to our reserved names, don't have a valid username.
|
||||||
|
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] does not have a valid username: %v", u.ID, err)
|
||||||
|
}
|
||||||
|
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() {
|
func init() {
|
||||||
Register(&Check{
|
Register(&Check{
|
||||||
Title: "Check if users has an valid email address",
|
Title: "Check if users has an valid email address",
|
||||||
|
@ -66,4 +89,11 @@ func init() {
|
||||||
Run: checkUserEmail,
|
Run: checkUserEmail,
|
||||||
Priority: 9,
|
Priority: 9,
|
||||||
})
|
})
|
||||||
|
Register(&Check{
|
||||||
|
Title: "Check if users have a valid username",
|
||||||
|
Name: "check-user-names",
|
||||||
|
IsDefault: false,
|
||||||
|
Run: checkUserName,
|
||||||
|
Priority: 9,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue