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/git/branches.go | |
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/git/branches.go')
-rw-r--r-- | models/git/branches.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/models/git/branches.go b/models/git/branches.go index 87246ed149..c02ab0a888 100644 --- a/models/git/branches.go +++ b/models/git/branches.go @@ -73,10 +73,10 @@ func (protectBranch *ProtectedBranch) CanUserPush(userID int64) bool { } if !protectBranch.EnableWhitelist { - if user, err := user_model.GetUserByID(userID); err != nil { + if user, err := user_model.GetUserByID(db.DefaultContext, userID); err != nil { log.Error("GetUserByID: %v", err) return false - } else if repo, err := repo_model.GetRepositoryByID(protectBranch.RepoID); err != nil { + } else if repo, err := repo_model.GetRepositoryByID(db.DefaultContext, protectBranch.RepoID); err != nil { log.Error("repo_model.GetRepositoryByID: %v", err) return false } else if writeAccess, err := access_model.HasAccessUnit(db.DefaultContext, user, repo, unit.TypeCode, perm.AccessModeWrite); err != nil { @@ -127,13 +127,8 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch, } // IsUserOfficialReviewer check if user is official reviewer for the branch (counts towards required approvals) -func IsUserOfficialReviewer(protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { - return IsUserOfficialReviewerCtx(db.DefaultContext, protectBranch, user) -} - -// IsUserOfficialReviewerCtx check if user is official reviewer for the branch (counts towards required approvals) -func IsUserOfficialReviewerCtx(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { - repo, err := repo_model.GetRepositoryByIDCtx(ctx, protectBranch.RepoID) +func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch, user *user_model.User) (bool, error) { + repo, err := repo_model.GetRepositoryByID(ctx, protectBranch.RepoID) if err != nil { return false, err } @@ -375,7 +370,7 @@ func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, curre whitelist = make([]int64, 0, len(newWhitelist)) for _, userID := range newWhitelist { - user, err := user_model.GetUserByIDCtx(ctx, userID) + user, err := user_model.GetUserByID(ctx, userID) if err != nil { return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %w", userID, repo.ID, err) } @@ -494,8 +489,8 @@ func RemoveDeletedBranchByID(repoID, id int64) (err error) { // LoadUser loads the user that deleted the branch // When there's no user found it returns a user_model.NewGhostUser -func (deletedBranch *DeletedBranch) LoadUser() { - user, err := user_model.GetUserByID(deletedBranch.DeletedByID) +func (deletedBranch *DeletedBranch) LoadUser(ctx context.Context) { + user, err := user_model.GetUserByID(ctx, deletedBranch.DeletedByID) if err != nil { user = user_model.NewGhostUser() } |