aboutsummaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-04-28 13:48:48 +0200
committerGitHub <noreply@github.com>2022-04-28 13:48:48 +0200
commit06e4687cecaed41500b653e5b8685f48b8b18310 (patch)
treea98dd6d0139ba5d89c7e08d3c52930d66a77119b /services/issue
parent332b2ecd214a79b49f3798f4f27fe02b23a17bf8 (diff)
downloadgitea-06e4687cecaed41500b653e5b8685f48b8b18310.tar.gz
gitea-06e4687cecaed41500b653e5b8685f48b8b18310.zip
more context for models (#19511)
make more usage of context, to have more db transaction in one session (make diff of #9307 smaller)
Diffstat (limited to 'services/issue')
-rw-r--r--services/issue/assignee.go14
-rw-r--r--services/issue/commit.go3
-rw-r--r--services/issue/label.go16
3 files changed, 23 insertions, 10 deletions
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index 479c9cbb13..e6169b9c7e 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -5,6 +5,8 @@
package issue
import (
+ "context"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
@@ -78,7 +80,7 @@ func ReviewRequest(issue *models.Issue, doer, reviewer *user_model.User, isAdd b
}
// IsValidReviewRequest Check permission for ReviewRequest
-func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error {
+func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User, isAdd bool, issue *models.Issue, permDoer *models.Permission) error {
if reviewer.IsOrganization() {
return models.ErrNotValidReviewRequest{
Reason: "Organization can't be added as reviewer",
@@ -94,14 +96,14 @@ func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *mo
}
}
- permReviewer, err := models.GetUserRepoPermission(issue.Repo, reviewer)
+ permReviewer, err := models.GetUserRepoPermission(ctx, issue.Repo, reviewer)
if err != nil {
return err
}
if permDoer == nil {
permDoer = new(models.Permission)
- *permDoer, err = models.GetUserRepoPermission(issue.Repo, doer)
+ *permDoer, err = models.GetUserRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return err
}
@@ -168,7 +170,7 @@ func IsValidReviewRequest(reviewer, doer *user_model.User, isAdd bool, issue *mo
}
// IsValidTeamReviewRequest Check permission for ReviewRequest Team
-func IsValidTeamReviewRequest(reviewer *organization.Team, doer *user_model.User, isAdd bool, issue *models.Issue) error {
+func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team, doer *user_model.User, isAdd bool, issue *models.Issue) error {
if doer.IsOrganization() {
return models.ErrNotValidReviewRequest{
Reason: "Organization can't be doer to add reviewer",
@@ -177,7 +179,7 @@ func IsValidTeamReviewRequest(reviewer *organization.Team, doer *user_model.User
}
}
- permission, err := models.GetUserRepoPermission(issue.Repo, doer)
+ permission, err := models.GetUserRepoPermission(ctx, issue.Repo, doer)
if err != nil {
log.Error("Unable to GetUserRepoPermission for %-v in %-v#%d", doer, issue.Repo, issue.Index)
return err
@@ -185,7 +187,7 @@ func IsValidTeamReviewRequest(reviewer *organization.Team, doer *user_model.User
if isAdd {
if issue.Repo.IsPrivate {
- hasTeam := organization.HasTeamRepo(db.DefaultContext, reviewer.OrgID, reviewer.ID, issue.RepoID)
+ hasTeam := organization.HasTeamRepo(ctx, reviewer.OrgID, reviewer.ID, issue.RepoID)
if !hasTeam {
return models.ErrNotValidReviewRequest{
diff --git a/services/issue/commit.go b/services/issue/commit.go
index 0dda5f202f..b5d97e12a8 100644
--- a/services/issue/commit.go
+++ b/services/issue/commit.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/references"
@@ -130,7 +131,7 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
continue
}
- perm, err := models.GetUserRepoPermission(refRepo, doer)
+ perm, err := models.GetUserRepoPermission(db.DefaultContext, refRepo, doer)
if err != nil {
return err
}
diff --git a/services/issue/label.go b/services/issue/label.go
index e72e1cb521..62ccc0ad65 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -44,11 +44,17 @@ func AddLabels(issue *models.Issue, doer *user_model.User, labels []*models.Labe
// RemoveLabel removes a label from issue by given ID.
func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label) error {
- if err := issue.LoadRepo(db.DefaultContext); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
+ return err
+ }
+ defer committer.Close()
+
+ if err := issue.LoadRepo(ctx); err != nil {
return err
}
- perm, err := models.GetUserRepoPermission(issue.Repo, doer)
+ perm, err := models.GetUserRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return err
}
@@ -59,7 +65,11 @@ func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label
return models.ErrRepoLabelNotExist{}
}
- if err := models.DeleteIssueLabel(issue, label, doer); err != nil {
+ if err := models.DeleteIssueLabel(ctx, issue, label, doer); err != nil {
+ return err
+ }
+
+ if err := committer.Commit(); err != nil {
return err
}