aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2023-01-18 11:47:23 -0600
committerGitHub <noreply@github.com>2023-01-18 11:47:23 -0600
commite6e2c2f4a481b06dbb66ef13f275dd26808656a5 (patch)
tree5d54518dd0473be4cdb1b4eeffb130e23ddf4e18
parente902b98cc242776f60f845a353b215115e0a4b1f (diff)
downloadgitea-e6e2c2f4a481b06dbb66ef13f275dd26808656a5.tar.gz
gitea-e6e2c2f4a481b06dbb66ef13f275dd26808656a5.zip
Reliable selection of admin user (#22509) (#22511)
Backport #22509 Co-authored-by: Sybren <122987084+drsybren@users.noreply.github.com>
-rw-r--r--models/user/user.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/models/user/user.go b/models/user/user.go
index 9a2da6dbc1..63d9b8ad6b 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -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 {