diff options
author | Sybren <122987084+drsybren@users.noreply.github.com> | 2023-01-18 17:57:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 10:57:16 -0600 |
commit | 326d29dce0cf2dcd5478f297d899f098aefaadaa (patch) | |
tree | 8ed0431f36bdf8e6a54de3ace90e3e17217476b0 /models | |
parent | f59ce777728cf84ccdf711491772104a0fc0dd6e (diff) | |
download | gitea-326d29dce0cf2dcd5478f297d899f098aefaadaa.tar.gz gitea-326d29dce0cf2dcd5478f297d899f098aefaadaa.zip |
Reliable selection of admin user (#22509)
When importing a repository via `gitea restore-repo`, external users
will get remapped to an admin user. This admin user is obtained via
`users.GetAdminUser()`, which unfortunately picks a more-or-less random
admin to return.
This makes it hard to predict which admin user will get assigned. This
patch orders the admin by ascending ID before choosing the first one,
i.e. it picks the admin with the lowest ID.
Even though it would be nicer to have full control over which user is
chosen, this at least gives us a predictable result.
Diffstat (limited to 'models')
-rw-r--r-- | models/user/user.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/models/user/user.go b/models/user/user.go index 825223201b..a2c54a4429 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1233,7 +1233,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 { |