2019-10-28 02:11:50 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-10-28 02:11:50 +00:00
|
|
|
|
|
|
|
package issue
|
|
|
|
|
|
|
|
import (
|
2022-04-28 11:48:48 +00:00
|
|
|
"context"
|
|
|
|
|
2022-06-13 09:37:59 +00:00
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-24 09:49:20 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2023-09-05 18:37:47 +00:00
|
|
|
notify_service "code.gitea.io/gitea/services/notify"
|
2019-10-28 02:11:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
|
2023-04-14 18:18:28 +00:00
|
|
|
func DeleteNotPassedAssignee(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, assignees []*user_model.User) (err error) {
|
2019-10-28 02:11:50 +00:00
|
|
|
var found bool
|
2022-05-20 14:08:52 +00:00
|
|
|
oriAssignes := make([]*user_model.User, len(issue.Assignees))
|
|
|
|
_ = copy(oriAssignes, issue.Assignees)
|
2019-10-28 02:11:50 +00:00
|
|
|
|
2022-05-20 14:08:52 +00:00
|
|
|
for _, assignee := range oriAssignes {
|
2019-10-28 02:11:50 +00:00
|
|
|
found = false
|
|
|
|
for _, alreadyAssignee := range assignees {
|
|
|
|
if assignee.ID == alreadyAssignee.ID {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
2021-07-08 11:38:13 +00:00
|
|
|
// This function also does comments and hooks, which is why we call it separately instead of directly removing the assignees here
|
2023-08-10 02:39:21 +00:00
|
|
|
if _, _, err := ToggleAssigneeWithNotify(ctx, issue, doer, assignee.ID); err != nil {
|
2019-10-28 02:11:50 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-10 02:39:21 +00:00
|
|
|
// ToggleAssigneeWithNoNotify changes a user between assigned and not assigned for this issue, and make issue comment for it.
|
|
|
|
func ToggleAssigneeWithNotify(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *issues_model.Comment, err error) {
|
2023-04-14 18:18:28 +00:00
|
|
|
removed, comment, err = issues_model.ToggleIssueAssignee(ctx, issue, doer, assigneeID)
|
2019-10-28 02:11:50 +00:00
|
|
|
if err != nil {
|
2023-07-07 05:31:56 +00:00
|
|
|
return false, nil, err
|
2019-10-28 02:11:50 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 05:31:56 +00:00
|
|
|
assignee, err := user_model.GetUserByID(ctx, assigneeID)
|
|
|
|
if err != nil {
|
|
|
|
return false, nil, err
|
2019-10-28 02:11:50 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 18:37:47 +00:00
|
|
|
notify_service.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
2019-10-28 02:11:50 +00:00
|
|
|
|
2022-06-20 10:02:49 +00:00
|
|
|
return removed, comment, err
|
2019-10-28 02:11:50 +00:00
|
|
|
}
|