[MM-26969] Add team filters to search teams (#15065)
* Add team filters to search teams Remove unneeded logs Add team filters to search teams * Use bool pointers for filters Re-add include group constrained Fix lint Return the union of filters
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fbde669dda
Коммит
c511042c0f
@@ -972,13 +972,13 @@ func (_m *TeamStore) SaveMultipleMembers(members []*model.TeamMember, maxUsersPe
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchAll provides a mock function with given fields: term
|
||||
func (_m *TeamStore) SearchAll(term string) ([]*model.Team, *model.AppError) {
|
||||
ret := _m.Called(term)
|
||||
// SearchAll provides a mock function with given fields: term, opts
|
||||
func (_m *TeamStore) SearchAll(term string, opts *model.TeamSearch) ([]*model.Team, *model.AppError) {
|
||||
ret := _m.Called(term, opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.Team); ok {
|
||||
r0 = rf(term)
|
||||
if rf, ok := ret.Get(0).(func(string, *model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(term, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -986,8 +986,8 @@ func (_m *TeamStore) SearchAll(term string) ([]*model.Team, *model.AppError) {
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||
r1 = rf(term)
|
||||
if rf, ok := ret.Get(1).(func(string, *model.TeamSearch) *model.AppError); ok {
|
||||
r1 = rf(term, opts)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
@@ -997,13 +997,13 @@ func (_m *TeamStore) SearchAll(term string) ([]*model.Team, *model.AppError) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SearchAllPaged provides a mock function with given fields: term, page, perPage
|
||||
func (_m *TeamStore) SearchAllPaged(term string, page int, perPage int) ([]*model.Team, int64, *model.AppError) {
|
||||
ret := _m.Called(term, page, perPage)
|
||||
// SearchAllPaged provides a mock function with given fields: term, opts
|
||||
func (_m *TeamStore) SearchAllPaged(term string, opts *model.TeamSearch) ([]*model.Team, int64, *model.AppError) {
|
||||
ret := _m.Called(term, opts)
|
||||
|
||||
var r0 []*model.Team
|
||||
if rf, ok := ret.Get(0).(func(string, int, int) []*model.Team); ok {
|
||||
r0 = rf(term, page, perPage)
|
||||
if rf, ok := ret.Get(0).(func(string, *model.TeamSearch) []*model.Team); ok {
|
||||
r0 = rf(term, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*model.Team)
|
||||
@@ -1011,15 +1011,15 @@ func (_m *TeamStore) SearchAllPaged(term string, page int, perPage int) ([]*mode
|
||||
}
|
||||
|
||||
var r1 int64
|
||||
if rf, ok := ret.Get(1).(func(string, int, int) int64); ok {
|
||||
r1 = rf(term, page, perPage)
|
||||
if rf, ok := ret.Get(1).(func(string, *model.TeamSearch) int64); ok {
|
||||
r1 = rf(term, opts)
|
||||
} else {
|
||||
r1 = ret.Get(1).(int64)
|
||||
}
|
||||
|
||||
var r2 *model.AppError
|
||||
if rf, ok := ret.Get(2).(func(string, int, int) *model.AppError); ok {
|
||||
r2 = rf(term, page, perPage)
|
||||
if rf, ok := ret.Get(2).(func(string, *model.TeamSearch) *model.AppError); ok {
|
||||
r2 = rf(term, opts)
|
||||
} else {
|
||||
if ret.Get(2) != nil {
|
||||
r2 = ret.Get(2).(*model.AppError)
|
||||
|
||||
@@ -222,7 +222,7 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
require.Nil(t, err)
|
||||
|
||||
p := model.Team{}
|
||||
p.DisplayName = "ADisplayName" + model.NewId()
|
||||
p.DisplayName = "BDisplayName" + model.NewId()
|
||||
p.Name = "zzzzzz-" + model.NewId() + "a"
|
||||
p.Email = MakeEmail()
|
||||
p.Type = model.TEAM_OPEN
|
||||
@@ -231,6 +231,17 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
_, err = ss.Team().Save(&p)
|
||||
require.Nil(t, err)
|
||||
|
||||
g := model.Team{}
|
||||
g.DisplayName = "CDisplayName" + model.NewId()
|
||||
g.Name = "zzzzzz-" + model.NewId() + "a"
|
||||
g.Email = MakeEmail()
|
||||
g.Type = model.TEAM_OPEN
|
||||
g.AllowOpenInvite = false
|
||||
g.GroupConstrained = model.NewBool(true)
|
||||
|
||||
_, err = ss.Team().Save(&g)
|
||||
require.Nil(t, err)
|
||||
|
||||
q := model.Team{}
|
||||
q.DisplayName = "CHOCOLATE"
|
||||
q.Name = "ilovecake"
|
||||
@@ -243,80 +254,130 @@ func testTeamStoreSearchAll(t *testing.T, ss store.Store) {
|
||||
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Term string
|
||||
Opts *model.TeamSearch
|
||||
ExpectedLenth int
|
||||
ExpectedFirstId string
|
||||
ExpectedTeamIds []string
|
||||
}{
|
||||
{
|
||||
"Search chocolate by display name",
|
||||
"ocola",
|
||||
&model.TeamSearch{Term: "ocola"},
|
||||
1,
|
||||
q.Id,
|
||||
[]string{q.Id},
|
||||
},
|
||||
{
|
||||
"Search chocolate by display name",
|
||||
"choc",
|
||||
&model.TeamSearch{Term: "choc"},
|
||||
1,
|
||||
q.Id,
|
||||
[]string{q.Id},
|
||||
},
|
||||
{
|
||||
"Search chocolate by display name",
|
||||
"late",
|
||||
&model.TeamSearch{Term: "late"},
|
||||
1,
|
||||
q.Id,
|
||||
[]string{q.Id},
|
||||
},
|
||||
{
|
||||
"Search chocolate by name",
|
||||
"ilov",
|
||||
&model.TeamSearch{Term: "ilov"},
|
||||
1,
|
||||
q.Id,
|
||||
[]string{q.Id},
|
||||
},
|
||||
{
|
||||
"Search chocolate by name",
|
||||
"ecake",
|
||||
&model.TeamSearch{Term: "ecake"},
|
||||
1,
|
||||
q.Id,
|
||||
[]string{q.Id},
|
||||
},
|
||||
{
|
||||
"Search for open team name",
|
||||
o.Name,
|
||||
&model.TeamSearch{Term: o.Name},
|
||||
1,
|
||||
o.Id,
|
||||
[]string{o.Id},
|
||||
},
|
||||
{
|
||||
"Search for open team displayName",
|
||||
o.DisplayName,
|
||||
&model.TeamSearch{Term: o.DisplayName},
|
||||
1,
|
||||
o.Id,
|
||||
[]string{o.Id},
|
||||
},
|
||||
{
|
||||
"Search for open team without results",
|
||||
"junk",
|
||||
&model.TeamSearch{Term: "junk"},
|
||||
0,
|
||||
"",
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
"Search for private team",
|
||||
p.DisplayName,
|
||||
&model.TeamSearch{Term: p.DisplayName},
|
||||
1,
|
||||
p.Id,
|
||||
[]string{p.Id},
|
||||
},
|
||||
{
|
||||
"Search for both teams",
|
||||
"zzzzzz",
|
||||
"Search for all 3 z teams",
|
||||
&model.TeamSearch{Term: "zzzzzz"},
|
||||
3,
|
||||
[]string{o.Id, p.Id, g.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by allow open invite",
|
||||
&model.TeamSearch{Term: "zzzzzz", AllowOpenInvite: model.NewBool(true)},
|
||||
1,
|
||||
[]string{o.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by allow open invite = false",
|
||||
&model.TeamSearch{Term: "zzzzzz", AllowOpenInvite: model.NewBool(false)},
|
||||
1,
|
||||
[]string{p.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by group constrained",
|
||||
&model.TeamSearch{Term: "zzzzzz", GroupConstrained: model.NewBool(true)},
|
||||
1,
|
||||
[]string{g.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by group constrained = false",
|
||||
&model.TeamSearch{Term: "zzzzzz", GroupConstrained: model.NewBool(false)},
|
||||
2,
|
||||
"",
|
||||
[]string{o.Id, p.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by allow open invite and include group constrained",
|
||||
&model.TeamSearch{Term: "zzzzzz", AllowOpenInvite: model.NewBool(true), GroupConstrained: model.NewBool(true)},
|
||||
2,
|
||||
[]string{o.Id, g.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by group constrained and not open invite",
|
||||
&model.TeamSearch{Term: "zzzzzz", GroupConstrained: model.NewBool(true), AllowOpenInvite: model.NewBool(false)},
|
||||
2,
|
||||
[]string{g.Id, p.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by group constrained false and open invite",
|
||||
&model.TeamSearch{Term: "zzzzzz", GroupConstrained: model.NewBool(false), AllowOpenInvite: model.NewBool(true)},
|
||||
2,
|
||||
[]string{o.Id, p.Id},
|
||||
},
|
||||
{
|
||||
"Search for all 3 teams filter by group constrained false and open invite false",
|
||||
&model.TeamSearch{Term: "zzzzzz", GroupConstrained: model.NewBool(false), AllowOpenInvite: model.NewBool(false)},
|
||||
2,
|
||||
[]string{p.Id, o.Id},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
r1, err := ss.Team().SearchAll(tc.Term)
|
||||
response, err := ss.Team().SearchAll(tc.Opts.Term, tc.Opts)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, tc.ExpectedLenth, len(r1))
|
||||
if tc.ExpectedFirstId != "" {
|
||||
assert.Equal(t, tc.ExpectedFirstId, r1[0].Id)
|
||||
require.Equal(t, tc.ExpectedLenth, len(response))
|
||||
responseTeamIds := []string{}
|
||||
for _, team := range response {
|
||||
responseTeamIds = append(responseTeamIds, team.Id)
|
||||
}
|
||||
require.ElementsMatch(t, tc.ExpectedTeamIds, responseTeamIds)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user