[MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default (#11103)
* [MM-16166] Migrate Team.GetAllPrivateTeamListing to Sync by default * Simplifying code
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
bed9102eb1
Коммит
eddf48c848
@@ -626,11 +626,7 @@ func (a *App) GetAllTeamsPageWithCount(offset int, limit int) (*model.TeamsWithC
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) {
|
func (a *App) GetAllPrivateTeams() ([]*model.Team, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Team().GetAllPrivateTeamListing()
|
return a.Srv.Store.Team().GetAllPrivateTeamListing()
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.Team), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {
|
func (a *App) GetAllPrivateTeamsPage(offset int, limit int) ([]*model.Team, *model.AppError) {
|
||||||
|
|||||||
@@ -388,22 +388,19 @@ func (s SqlTeamStore) GetTeamsByUserId(userId string) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) GetAllPrivateTeamListing() store.StoreChannel {
|
func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName"
|
||||||
query := "SELECT * FROM Teams WHERE AllowOpenInvite = 0 ORDER BY DisplayName"
|
|
||||||
|
|
||||||
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
if s.DriverName() == model.DATABASE_DRIVER_POSTGRES {
|
||||||
query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName"
|
query = "SELECT * FROM Teams WHERE AllowOpenInvite = false ORDER BY DisplayName"
|
||||||
}
|
}
|
||||||
|
|
||||||
var data []*model.Team
|
var data []*model.Team
|
||||||
if _, err := s.GetReplica().Select(&data, query); err != nil {
|
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 nil, model.NewAppError("SqlTeamStore.GetAllPrivateTeamListing", "store.sql_team.get_all_private_team_listing.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result.Data = data
|
return data, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
|
func (s SqlTeamStore) GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ type TeamStore interface {
|
|||||||
SearchPrivate(term string) ([]*model.Team, *model.AppError)
|
SearchPrivate(term string) ([]*model.Team, *model.AppError)
|
||||||
GetAll() ([]*model.Team, *model.AppError)
|
GetAll() ([]*model.Team, *model.AppError)
|
||||||
GetAllPage(offset int, limit int) ([]*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)
|
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetAllTeamListing() StoreChannel
|
GetAllTeamListing() StoreChannel
|
||||||
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
|
|||||||
@@ -197,19 +197,28 @@ func (_m *TeamStore) GetAllPage(offset int, limit int) ([]*model.Team, *model.Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllPrivateTeamListing provides a mock function with given fields:
|
// 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()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Team
|
||||||
if rf, ok := ret.Get(0).(func() store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func() []*model.Team); ok {
|
||||||
r0 = rf()
|
r0 = rf()
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
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
|
// GetAllPrivateTeamPageListing provides a mock function with given fields: offset, limit
|
||||||
|
|||||||
@@ -619,11 +619,9 @@ func testGetAllPrivateTeamListing(t *testing.T, ss store.Store) {
|
|||||||
_, err = ss.Team().Save(&o4)
|
_, err = ss.Team().Save(&o4)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Team().GetAllPrivateTeamListing(); r1.Err != nil {
|
if teams, err := ss.Team().GetAllPrivateTeamListing(); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
teams := r1.Data.([]*model.Team)
|
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, team := range teams {
|
||||||
if team.AllowOpenInvite {
|
if team.AllowOpenInvite {
|
||||||
t.Fatal("should have returned team with AllowOpenInvite as false")
|
t.Fatal("should have returned team with AllowOpenInvite as false")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user