Reliable selection of admin user (#22509) (#22511)

Backport #22509

Co-authored-by: Sybren <122987084+drsybren@users.noreply.github.com>
(cherry picked from commit e6e2c2f4a4)
This commit is contained in:
John Olheiser 2023-01-18 11:47:23 -06:00 committed by Loïc Dachary
parent 4430bd6dd9
commit 86857fdac3
No known key found for this signature in database
GPG Key ID: 992D23B392F9E4F2
1 changed files with 4 additions and 1 deletions

View File

@ -1227,7 +1227,10 @@ func GetUserByOpenID(uri string) (*User, error) {
// GetAdminUser returns the first administrator
func GetAdminUser() (*User, error) {
var admin User
has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
has, err := db.GetEngine(db.DefaultContext).
Where("is_admin=?", true).
Asc("id"). // Reliably get the admin with the lowest ID.
Get(&admin)
if err != nil {
return nil, err
} else if !has {