aboutsummaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-05-20 22:08:52 +0800
committerGitHub <noreply@github.com>2022-05-20 22:08:52 +0800
commitfd7d83ace60258acf7139c4c787aa8af75b7ba8c (patch)
tree50038348ec10485f72344f3ac80324e04abc1283 /services/issue
parentd81e31ad7826a81fc7139f329f250594610a274b (diff)
downloadgitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.tar.gz
gitea-fd7d83ace60258acf7139c4c787aa8af75b7ba8c.zip
Move almost all functions' parameter db.Engine to context.Context (#19748)
* Move almost all functions' parameter db.Engine to context.Context * remove some unnecessary wrap functions
Diffstat (limited to 'services/issue')
-rw-r--r--services/issue/assignee.go11
-rw-r--r--services/issue/assignee_test.go11
-rw-r--r--services/issue/issue.go4
-rw-r--r--services/issue/label.go2
4 files changed, 16 insertions, 12 deletions
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index 0b6d0045fd..8cad03351c 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -21,9 +21,10 @@ import (
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
var found bool
+ oriAssignes := make([]*user_model.User, len(issue.Assignees))
+ _ = copy(oriAssignes, issue.Assignees)
- for _, assignee := range issue.Assignees {
-
+ for _, assignee := range oriAssignes {
found = false
for _, alreadyAssignee := range assignees {
if assignee.ID == alreadyAssignee.ID {
@@ -110,7 +111,7 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
}
}
- lastreview, err := models.GetReviewByIssueIDAndUserID(issue.ID, reviewer.ID)
+ lastreview, err := models.GetReviewByIssueIDAndUserID(ctx, issue.ID, reviewer.ID)
if err != nil && !models.IsErrReviewNotExist(err) {
return err
}
@@ -132,7 +133,7 @@ func IsValidReviewRequest(ctx context.Context, reviewer, doer *user_model.User,
pemResult = permDoer.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !pemResult {
- pemResult, err = models.IsOfficialReviewer(issue, doer)
+ pemResult, err = models.IsOfficialReviewer(ctx, issue, doer)
if err != nil {
return err
}
@@ -201,7 +202,7 @@ func IsValidTeamReviewRequest(ctx context.Context, reviewer *organization.Team,
doerCanWrite := permission.CanAccessAny(perm.AccessModeWrite, unit.TypePullRequests)
if !doerCanWrite {
- official, err := models.IsOfficialReviewer(issue, doer)
+ official, err := models.IsOfficialReviewer(ctx, issue, doer)
if err != nil {
log.Error("Unable to Check if IsOfficialReviewer for %-v in %-v#%d", doer, issue.Repo, issue.Index)
return err
diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go
index d3d7ad74f8..ff4d7029eb 100644
--- a/services/issue/assignee_test.go
+++ b/services/issue/assignee_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -20,21 +21,23 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
// Fake issue with assignees
issue, err := models.GetIssueWithAttrsByID(1)
assert.NoError(t, err)
+ assert.EqualValues(t, 1, len(issue.Assignees))
user1, err := user_model.GetUserByID(1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
// Check if he got removed
- isAssigned, err := models.IsUserAssignedToIssue(issue, user1)
+ isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
assert.NoError(t, err)
assert.True(t, isAssigned)
// Clean everyone
err = DeleteNotPassedAssignee(issue, user1, []*user_model.User{})
assert.NoError(t, err)
+ assert.EqualValues(t, 0, len(issue.Assignees))
// Check they're gone
- assignees, err := models.GetAssigneesByIssue(issue)
- assert.NoError(t, err)
- assert.Empty(t, assignees)
+ assert.NoError(t, issue.LoadAssignees(db.DefaultContext))
+ assert.EqualValues(t, 0, len(issue.Assignees))
+ assert.Empty(t, issue.Assignee)
}
diff --git a/services/issue/issue.go b/services/issue/issue.go
index db304a46b7..78a486727a 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -100,7 +100,7 @@ func UpdateAssignees(issue *models.Issue, oneAssignee string, multipleAssignees
// Loop through all assignees to add them
for _, assigneeName := range multipleAssignees {
- assignee, err := user_model.GetUserByName(assigneeName)
+ assignee, err := user_model.GetUserByName(db.DefaultContext, assigneeName)
if err != nil {
return err
}
@@ -164,7 +164,7 @@ func AddAssigneeIfNotAssigned(issue *models.Issue, doer *user_model.User, assign
}
// Check if the user is already assigned
- isAssigned, err := models.IsUserAssignedToIssue(issue, assignee)
+ isAssigned, err := models.IsUserAssignedToIssue(db.DefaultContext, issue, assignee)
if err != nil {
return err
}
diff --git a/services/issue/label.go b/services/issue/label.go
index 94e52482fb..289466f604 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -80,7 +80,7 @@ func RemoveLabel(issue *models.Issue, doer *user_model.User, label *models.Label
// ReplaceLabels removes all current labels and add new labels to the issue.
func ReplaceLabels(issue *models.Issue, doer *user_model.User, labels []*models.Label) error {
- old, err := models.GetLabelsByIssueID(issue.ID)
+ old, err := models.GetLabelsByIssueID(db.DefaultContext, issue.ID)
if err != nil {
return err
}