Skip to content

Commit 57e8163

Browse files
authored
Fix bug (#19757)
1 parent 09b7629 commit 57e8163

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

models/issue_assignees.go

+7-12
Original file line numberDiff line numberDiff line change
@@ -155,31 +155,26 @@ func toggleUserAssignee(e db.Engine, issue *Issue, assigneeID int64) (removed bo
155155
}
156156

157157
// Check if the submitted user is already assigned, if yes delete him otherwise add him
158-
var i int
159-
for i = 0; i < len(issue.Assignees); i++ {
158+
found := false
159+
i := 0
160+
for ; i < len(issue.Assignees); i++ {
160161
if issue.Assignees[i].ID == assigneeID {
162+
found = true
161163
break
162164
}
163165
}
164166

165167
assigneeIn := IssueAssignees{AssigneeID: assigneeID, IssueID: issue.ID}
166168

167-
toBeDeleted := i < len(issue.Assignees)
168-
if toBeDeleted {
169-
issue.Assignees = append(issue.Assignees[:i], issue.Assignees[i:]...)
169+
if found {
170+
issue.Assignees = append(issue.Assignees[:i], issue.Assignees[i+1:]...)
170171
_, err = e.Delete(assigneeIn)
171-
if err != nil {
172-
return toBeDeleted, err
173-
}
174172
} else {
175173
issue.Assignees = append(issue.Assignees, assignee)
176174
_, err = e.Insert(assigneeIn)
177-
if err != nil {
178-
return toBeDeleted, err
179-
}
180175
}
181176

182-
return toBeDeleted, nil
177+
return found, err
183178
}
184179

185180
// MakeIDsFromAPIAssigneesToAdd returns an array with all assignee IDs

services/issue/assignee.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
1717
func DeleteNotPassedAssignee(issue *models.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
1818
var found bool
19+
oriAssignes := make([]*user_model.User, len(issue.Assignees))
20+
_ = copy(oriAssignes, issue.Assignees)
1921

20-
for _, assignee := range issue.Assignees {
21-
22+
for _, assignee := range oriAssignes {
2223
found = false
2324
for _, alreadyAssignee := range assignees {
2425
if assignee.ID == alreadyAssignee.ID {

0 commit comments

Comments
 (0)