Skip to content

Commit e6e2c2f

Browse files
jolheiserdrsybren
andauthored
Reliable selection of admin user (#22509) (#22511)
Backport #22509 Co-authored-by: Sybren <[email protected]>
1 parent e902b98 commit e6e2c2f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: models/user/user.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,10 @@ func GetUserByOpenID(uri string) (*User, error) {
12271227
// GetAdminUser returns the first administrator
12281228
func GetAdminUser() (*User, error) {
12291229
var admin User
1230-
has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
1230+
has, err := db.GetEngine(db.DefaultContext).
1231+
Where("is_admin=?", true).
1232+
Asc("id"). // Reliably get the admin with the lowest ID.
1233+
Get(&admin)
12311234
if err != nil {
12321235
return nil, err
12331236
} else if !has {

0 commit comments

Comments
 (0)