aboutsummaryrefslogtreecommitdiffstats
path: root/modules/repository/collaborator.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 /modules/repository/collaborator.go
parent097d4e30b180eef30600beef2c08095e2571319c (diff)
downloadgitea-68704532c28cf09db96c988291b2f82c5e615984.tar.gz
gitea-68704532c28cf09db96c988291b2f82c5e615984.zip
Rename almost all Ctx functions (#22071)
Diffstat (limited to 'modules/repository/collaborator.go')
-rw-r--r--modules/repository/collaborator.go45
1 files changed, 20 insertions, 25 deletions
diff --git a/modules/repository/collaborator.go b/modules/repository/collaborator.go
index 44c03f999e..f2b9515187 100644
--- a/modules/repository/collaborator.go
+++ b/modules/repository/collaborator.go
@@ -13,30 +13,25 @@ import (
user_model "code.gitea.io/gitea/models/user"
)
-func addCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_model.User) error {
- collaboration := &repo_model.Collaboration{
- RepoID: repo.ID,
- UserID: u.ID,
- }
-
- has, err := db.GetByBean(ctx, collaboration)
- if err != nil {
- return err
- } else if has {
- return nil
- }
- collaboration.Mode = perm.AccessModeWrite
-
- if err = db.Insert(ctx, collaboration); err != nil {
- return err
- }
-
- return access_model.RecalculateUserAccess(ctx, repo, u.ID)
-}
-
-// AddCollaborator adds new collaboration to a repository with default access mode.
-func AddCollaborator(repo *repo_model.Repository, u *user_model.User) error {
- return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
- return addCollaborator(ctx, repo, u)
+func AddCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_model.User) error {
+ return db.AutoTx(ctx, func(ctx context.Context) error {
+ collaboration := &repo_model.Collaboration{
+ RepoID: repo.ID,
+ UserID: u.ID,
+ }
+
+ has, err := db.GetByBean(ctx, collaboration)
+ if err != nil {
+ return err
+ } else if has {
+ return nil
+ }
+ collaboration.Mode = perm.AccessModeWrite
+
+ if err = db.Insert(ctx, collaboration); err != nil {
+ return err
+ }
+
+ return access_model.RecalculateUserAccess(ctx, repo, u.ID)
})
}