[MM-16170] Migrate Team.GetTeamsByUserId to Sync by default (#11100)
* [MM-16170] Migrate Team.GetTeamsByUserId to Sync by default * Fixing comments
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
0ec609d159
Коммит
ff89b2c8e1
@@ -192,13 +192,12 @@ func (a *App) FindTeamIdForFilename(post *model.Post, filename string) string {
|
|||||||
name, _ := url.QueryUnescape(split[4])
|
name, _ := url.QueryUnescape(split[4])
|
||||||
|
|
||||||
// This post is in a direct channel so we need to figure out what team the files are stored under.
|
// This post is in a direct channel so we need to figure out what team the files are stored under.
|
||||||
result := <-a.Srv.Store.Team().GetTeamsByUserId(post.UserId)
|
teams, err := a.Srv.Store.Team().GetTeamsByUserId(post.UserId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
mlog.Error(fmt.Sprintf("Unable to get teams when migrating post to use FileInfo, err=%v", result.Err), mlog.String("post_id", post.Id))
|
mlog.Error(fmt.Sprintf("Unable to get teams when migrating post to use FileInfo, err=%v", err), mlog.String("post_id", post.Id))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
teams := result.Data.([]*model.Team)
|
|
||||||
if len(teams) == 1 {
|
if len(teams) == 1 {
|
||||||
// The user has only one team so the post must've been sent from it
|
// The user has only one team so the post must've been sent from it
|
||||||
return teams[0].Id
|
return teams[0].Id
|
||||||
|
|||||||
@@ -22,13 +22,12 @@ func (a *App) sendNotificationEmail(notification *postNotification, user *model.
|
|||||||
post := notification.post
|
post := notification.post
|
||||||
|
|
||||||
if channel.IsGroupOrDirect() {
|
if channel.IsGroupOrDirect() {
|
||||||
result := <-a.Srv.Store.Team().GetTeamsByUserId(user.Id)
|
teams, err := a.Srv.Store.Team().GetTeamsByUserId(user.Id)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return result.Err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the recipient isn't in the current user's team, just pick one
|
// if the recipient isn't in the current user's team, just pick one
|
||||||
teams := result.Data.([]*model.Team)
|
|
||||||
found := false
|
found := false
|
||||||
|
|
||||||
for i := range teams {
|
for i := range teams {
|
||||||
|
|||||||
@@ -654,11 +654,7 @@ func (a *App) SearchPrivateTeams(term string) ([]*model.Team, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetTeamsForUser(userId string) ([]*model.Team, *model.AppError) {
|
func (a *App) GetTeamsForUser(userId string) ([]*model.Team, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Team().GetTeamsByUserId(userId)
|
return a.Srv.Store.Team().GetTeamsByUserId(userId)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
return result.Data.([]*model.Team), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) {
|
func (a *App) GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) {
|
||||||
|
|||||||
@@ -189,13 +189,13 @@ func (a *App) IsFirstUserAccount() bool {
|
|||||||
// indexUser fetches the required information to index a user from the database and
|
// indexUser fetches the required information to index a user from the database and
|
||||||
// calls the elasticsearch interface method
|
// calls the elasticsearch interface method
|
||||||
func (a *App) indexUser(user *model.User) *model.AppError {
|
func (a *App) indexUser(user *model.User) *model.AppError {
|
||||||
userTeams := <-a.Srv.Store.Team().GetTeamsByUserId(user.Id)
|
userTeams, err := a.Srv.Store.Team().GetTeamsByUserId(user.Id)
|
||||||
if userTeams.Err != nil {
|
if err != nil {
|
||||||
return userTeams.Err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
userTeamsIds := []string{}
|
userTeamsIds := []string{}
|
||||||
for _, team := range userTeams.Data.([]*model.Team) {
|
for _, team := range userTeams {
|
||||||
userTeamsIds = append(userTeamsIds, team.Id)
|
userTeamsIds = append(userTeamsIds, team.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,9 +71,8 @@ func TestLeaveTeam(t *testing.T) {
|
|||||||
t.Fatal("profile should not be on team")
|
t.Fatal("profile should not be on team")
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); result.Err != nil {
|
if teams, err := th.App.Srv.Store.Team().GetTeamsByUserId(th.BasicUser.Id); err != nil {
|
||||||
teamMembers := result.Data.([]*model.TeamMember)
|
if len(teams) > 0 {
|
||||||
if len(teamMembers) > 0 {
|
|
||||||
t.Fatal("Shouldn't be in team")
|
t.Fatal("Shouldn't be in team")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,16 +376,13 @@ func (s SqlTeamStore) GetAllPage(offset int, limit int) ([]*model.Team, *model.A
|
|||||||
return teams, nil
|
return teams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) GetTeamsByUserId(userId string) store.StoreChannel {
|
func (s SqlTeamStore) GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var teams []*model.Team
|
||||||
var data []*model.Team
|
if _, err := s.GetReplica().Select(&teams, "SELECT Teams.* FROM Teams, TeamMembers WHERE TeamMembers.TeamId = Teams.Id AND TeamMembers.UserId = :UserId AND TeamMembers.DeleteAt = 0 AND Teams.DeleteAt = 0", map[string]interface{}{"UserId": userId}); err != nil {
|
||||||
if _, err := s.GetReplica().Select(&data, "SELECT Teams.* FROM Teams, TeamMembers WHERE TeamMembers.TeamId = Teams.Id AND TeamMembers.UserId = :UserId AND TeamMembers.DeleteAt = 0 AND Teams.DeleteAt = 0", map[string]interface{}{"UserId": userId}); err != nil {
|
return nil, model.NewAppError("SqlTeamStore.GetTeamsByUserId", "store.sql_team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Err = model.NewAppError("SqlTeamStore.GetTeamsByUserId", "store.sql_team.get_all.app_error", nil, err.Error(), http.StatusInternalServerError)
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Data = data
|
return teams, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) {
|
func (s SqlTeamStore) GetAllPrivateTeamListing() ([]*model.Team, *model.AppError) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ type TeamStore interface {
|
|||||||
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetAllTeamListing() ([]*model.Team, *model.AppError)
|
GetAllTeamListing() ([]*model.Team, *model.AppError)
|
||||||
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError)
|
||||||
GetTeamsByUserId(userId string) StoreChannel
|
GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError)
|
||||||
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
GetByInviteId(inviteId string) (*model.Team, *model.AppError)
|
||||||
PermanentDelete(teamId string) *model.AppError
|
PermanentDelete(teamId string) *model.AppError
|
||||||
AnalyticsTeamCount() (int64, *model.AppError)
|
AnalyticsTeamCount() (int64, *model.AppError)
|
||||||
|
|||||||
@@ -522,19 +522,28 @@ func (_m *TeamStore) GetTeamsByScheme(schemeId string, offset int, limit int) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTeamsByUserId provides a mock function with given fields: userId
|
// GetTeamsByUserId provides a mock function with given fields: userId
|
||||||
func (_m *TeamStore) GetTeamsByUserId(userId string) store.StoreChannel {
|
func (_m *TeamStore) GetTeamsByUserId(userId string) ([]*model.Team, *model.AppError) {
|
||||||
ret := _m.Called(userId)
|
ret := _m.Called(userId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Team
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.Team); ok {
|
||||||
r0 = rf(userId)
|
r0 = rf(userId)
|
||||||
} 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(string) *model.AppError); ok {
|
||||||
|
r1 = rf(userId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTeamsForUser provides a mock function with given fields: userId
|
// GetTeamsForUser provides a mock function with given fields: userId
|
||||||
|
|||||||
@@ -431,10 +431,9 @@ func testTeamStoreByUserId(t *testing.T, ss store.Store) {
|
|||||||
m1 := &model.TeamMember{TeamId: o1.Id, UserId: model.NewId()}
|
m1 := &model.TeamMember{TeamId: o1.Id, UserId: model.NewId()}
|
||||||
store.Must(ss.Team().SaveMember(m1, -1))
|
store.Must(ss.Team().SaveMember(m1, -1))
|
||||||
|
|
||||||
if r1 := <-ss.Team().GetTeamsByUserId(m1.UserId); r1.Err != nil {
|
if teams, err := ss.Team().GetTeamsByUserId(m1.UserId); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
teams := r1.Data.([]*model.Team)
|
|
||||||
if len(teams) == 0 {
|
if len(teams) == 0 {
|
||||||
t.Fatal("Should return a team")
|
t.Fatal("Should return a team")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user