diff options
author | JakobDev <jakobdev@gmx.de> | 2023-09-25 15:17:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 13:17:37 +0000 |
commit | 7047df36d4c39fefa6464b713c66302aa0038123 (patch) | |
tree | a5c471a3e8abf5cabac8de42c0fd8a814df7abf1 /models/user | |
parent | 93bd4351bfb4a2f5f37ecb80d50496d044240e00 (diff) | |
download | gitea-7047df36d4c39fefa6464b713c66302aa0038123.tar.gz gitea-7047df36d4c39fefa6464b713c66302aa0038123.zip |
Another round of `db.DefaultContext` refactor (#27103)
Part of #27065
---------
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'models/user')
-rw-r--r-- | models/user/redirect.go | 4 | ||||
-rw-r--r-- | models/user/redirect_test.go | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/models/user/redirect.go b/models/user/redirect.go index 42e991888a..5a40d4df3b 100644 --- a/models/user/redirect.go +++ b/models/user/redirect.go @@ -48,10 +48,10 @@ func init() { } // LookupUserRedirect look up userID if a user has a redirect name -func LookupUserRedirect(userName string) (int64, error) { +func LookupUserRedirect(ctx context.Context, userName string) (int64, error) { userName = strings.ToLower(userName) redirect := &Redirect{LowerName: userName} - if has, err := db.GetEngine(db.DefaultContext).Get(redirect); err != nil { + if has, err := db.GetEngine(ctx).Get(redirect); err != nil { return 0, err } else if !has { return 0, ErrUserRedirectNotExist{Name: userName} diff --git a/models/user/redirect_test.go b/models/user/redirect_test.go index 3d2ea3aeec..484c5a663f 100644 --- a/models/user/redirect_test.go +++ b/models/user/redirect_test.go @@ -6,6 +6,7 @@ package user_test import ( "testing" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" @@ -15,10 +16,10 @@ import ( func TestLookupUserRedirect(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - userID, err := user_model.LookupUserRedirect("olduser1") + userID, err := user_model.LookupUserRedirect(db.DefaultContext, "olduser1") assert.NoError(t, err) assert.EqualValues(t, 1, userID) - _, err = user_model.LookupUserRedirect("doesnotexist") + _, err = user_model.LookupUserRedirect(db.DefaultContext, "doesnotexist") assert.True(t, user_model.IsErrUserRedirectNotExist(err)) } |