]> source.dussan.org Git - gitea.git/commitdiff
Reliable selection of admin user (#22509) (#22511)
authorJohn Olheiser <john.olheiser@gmail.com>
Wed, 18 Jan 2023 17:47:23 +0000 (11:47 -0600)
committerGitHub <noreply@github.com>
Wed, 18 Jan 2023 17:47:23 +0000 (11:47 -0600)
Backport #22509

Co-authored-by: Sybren <122987084+drsybren@users.noreply.github.com>
models/user/user.go

index 9a2da6dbc1a91718e81a9067b25b64c2dea8630e..63d9b8ad6bcb70d24ae85e9701944587b2187114 100644 (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 {