Skip to content

Commit 330c7e2

Browse files
committed
fix
1 parent 71a2a67 commit 330c7e2

File tree

19 files changed

+116
-119
lines changed

19 files changed

+116
-119
lines changed

models/db/search.go

-9
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,3 @@ const (
2929
// NoConditionID means a condition to filter the records which don't match any id.
3030
// eg: "milestone_id=-1" means "find the items without any milestone.
3131
const NoConditionID int64 = -1
32-
33-
// AnyConditionID means a condition to filter the records which match any id.
34-
// The inverse of the above NoConditionID
35-
// eg: "assignee_id=-1000001" means "find the issues with an assignee"
36-
const AnyConditionID int64 = -1000001
37-
38-
// NonExistingID means a condition to match no result (eg: a non-existing user)
39-
// It doesn't use -1 or -2 because they are used as builtin users.
40-
const NonExistingID int64 = -1000000

models/issues/issue_search.go

+12-17
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ type IssuesOptions struct { //nolint
2727
RepoIDs []int64 // overwrites RepoCond if the length is not 0
2828
AllPublic bool // include also all public repositories
2929
RepoCond builder.Cond
30-
AssigneeID optional.Option[int64]
31-
PosterID optional.Option[int64]
30+
AssigneeID string // "(none)" or "(any)" or a user ID
31+
PosterID string // "(none)" or "(any)" or a user ID
3232
MentionedID int64
3333
ReviewRequestedID int64
3434
ReviewedID int64
@@ -356,28 +356,23 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, owner *user_mod
356356
return cond
357357
}
358358

359-
func applyAssigneeCondition(sess *xorm.Session, assigneeID optional.Option[int64]) {
359+
func applyAssigneeCondition(sess *xorm.Session, assigneeID string) {
360360
// old logic: 0 is also treated as "not filtering assignee", because the "assignee" was read as FormInt64
361-
if !assigneeID.Has() || assigneeID.Value() == 0 {
362-
return
363-
}
364-
if assigneeID.Value() == db.NoConditionID {
361+
if assigneeID == "(none)" {
365362
sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
366-
} else if assigneeID.Value() == db.AnyConditionID {
363+
} else if assigneeID == "(any)" {
367364
sess.Where("issue.id IN (SELECT issue_id FROM issue_assignees)")
368-
} else {
365+
} else if assigneeIDInt64, _ := strconv.ParseInt(assigneeID, 10, 64); assigneeIDInt64 > 0 {
369366
sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
370-
And("issue_assignees.assignee_id = ?", assigneeID.Value())
367+
And("issue_assignees.assignee_id = ?", assigneeIDInt64)
371368
}
372369
}
373370

374-
func applyPosterCondition(sess *xorm.Session, posterID optional.Option[int64]) {
375-
if !posterID.Has() {
376-
return
377-
}
378-
// poster doesn't need to support db.NoConditionID(-1), so just use the value as-is
379-
if posterID.Has() {
380-
sess.And("issue.poster_id=?", posterID.Value())
371+
func applyPosterCondition(sess *xorm.Session, posterID string) {
372+
if posterID == "(none)" {
373+
sess.And("issue.poster_id=0")
374+
} else if posterIDInt64, _ := strconv.ParseInt(posterID, 10, 64); posterIDInt64 > 0 {
375+
sess.And("issue.poster_id=?", posterIDInt64)
381376
}
382377
}
383378

modules/indexer/issues/bleve/bleve.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package bleve
55

66
import (
77
"context"
8+
"strconv"
89

910
"code.gitea.io/gitea/modules/indexer"
1011
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
@@ -247,14 +248,20 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
247248
queries = append(queries, inner_bleve.NumericEqualityQuery(options.ProjectColumnID.Value(), "project_board_id"))
248249
}
249250

250-
if options.PosterID.Has() {
251-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.PosterID.Value(), "poster_id"))
251+
if options.PosterID != "" {
252+
// "(none)" becomes 0, it means no poster
253+
posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
254+
queries = append(queries, inner_bleve.NumericEqualityQuery(posterIDInt64, "poster_id"))
252255
}
253256

254-
if options.AnyAssigneeOnly {
255-
queries = append(queries, inner_bleve.NumericRangeInclusiveQuery(optional.Some[int64](1), optional.None[int64](), "assignee_id"))
256-
} else if options.AssigneeID.Has() {
257-
queries = append(queries, inner_bleve.NumericEqualityQuery(options.AssigneeID.Value(), "assignee_id"))
257+
if options.AssigneeID != "" {
258+
if options.AssigneeID == "(any)" {
259+
queries = append(queries, inner_bleve.NumericRangeInclusiveQuery(optional.Some[int64](1), optional.None[int64](), "assignee_id"))
260+
} else {
261+
// "(none)" becomes 0, it means no assignee
262+
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
263+
queries = append(queries, inner_bleve.NumericEqualityQuery(assigneeIDInt64, "assignee_id"))
264+
}
258265
}
259266

260267
if options.MentionID.Has() {

modules/indexer/issues/db/options.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,12 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
4949
return value
5050
}
5151

52-
assigneeID := optional.Some(convertID(options.AssigneeID))
53-
if options.AnyAssigneeOnly {
54-
assigneeID = optional.Some(db.AnyConditionID)
55-
}
56-
5752
opts := &issue_model.IssuesOptions{
5853
Paginator: options.Paginator,
5954
RepoIDs: options.RepoIDs,
6055
AllPublic: options.AllPublic,
6156
RepoCond: nil,
62-
AssigneeID: assigneeID,
57+
AssigneeID: options.AssigneeID,
6358
PosterID: options.PosterID,
6459
MentionedID: convertID(options.MentionID),
6560
ReviewRequestedID: convertID(options.ReviewRequestedID),

modules/indexer/issues/dboptions.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,7 @@ func ToSearchOptions(keyword string, opts *issues_model.IssuesOptions) *SearchOp
4545
searchOpt.ProjectID = optional.Some[int64](0) // Those issues with no project(projectid==0)
4646
}
4747

48-
if opts.AssigneeID.Value() == db.NoConditionID {
49-
searchOpt.AssigneeID = optional.Some[int64](0) // FIXME: this is inconsistent from other places, 0 means "no assignee"
50-
} else if opts.AssigneeID.Value() == db.AnyConditionID {
51-
searchOpt.AnyAssigneeOnly = true
52-
} else if opts.AssigneeID.Value() != 0 {
53-
searchOpt.AssigneeID = opts.AssigneeID
54-
}
48+
searchOpt.AssigneeID = opts.AssigneeID
5549

5650
// See the comment of issues_model.SearchOptions for the reason why we need to convert
5751
convertID := func(id int64) optional.Option[int64] {

modules/indexer/issues/elasticsearch/elasticsearch.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,22 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
212212
query.Must(elastic.NewTermQuery("project_board_id", options.ProjectColumnID.Value()))
213213
}
214214

215-
if options.PosterID.Has() {
216-
query.Must(elastic.NewTermQuery("poster_id", options.PosterID.Value()))
215+
if options.PosterID != "" {
216+
// "(none)" becomes 0, it means no poster
217+
posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
218+
query.Must(elastic.NewTermQuery("poster_id", posterIDInt64))
217219
}
218220

219-
if options.AnyAssigneeOnly {
220-
q := elastic.NewRangeQuery("assignee_id")
221-
q.Gte(1)
222-
query.Must(q)
223-
} else if options.AssigneeID.Has() {
224-
query.Must(elastic.NewTermQuery("assignee_id", options.AssigneeID.Value()))
221+
if options.AssigneeID != "" {
222+
if options.AssigneeID == "(any)" {
223+
q := elastic.NewRangeQuery("assignee_id")
224+
q.Gte(1)
225+
query.Must(q)
226+
} else {
227+
// "(none)" becomes 0, it means no assignee
228+
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
229+
query.Must(elastic.NewTermQuery("assignee_id", assigneeIDInt64))
230+
}
225231
}
226232

227233
if options.MentionID.Has() {

modules/indexer/issues/internal/model.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ type SearchOptions struct {
9797
ProjectID optional.Option[int64] // project the issues belong to
9898
ProjectColumnID optional.Option[int64] // project column the issues belong to
9999

100-
PosterID optional.Option[int64] // poster of the issues
101-
102-
AssigneeID optional.Option[int64] // assignee of the issues, zero means no assignee
103-
AnyAssigneeOnly bool // if the issues have any assignee (non-zero), if true, AssigneeID will be ignored
100+
PosterID string // poster of the issues, "(none)" or "(any)" or a user ID
101+
AssigneeID string // assignee of the issues, "(none)" or "(any)" or a user ID
104102

105103
MentionID optional.Option[int64] // mentioned user of the issues
106104

modules/indexer/issues/meilisearch/meilisearch.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,20 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
187187
query.And(inner_meilisearch.NewFilterEq("project_board_id", options.ProjectColumnID.Value()))
188188
}
189189

190-
if options.PosterID.Has() {
191-
query.And(inner_meilisearch.NewFilterEq("poster_id", options.PosterID.Value()))
192-
}
193-
194-
if options.AnyAssigneeOnly {
195-
query.And(inner_meilisearch.NewFilterGte("assignee_id", 1))
196-
} else if options.AssigneeID.Has() {
197-
query.And(inner_meilisearch.NewFilterEq("assignee_id", options.AssigneeID.Value()))
190+
if options.PosterID != "" {
191+
// "(none)" becomes 0, it means no poster
192+
posterIDInt64, _ := strconv.ParseInt(options.PosterID, 10, 64)
193+
query.And(inner_meilisearch.NewFilterEq("poster_id", posterIDInt64))
194+
}
195+
196+
if options.AssigneeID != "" {
197+
if options.AssigneeID == "(any)" {
198+
query.And(inner_meilisearch.NewFilterGte("assignee_id", 1))
199+
} else {
200+
// "(none)" becomes 0, it means no assignee
201+
assigneeIDInt64, _ := strconv.ParseInt(options.AssigneeID, 10, 64)
202+
query.And(inner_meilisearch.NewFilterEq("assignee_id", assigneeIDInt64))
203+
}
198204
}
199205

200206
if options.MentionID.Has() {

options/locale/locale_en-US.ini

+2-3
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,8 @@ issues.filter_project = Project
15471547
issues.filter_project_all = All projects
15481548
issues.filter_project_none = No project
15491549
issues.filter_assignee = Assignee
1550-
issues.filter_assginee_no_select = All assignees
1551-
issues.filter_assginee_no_assignee = No assignee
1552-
issues.filter_assignee_any_assignee = Any assignee
1550+
issues.filter_assginee_no_assignee = Assigned to nobody
1551+
issues.filter_assignee_any_assignee = Assigned to anybody
15531552
issues.filter_poster = Author
15541553
issues.filter_user_placeholder = Search users
15551554
issues.filter_user_no_select = All users

routers/api/v1/repo/issue.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ func SearchIssues(ctx *context.APIContext) {
290290
if ctx.IsSigned {
291291
ctxUserID := ctx.Doer.ID
292292
if ctx.FormBool("created") {
293-
searchOpt.PosterID = optional.Some(ctxUserID)
293+
searchOpt.PosterID = strconv.FormatInt(ctxUserID, 10)
294294
}
295295
if ctx.FormBool("assigned") {
296-
searchOpt.AssigneeID = optional.Some(ctxUserID)
296+
searchOpt.AssigneeID = strconv.FormatInt(ctxUserID, 10)
297297
}
298298
if ctx.FormBool("mentioned") {
299299
searchOpt.MentionID = optional.Some(ctxUserID)
@@ -538,10 +538,10 @@ func ListIssues(ctx *context.APIContext) {
538538
}
539539

540540
if createdByID > 0 {
541-
searchOpt.PosterID = optional.Some(createdByID)
541+
searchOpt.PosterID = strconv.FormatInt(createdByID, 10)
542542
}
543543
if assignedByID > 0 {
544-
searchOpt.AssigneeID = optional.Some(assignedByID)
544+
searchOpt.AssigneeID = strconv.FormatInt(assignedByID, 64)
545545
}
546546
if mentionedByID > 0 {
547547
searchOpt.MentionID = optional.Some(mentionedByID)

routers/web/org/projects.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ func ViewProject(ctx *context.Context) {
347347
if ctx.Written() {
348348
return
349349
}
350-
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
350+
assigneeID := ctx.FormString("assignee")
351351

352352
opts := issues_model.IssuesOptions{
353353
LabelIDs: labelIDs,
354-
AssigneeID: optional.Some(assigneeID),
354+
AssigneeID: assigneeID,
355355
Owner: project.Owner,
356356
Doer: ctx.Doer,
357357
}

routers/web/repo/issue_list.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ func SearchIssues(ctx *context.Context) {
208208
if ctx.IsSigned {
209209
ctxUserID := ctx.Doer.ID
210210
if ctx.FormBool("created") {
211-
searchOpt.PosterID = optional.Some(ctxUserID)
211+
searchOpt.PosterID = strconv.FormatInt(ctxUserID, 10)
212212
}
213213
if ctx.FormBool("assigned") {
214-
searchOpt.AssigneeID = optional.Some(ctxUserID)
214+
searchOpt.AssigneeID = strconv.FormatInt(ctxUserID, 10)
215215
}
216216
if ctx.FormBool("mentioned") {
217217
searchOpt.MentionID = optional.Some(ctxUserID)
@@ -373,10 +373,10 @@ func SearchRepoIssuesJSON(ctx *context.Context) {
373373
}
374374

375375
if createdByID > 0 {
376-
searchOpt.PosterID = optional.Some(createdByID)
376+
searchOpt.PosterID = strconv.FormatInt(createdByID, 10)
377377
}
378378
if assignedByID > 0 {
379-
searchOpt.AssigneeID = optional.Some(assignedByID)
379+
searchOpt.AssigneeID = strconv.FormatInt(assignedByID, 10)
380380
}
381381
if mentionedByID > 0 {
382382
searchOpt.MentionID = optional.Some(mentionedByID)
@@ -490,19 +490,19 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
490490
viewType = "all"
491491
}
492492

493-
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
493+
assigneeID := ctx.FormString("assignee")
494494
posterUsername := ctx.FormString("poster")
495495
posterUserID := shared_user.GetFilterUserIDByName(ctx, posterUsername)
496496
var mentionedID, reviewRequestedID, reviewedID int64
497497

498498
if ctx.IsSigned {
499499
switch viewType {
500500
case "created_by":
501-
posterUserID = optional.Some(ctx.Doer.ID)
501+
posterUserID = strconv.FormatInt(ctx.Doer.ID, 10)
502502
case "mentioned":
503503
mentionedID = ctx.Doer.ID
504504
case "assigned":
505-
assigneeID = ctx.Doer.ID
505+
assigneeID = fmt.Sprint(ctx.Doer.ID)
506506
case "review_requested":
507507
reviewRequestedID = ctx.Doer.ID
508508
case "reviewed_by":
@@ -532,7 +532,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
532532
LabelIDs: labelIDs,
533533
MilestoneIDs: mileIDs,
534534
ProjectID: projectID,
535-
AssigneeID: optional.Some(assigneeID),
535+
AssigneeID: assigneeID,
536536
MentionedID: mentionedID,
537537
PosterID: posterUserID,
538538
ReviewRequestedID: reviewRequestedID,
@@ -613,7 +613,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
613613
PageSize: setting.UI.IssuePagingNum,
614614
},
615615
RepoIDs: []int64{repo.ID},
616-
AssigneeID: optional.Some(assigneeID),
616+
AssigneeID: assigneeID,
617617
PosterID: posterUserID,
618618
MentionedID: mentionedID,
619619
ReviewRequestedID: reviewRequestedID,

routers/web/repo/projects.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ func ViewProject(ctx *context.Context) {
315315

316316
labelIDs := issue.PrepareFilterIssueLabels(ctx, ctx.Repo.Repository.ID, ctx.Repo.Owner)
317317

318-
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
318+
assigneeID := ctx.FormString("assignee")
319319

320320
issuesMap, err := project_service.LoadIssuesFromProject(ctx, project, &issues_model.IssuesOptions{
321321
RepoIDs: []int64{ctx.Repo.Repository.ID},
322322
LabelIDs: labelIDs,
323-
AssigneeID: optional.Some(assigneeID),
323+
AssigneeID: assigneeID,
324324
})
325325
if err != nil {
326326
ctx.ServerError("LoadIssuesOfColumns", err)

routers/web/shared/user/helper.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import (
88
"slices"
99
"strconv"
1010

11-
"code.gitea.io/gitea/models/db"
1211
"code.gitea.io/gitea/models/user"
13-
"code.gitea.io/gitea/modules/optional"
1412
)
1513

1614
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
@@ -34,19 +32,19 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
3432
// So it's better to make it work like GitHub: users could input username directly.
3533
// Since it only converts the username to ID directly and is only used internally (to search issues), so no permission check is needed.
3634
// Return values:
37-
// * nil: no filter
38-
// * some(id): match the id, the id could be -1 to match the issues without assignee
39-
// * some(NonExistingID): match no issue (due to the user doesn't exist)
40-
func GetFilterUserIDByName(ctx context.Context, name string) optional.Option[int64] {
35+
// * "": no filter
36+
// * "{the-id}": match the id
37+
// * "(none)": match no issue (due to the user doesn't exist)
38+
func GetFilterUserIDByName(ctx context.Context, name string) string {
4139
if name == "" {
42-
return optional.None[int64]()
40+
return ""
4341
}
4442
u, err := user.GetUserByName(ctx, name)
4543
if err != nil {
4644
if id, err := strconv.ParseInt(name, 10, 64); err == nil {
47-
return optional.Some(id)
45+
return strconv.FormatInt(id, 10)
4846
}
49-
return optional.Some(db.NonExistingID)
47+
return "(none)"
5048
}
51-
return optional.Some(u.ID)
49+
return strconv.FormatInt(u.ID, 10)
5250
}

0 commit comments

Comments
 (0)