diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-05-20 22:08:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 22:08:52 +0800 |
commit | fd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch) | |
tree | 50038348ec10485f72344f3ac80324e04abc1283 /services/auth | |
parent | d81e31ad7826a81fc7139f329f250594610a274b (diff) | |
download | gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip |
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context
* remove some unnecessary wrap functions
Diffstat (limited to 'services/auth')
-rw-r--r-- | services/auth/oauth2.go | 2 | ||||
-rw-r--r-- | services/auth/reverseproxy.go | 2 | ||||
-rw-r--r-- | services/auth/source/ldap/source_authenticate.go | 4 | ||||
-rw-r--r-- | services/auth/source/ldap/source_sync.go | 3 | ||||
-rw-r--r-- | services/auth/sspi_windows.go | 2 |
5 files changed, 6 insertions, 7 deletions
diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go index 42c91fac37..68638a0806 100644 --- a/services/auth/oauth2.go +++ b/services/auth/oauth2.go @@ -38,7 +38,7 @@ func CheckOAuthAccessToken(accessToken string) int64 { return 0 } var grant *auth.OAuth2Grant - if grant, err = auth.GetOAuth2GrantByID(token.GrantID); err != nil || grant == nil { + if grant, err = auth.GetOAuth2GrantByID(db.DefaultContext, token.GrantID); err != nil || grant == nil { return 0 } if token.Type != oauth2.TypeAccessToken { diff --git a/services/auth/reverseproxy.go b/services/auth/reverseproxy.go index 299d7abd34..05d6af78f1 100644 --- a/services/auth/reverseproxy.go +++ b/services/auth/reverseproxy.go @@ -63,7 +63,7 @@ func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store Da } log.Trace("ReverseProxy Authorization: Found username: %s", username) - user, err := user_model.GetUserByName(username) + user, err := user_model.GetUserByName(req.Context(), username) if err != nil { if !user_model.IsErrUserNotExist(err) || !r.isAutoRegisterAllowed() { log.Error("GetUserByName: %v", err) diff --git a/services/auth/source/ldap/source_authenticate.go b/services/auth/source/ldap/source_authenticate.go index d8d11f18e1..785cb8ed31 100644 --- a/services/auth/source/ldap/source_authenticate.go +++ b/services/auth/source/ldap/source_authenticate.go @@ -34,11 +34,11 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str isAttributeSSHPublicKeySet := len(strings.TrimSpace(source.AttributeSSHPublicKey)) > 0 // Update User admin flag if exist - if isExist, err := user_model.IsUserExist(0, sr.Username); err != nil { + if isExist, err := user_model.IsUserExist(db.DefaultContext, 0, sr.Username); err != nil { return nil, err } else if isExist { if user == nil { - user, err = user_model.GetUserByName(sr.Username) + user, err = user_model.GetUserByName(db.DefaultContext, sr.Username) if err != nil { return nil, err } diff --git a/services/auth/source/ldap/source_sync.go b/services/auth/source/ldap/source_sync.go index a245f4c6ff..eb5ee8463f 100644 --- a/services/auth/source/ldap/source_sync.go +++ b/services/auth/source/ldap/source_sync.go @@ -118,7 +118,6 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error { } err = user_model.CreateUser(usr, overwriteDefault) - if err != nil { log.Error("SyncExternalUsers[%s]: Error creating user %s: %v", source.authSource.Name, su.Username, err) } @@ -161,7 +160,7 @@ func (source *Source) Sync(ctx context.Context, updateExisting bool) error { } usr.IsActive = true - err = user_model.UpdateUser(usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active") + err = user_model.UpdateUser(ctx, usr, emailChanged, "full_name", "email", "is_admin", "is_restricted", "is_active") if err != nil { log.Error("SyncExternalUsers[%s]: Error updating user %s: %v", source.authSource.Name, usr.Name, err) } diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go index 9bc4041a74..7c9529a76b 100644 --- a/services/auth/sspi_windows.go +++ b/services/auth/sspi_windows.go @@ -127,7 +127,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore, } log.Info("Authenticated as %s\n", username) - user, err := user_model.GetUserByName(username) + user, err := user_model.GetUserByName(req.Context(), username) if err != nil { if !user_model.IsErrUserNotExist(err) { log.Error("GetUserByName: %v", err) |