diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-14 10:37:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 08:37:24 +0000 |
commit | 76a85a4ce90fead1eb2b743a42b41617b4592889 (patch) | |
tree | ef172bbbc48c24e0d95cd5c689426bad16205a69 /models/user | |
parent | ae419fa49403537725c806a5f3f1e5b274f52eb7 (diff) | |
download | gitea-76a85a4ce90fead1eb2b743a42b41617b4592889.tar.gz gitea-76a85a4ce90fead1eb2b743a42b41617b4592889.zip |
Final round of `db.DefaultContext` refactor (#27587)
Last part of #27065
Diffstat (limited to 'models/user')
-rw-r--r-- | models/user/external_login_user.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/models/user/external_login_user.go b/models/user/external_login_user.go index 3a56240435..4121c5d89f 100644 --- a/models/user/external_login_user.go +++ b/models/user/external_login_user.go @@ -92,14 +92,14 @@ func init() { } // GetExternalLogin checks if a externalID in loginSourceID scope already exists -func GetExternalLogin(externalLoginUser *ExternalLoginUser) (bool, error) { - return db.GetEngine(db.DefaultContext).Get(externalLoginUser) +func GetExternalLogin(ctx context.Context, externalLoginUser *ExternalLoginUser) (bool, error) { + return db.GetEngine(ctx).Get(externalLoginUser) } // ListAccountLinks returns a map with the ExternalLoginUser and its LoginSource -func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) { +func ListAccountLinks(ctx context.Context, user *User) ([]*ExternalLoginUser, error) { externalAccounts := make([]*ExternalLoginUser, 0, 5) - err := db.GetEngine(db.DefaultContext).Where("user_id=?", user.ID). + err := db.GetEngine(ctx).Where("user_id=?", user.ID). Desc("login_source_id"). Find(&externalAccounts) if err != nil { @@ -110,8 +110,8 @@ func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) { } // LinkExternalToUser link the external user to the user -func LinkExternalToUser(user *User, externalLoginUser *ExternalLoginUser) error { - has, err := db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", externalLoginUser.ExternalID, externalLoginUser.LoginSourceID). +func LinkExternalToUser(ctx context.Context, user *User, externalLoginUser *ExternalLoginUser) error { + has, err := db.GetEngine(ctx).Where("external_id=? AND login_source_id=?", externalLoginUser.ExternalID, externalLoginUser.LoginSourceID). NoAutoCondition(). Exist(externalLoginUser) if err != nil { @@ -120,13 +120,13 @@ func LinkExternalToUser(user *User, externalLoginUser *ExternalLoginUser) error return ErrExternalLoginUserAlreadyExist{externalLoginUser.ExternalID, user.ID, externalLoginUser.LoginSourceID} } - _, err = db.GetEngine(db.DefaultContext).Insert(externalLoginUser) + _, err = db.GetEngine(ctx).Insert(externalLoginUser) return err } // RemoveAccountLink will remove all external login sources for the given user -func RemoveAccountLink(user *User, loginSourceID int64) (int64, error) { - deleted, err := db.GetEngine(db.DefaultContext).Delete(&ExternalLoginUser{UserID: user.ID, LoginSourceID: loginSourceID}) +func RemoveAccountLink(ctx context.Context, user *User, loginSourceID int64) (int64, error) { + deleted, err := db.GetEngine(ctx).Delete(&ExternalLoginUser{UserID: user.ID, LoginSourceID: loginSourceID}) if err != nil { return deleted, err } @@ -143,9 +143,9 @@ func RemoveAllAccountLinks(ctx context.Context, user *User) error { } // GetUserIDByExternalUserID get user id according to provider and userID -func GetUserIDByExternalUserID(provider, userID string) (int64, error) { +func GetUserIDByExternalUserID(ctx context.Context, provider, userID string) (int64, error) { var id int64 - _, err := db.GetEngine(db.DefaultContext).Table("external_login_user"). + _, err := db.GetEngine(ctx).Table("external_login_user"). Select("user_id"). Where("provider=?", provider). And("external_id=?", userID). @@ -157,8 +157,8 @@ func GetUserIDByExternalUserID(provider, userID string) (int64, error) { } // UpdateExternalUserByExternalID updates an external user's information -func UpdateExternalUserByExternalID(external *ExternalLoginUser) error { - has, err := db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID). +func UpdateExternalUserByExternalID(ctx context.Context, external *ExternalLoginUser) error { + has, err := db.GetEngine(ctx).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID). NoAutoCondition(). Exist(external) if err != nil { @@ -167,7 +167,7 @@ func UpdateExternalUserByExternalID(external *ExternalLoginUser) error { return ErrExternalLoginUserNotExist{external.UserID, external.LoginSourceID} } - _, err = db.GetEngine(db.DefaultContext).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).AllCols().Update(external) + _, err = db.GetEngine(ctx).Where("external_id=? AND login_source_id=?", external.ExternalID, external.LoginSourceID).AllCols().Update(external) return err } @@ -187,9 +187,9 @@ func (opts FindExternalUserOptions) toConds() builder.Cond { } // FindExternalUsersByProvider represents external users via provider -func FindExternalUsersByProvider(opts FindExternalUserOptions) ([]ExternalLoginUser, error) { +func FindExternalUsersByProvider(ctx context.Context, opts FindExternalUserOptions) ([]ExternalLoginUser, error) { var users []ExternalLoginUser - err := db.GetEngine(db.DefaultContext).Where(opts.toConds()). + err := db.GetEngine(ctx).Where(opts.toConds()). Limit(opts.Limit, opts.Start). OrderBy("login_source_id ASC, external_id ASC"). Find(&users) |