[MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default (#11103)

* [MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default

* Simplifying code
This commit is contained in:
Mounica Paladugu
2019-07-08 12:30:52 -07:00
committed by Jesús Espino
parent bed9102eb1
commit eddf48c848
5 changed files with 28 additions and 28 deletions

View File

@@ -626,11 +626,7 @@ func (a *App) GetAllTeamsPageWithCount(offset int, limit int) (*model.TeamsWithC
}
func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) {
result := <-a.Srv.Store.Team().GetAllPrivateTeamListing()
if result.Err != nil {
return nil, result.Err
}
return result.Data.([]*model.Team), nil
return a.Srv.Store.Team().GetAllPrivateTeamListing()
}
func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {

View File

@@ -388,22 +388,19 @@ func (s SqlTeamStore) GetTeamsByUserId(userId string) store.StoreChannel {
})
}
func (s SqlTeamStore) GetAllPrivateTeamListing() store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName"
func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) {
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName"
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName"
}
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName"
}
var data []*model.Team
if _, err := s.GetReplica().Select(&data, query); err != nil {
result.Err = model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
var data []*model.Team
if _, err := s.GetReplica().Select(&data, query); err != nil {
return nil, model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
}
result.Data = data
})
return data, nil
}
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {

View File

@@ -92,7 +92,7 @@ type TeamStore interface {
SearchPrivate(term string) ([]*model.Team, *model.AppError)
GetAll() ([]*model.Team, *model.AppError)
GetAllPage(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllPrivateTeamListing() StoreChannel
GetAllPrivateTeamListing() ([]*model.Team, *model.AppError)
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
GetAllTeamListing() StoreChannel
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)

View File

@@ -197,19 +197,28 @@ func (_m *TeamStore) GetAllPage(offset int, limit int) ([]*model.Team, *model.Ap
}
// GetAllPrivateTeamListing provides a mock function with given fields:
func (_m *TeamStore) GetAllPrivateTeamListing() store.StoreChannel {
func (_m *TeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) {
ret := _m.Called()
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
var r0 []*model.Team
if rf, ok := ret.Get(0).(func() []*model.Team); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).([]*model.Team)
}
}
return r0
var r1 *model.AppError
if rf, ok := ret.Get(1).(func() *model.AppError); ok {
r1 = rf()
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit

View File

@@ -619,11 +619,9 @@ func testGetAllPrivateTeamListing(t *testing.T, ss store.Store) {
_, err = ss.Team().Save(&o4)
require.Nil(t, err)
if r1 := <-ss.Team().GetAllPrivateTeamListing(); r1.Err != nil {
t.Fatal(r1.Err)
if teams, err := ss.Team().GetAllPrivateTeamListing(); err != nil {
t.Fatal(err)
} else {
teams := r1.Data.([]*model.Team)
for _, team := range teams {
if team.AllowOpenInvite {
t.Fatal("should have returned team with AllowOpenInvite as false")