aboutsummaryrefslogtreecommitdiffstats
path: root/services/repository/transfer.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-12-10 10:46:31 +0800
committerGitHub <noreply@github.com>2022-12-10 10:46:31 +0800
commit68704532c28cf09db96c988291b2f82c5e615984 (patch)
treec6537092dc11054f96b202fdb957755ed116cd99 /services/repository/transfer.go
parent097d4e30b180eef30600beef2c08095e2571319c (diff)
downloadgitea-68704532c28cf09db96c988291b2f82c5e615984.tar.gz
gitea-68704532c28cf09db96c988291b2f82c5e615984.zip
Rename almost all Ctx functions (#22071)
Diffstat (limited to 'services/repository/transfer.go')
-rw-r--r--services/repository/transfer.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index 9fba9c44eb..f4afb7e2de 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.go
@@ -4,6 +4,7 @@
package repository
import (
+ "context"
"fmt"
"code.gitea.io/gitea/models"
@@ -24,8 +25,8 @@ import (
var repoWorkingPool = sync.NewExclusivePool()
// TransferOwnership transfers all corresponding setting from old user to new one.
-func TransferOwnership(doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error {
- if err := repo.GetOwner(db.DefaultContext); err != nil {
+func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error {
+ if err := repo.GetOwner(ctx); err != nil {
return err
}
for _, team := range teams {
@@ -43,18 +44,18 @@ func TransferOwnership(doer, newOwner *user_model.User, repo *repo_model.Reposit
}
repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
- newRepo, err := repo_model.GetRepositoryByID(db.DefaultContext, repo.ID)
+ newRepo, err := repo_model.GetRepositoryByID(ctx, repo.ID)
if err != nil {
return err
}
for _, team := range teams {
- if err := models.AddRepository(db.DefaultContext, team, newRepo); err != nil {
+ if err := models.AddRepository(ctx, team, newRepo); err != nil {
return err
}
}
- notification.NotifyTransferRepository(db.DefaultContext, doer, repo, oldOwner.Name)
+ notification.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name)
return nil
}
@@ -84,49 +85,49 @@ func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, ne
// StartRepositoryTransfer transfer a repo from one owner to a new one.
// it make repository into pending transfer state, if doer can not create repo for new owner.
-func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error {
+func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository, teams []*organization.Team) error {
if err := models.TestRepositoryReadyForTransfer(repo.Status); err != nil {
return err
}
// Admin is always allowed to transfer || user transfer repo back to his account
if doer.IsAdmin || doer.ID == newOwner.ID {
- return TransferOwnership(doer, newOwner, repo, teams)
+ return TransferOwnership(ctx, doer, newOwner, repo, teams)
}
// If new owner is an org and user can create repos he can transfer directly too
if newOwner.IsOrganization() {
- allowed, err := organization.CanCreateOrgRepo(newOwner.ID, doer.ID)
+ allowed, err := organization.CanCreateOrgRepo(ctx, newOwner.ID, doer.ID)
if err != nil {
return err
}
if allowed {
- return TransferOwnership(doer, newOwner, repo, teams)
+ return TransferOwnership(ctx, doer, newOwner, repo, teams)
}
}
// In case the new owner would not have sufficient access to the repo, give access rights for read
- hasAccess, err := access_model.HasAccess(db.DefaultContext, newOwner.ID, repo)
+ hasAccess, err := access_model.HasAccess(ctx, newOwner.ID, repo)
if err != nil {
return err
}
if !hasAccess {
- if err := repo_module.AddCollaborator(repo, newOwner); err != nil {
+ if err := repo_module.AddCollaborator(ctx, repo, newOwner); err != nil {
return err
}
- if err := repo_model.ChangeCollaborationAccessMode(repo, newOwner.ID, perm.AccessModeRead); err != nil {
+ if err := repo_model.ChangeCollaborationAccessMode(ctx, repo, newOwner.ID, perm.AccessModeRead); err != nil {
return err
}
}
// Make repo as pending for transfer
repo.Status = repo_model.RepositoryPendingTransfer
- if err := models.CreatePendingRepositoryTransfer(doer, newOwner, repo.ID, teams); err != nil {
+ if err := models.CreatePendingRepositoryTransfer(ctx, doer, newOwner, repo.ID, teams); err != nil {
return err
}
// notify users who are able to accept / reject transfer
- notification.NotifyRepoPendingTransfer(db.DefaultContext, doer, newOwner, repo)
+ notification.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo)
return nil
}