Skip to content

Commit

Permalink
Reliable selection of admin user (#22509) (#22511)
Browse files Browse the repository at this point in the history
Backport #22509

Co-authored-by: Sybren <122987084+drsybren@users.noreply.github.com>
  • Loading branch information
jolheiser and drsybren authored Jan 18, 2023
1 parent e902b98 commit e6e2c2f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e6e2c2f

Please sign in to comment.