feat: search by assignee username instead of id
This commit is contained in:
parent
a273d1ae76
commit
7f28865903
3 changed files with 92 additions and 6 deletions
|
@ -214,6 +214,15 @@ func getNativeValueForTaskField(fieldName string, comparator taskFilterComparato
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if realFieldName == "Assignees" {
|
||||||
|
vals := strings.Split(value, ",")
|
||||||
|
valueSlice := []string{}
|
||||||
|
for _, val := range vals {
|
||||||
|
valueSlice = append(valueSlice, val)
|
||||||
|
}
|
||||||
|
return valueSlice, nil
|
||||||
|
}
|
||||||
|
|
||||||
field, ok := reflect.TypeOf(&Task{}).Elem().FieldByName(realFieldName)
|
field, ok := reflect.TypeOf(&Task{}).Elem().FieldByName(realFieldName)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrInvalidTaskField{TaskField: fieldName}
|
return nil, ErrInvalidTaskField{TaskField: fieldName}
|
||||||
|
|
|
@ -934,10 +934,10 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter assignees",
|
name: "filter assignees by username",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
FilterBy: []string{"assignees"},
|
FilterBy: []string{"assignees"},
|
||||||
FilterValue: []string{"1"},
|
FilterValue: []string{"user1"},
|
||||||
FilterComparator: []string{"equals"},
|
FilterComparator: []string{"equals"},
|
||||||
},
|
},
|
||||||
args: defaultArgs,
|
args: defaultArgs,
|
||||||
|
@ -947,13 +947,81 @@ func TestTaskCollection_ReadAll(t *testing.T) {
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "filter assignees in",
|
name: "filter assignees by username with users field name",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"users"},
|
||||||
|
FilterValue: []string{"user1"},
|
||||||
|
FilterComparator: []string{"equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: nil,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees by username with user_id field name",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"user_id"},
|
||||||
|
FilterValue: []string{"user1"},
|
||||||
|
FilterComparator: []string{"equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: nil,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees by multiple username",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"assignees", "assignees"},
|
||||||
|
FilterValue: []string{"user1", "user2"},
|
||||||
|
FilterComparator: []string{"equals", "equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: []*Task{
|
||||||
|
task30,
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees by numbers",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"assignees"},
|
||||||
|
FilterValue: []string{"1"},
|
||||||
|
FilterComparator: []string{"equals"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: []*Task{},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees by name with like",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"assignees"},
|
||||||
|
FilterValue: []string{"user"},
|
||||||
|
FilterComparator: []string{"like"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
|
want: []*Task{},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees in by id",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
FilterBy: []string{"assignees"},
|
FilterBy: []string{"assignees"},
|
||||||
FilterValue: []string{"1,2"},
|
FilterValue: []string{"1,2"},
|
||||||
FilterComparator: []string{"in"},
|
FilterComparator: []string{"in"},
|
||||||
},
|
},
|
||||||
args: defaultArgs,
|
args: defaultArgs,
|
||||||
|
want: []*Task{},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "filter assignees in by username",
|
||||||
|
fields: fields{
|
||||||
|
FilterBy: []string{"assignees"},
|
||||||
|
FilterValue: []string{"user1,user2"},
|
||||||
|
FilterComparator: []string{"in"},
|
||||||
|
},
|
||||||
|
args: defaultArgs,
|
||||||
want: []*Task{
|
want: []*Task{
|
||||||
task30,
|
task30,
|
||||||
},
|
},
|
||||||
|
|
|
@ -338,8 +338,11 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.field == "assignees" || f.field == "user_id" {
|
if f.field == "assignees" {
|
||||||
f.field = "user_id"
|
if f.comparator == taskFilterComparatorLike {
|
||||||
|
return nil, 0, 0, ErrInvalidTaskFilterValue{Field: f.field, Value: f.value}
|
||||||
|
}
|
||||||
|
f.field = "username"
|
||||||
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
filter, err := getFilterCond(f, opts.filterIncludeNulls)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
return nil, 0, 0, err
|
||||||
|
@ -430,7 +433,13 @@ func getRawTasksForLists(s *xorm.Session, lists []*List, a web.Auth, opts *taskO
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(assigneeFilters) > 0 {
|
if len(assigneeFilters) > 0 {
|
||||||
filters = append(filters, getFilterCondForSeparateTable("task_assignees", opts.filterConcat, assigneeFilters))
|
assigneeFilter := []builder.Cond{
|
||||||
|
builder.In("user_id",
|
||||||
|
builder.Select("id").
|
||||||
|
From("users").
|
||||||
|
Where(builder.Or(assigneeFilters...)),
|
||||||
|
)}
|
||||||
|
filters = append(filters, getFilterCondForSeparateTable("task_assignees", opts.filterConcat, assigneeFilter))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(labelFilters) > 0 {
|
if len(labelFilters) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue