diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-03 10:48:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-03 10:48:26 +0800 |
commit | 0a7d3ff786508284224ada17956a65bb759d9265 (patch) | |
tree | 4860fca95c1432ab59c6723ee2b053b1c7d6779d /models/user | |
parent | 8698458f48eafeab21014db544aa7160368856e1 (diff) | |
download | gitea-0a7d3ff786508284224ada17956a65bb759d9265.tar.gz gitea-0a7d3ff786508284224ada17956a65bb759d9265.zip |
refactor some functions to support ctx as first parameter (#21878)
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/user')
-rw-r--r-- | models/user/email_address.go | 2 | ||||
-rw-r--r-- | models/user/email_address_test.go | 2 | ||||
-rw-r--r-- | models/user/user.go | 11 | ||||
-rw-r--r-- | models/user/user_test.go | 2 |
4 files changed, 6 insertions, 11 deletions
diff --git a/models/user/email_address.go b/models/user/email_address.go index 70394edb23..69e94f8bb6 100644 --- a/models/user/email_address.go +++ b/models/user/email_address.go @@ -332,7 +332,7 @@ func ActivateEmail(email *EmailAddress) error { } func updateActivation(ctx context.Context, email *EmailAddress, activate bool) error { - user, err := GetUserByIDCtx(ctx, email.UID) + user, err := GetUserByID(ctx, email.UID) if err != nil { return err } diff --git a/models/user/email_address_test.go b/models/user/email_address_test.go index 7e523a165d..53fd18c303 100644 --- a/models/user/email_address_test.go +++ b/models/user/email_address_test.go @@ -162,7 +162,7 @@ func TestMakeEmailPrimary(t *testing.T) { err = user_model.MakeEmailPrimary(email) assert.NoError(t, err) - user, _ := user_model.GetUserByID(int64(10)) + user, _ := user_model.GetUserByID(db.DefaultContext, int64(10)) assert.Equal(t, "user101@example.com", user.Email) } diff --git a/models/user/user.go b/models/user/user.go index 915e4243cf..71b036b06f 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -993,12 +993,7 @@ func UserPath(userName string) string { //revive:disable-line:exported } // GetUserByID returns the user object by given ID if exists. -func GetUserByID(id int64) (*User, error) { - return GetUserByIDCtx(db.DefaultContext, id) -} - -// GetUserByIDCtx returns the user object by given ID if exists. -func GetUserByIDCtx(ctx context.Context, id int64) (*User, error) { +func GetUserByID(ctx context.Context, id int64) (*User, error) { u := new(User) has, err := db.GetEngine(ctx).ID(id).Get(u) if err != nil { @@ -1176,7 +1171,7 @@ func GetUserByEmailContext(ctx context.Context, email string) (*User, error) { return nil, err } if has { - return GetUserByIDCtx(ctx, emailAddress.UID) + return GetUserByID(ctx, emailAddress.UID) } // Finally, if email address is the protected email address: @@ -1220,7 +1215,7 @@ func GetUserByOpenID(uri string) (*User, error) { return nil, err } if has { - return GetUserByID(oid.UID) + return GetUserByID(db.DefaultContext, oid.UID) } return nil, ErrUserNotExist{0, uri, 0} diff --git a/models/user/user_test.go b/models/user/user_test.go index 2ee4da0d67..525da531f2 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -22,7 +22,7 @@ import ( func TestOAuth2Application_LoadUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) app := unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ID: 1}) - user, err := user_model.GetUserByID(app.UID) + user, err := user_model.GetUserByID(db.DefaultContext, app.UID) assert.NoError(t, err) assert.NotNil(t, user) } |