aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/assignees.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-12-07 15:27:36 +0800
committerGitHub <noreply@github.com>2023-12-07 15:27:36 +0800
commitdd30d9d5c0f577cb6e084aae6de2752ad43474d8 (patch)
tree1e3799a672a23424484b849827ba39eae447856a /models/issues/assignees.go
parentbeb71f5ef6e8074dc744ac995c15f7b5947a3f2e (diff)
downloadgitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.tar.gz
gitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.zip
Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220)
The function `GetByBean` has an obvious defect that when the fields are empty values, it will be ignored. Then users will get a wrong result which is possibly used to make a security problem. To avoid the possibility, this PR removed function `GetByBean` and all references. And some new generic functions have been introduced to be used. The recommand usage like below. ```go // if query an object according id obj, err := db.GetByID[Object](ctx, id) // query with other conditions obj, err := db.Get[Object](ctx, builder.Eq{"a": a, "b":b}) ```
Diffstat (limited to 'models/issues/assignees.go')
-rw-r--r--models/issues/assignees.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/models/issues/assignees.go b/models/issues/assignees.go
index fdd0d6f227..60f32d9557 100644
--- a/models/issues/assignees.go
+++ b/models/issues/assignees.go
@@ -10,6 +10,8 @@ import (
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/util"
+
+ "xorm.io/builder"
)
// IssueAssignees saves all issue assignees
@@ -59,7 +61,7 @@ func GetAssigneeIDsByIssue(ctx context.Context, issueID int64) ([]int64, error)
// IsUserAssignedToIssue returns true when the user is assigned to the issue
func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.User) (isAssigned bool, err error) {
- return db.GetByBean(ctx, &IssueAssignees{IssueID: issue.ID, AssigneeID: user.ID})
+ return db.Exist[IssueAssignees](ctx, builder.Eq{"assignee_id": user.ID, "issue_id": issue.ID})
}
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.