[MM-16159] Migrate "Team.GetByName" to Sync by default (#11107)
* [MM-16159] Migrate "Team.GetByName" to Sync by default * Refactor to correct mistakes and remove irrelevant code
Этот коммит содержится в:
коммит произвёл
Elias Nahum
родитель
3b03c9afcb
Коммит
88202a76d9
@@ -1208,12 +1208,13 @@ func (a *App) GetChannelsByNames(channelNames []string, teamId string) ([]*model
|
||||
func (a *App) GetChannelByNameForTeamName(channelName, teamName string, includeDeleted bool) (*model.Channel, *model.AppError) {
|
||||
var team *model.Team
|
||||
|
||||
result := <-a.Srv.Store.Team().GetByName(teamName)
|
||||
if result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
team, err := a.Srv.Store.Team().GetByName(teamName)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
}
|
||||
team = result.Data.(*model.Team)
|
||||
|
||||
var result store.StoreResult
|
||||
|
||||
if includeDeleted {
|
||||
result = <-a.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, channelName, false)
|
||||
|
||||
@@ -140,19 +140,19 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu
|
||||
continue
|
||||
}
|
||||
|
||||
result := <-job.server.Store.Team().GetByName(notifications[0].teamName)
|
||||
if result.Err != nil {
|
||||
mlog.Error(fmt.Sprint("Unable to find Team id for notification", result.Err))
|
||||
team, err := job.server.Store.Team().GetByName(notifications[0].teamName)
|
||||
if err != nil {
|
||||
mlog.Error(fmt.Sprint("Unable to find Team id for notification", err))
|
||||
continue
|
||||
}
|
||||
|
||||
if team, ok := result.Data.(*model.Team); ok {
|
||||
if team != nil {
|
||||
inspectedTeamNames[notification.teamName] = team.Id
|
||||
}
|
||||
|
||||
// if the user has viewed any channels in this team since the notification was queued, delete
|
||||
// all queued notifications
|
||||
result = <-job.server.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
|
||||
result := <-job.server.Store.Channel().GetMembersForUser(inspectedTeamNames[notification.teamName], userId)
|
||||
if result.Err != nil {
|
||||
mlog.Error(fmt.Sprint("Unable to find ChannelMembers for user", result.Err))
|
||||
continue
|
||||
|
||||
@@ -162,9 +162,9 @@ func (a *App) ImportTeam(data *TeamImportData, dryRun bool) *model.AppError {
|
||||
}
|
||||
|
||||
var team *model.Team
|
||||
if result := <-a.Srv.Store.Team().GetByName(*data.Name); result.Err == nil {
|
||||
team = result.Data.(*model.Team)
|
||||
} else {
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Name)
|
||||
|
||||
if err != nil {
|
||||
team = &model.Team{}
|
||||
}
|
||||
|
||||
@@ -220,11 +220,10 @@ func (a *App) ImportChannel(data *ChannelImportData, dryRun bool) *model.AppErro
|
||||
return nil
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.Team().GetByName(*data.Team)
|
||||
if result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_channel.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, result.Err.Error(), http.StatusBadRequest)
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Team)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_channel.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
team := result.Data.(*model.Team)
|
||||
|
||||
var channel *model.Channel
|
||||
if result := <-a.Srv.Store.Channel().GetByNameIncludeDeleted(team.Id, *data.Name, true); result.Err == nil {
|
||||
@@ -942,13 +941,12 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.Team().GetByName(*data.Team)
|
||||
if result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, result.Err.Error(), http.StatusBadRequest)
|
||||
team, err := a.Srv.Store.Team().GetByName(*data.Team)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.team_not_found.error", map[string]interface{}{"TeamName": *data.Team}, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
team := result.Data.(*model.Team)
|
||||
|
||||
result = <-a.Srv.Store.Channel().GetByName(team.Id, *data.Channel, false)
|
||||
result := <-a.Srv.Store.Channel().GetByName(team.Id, *data.Channel, false)
|
||||
if result.Err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.import_post.channel_not_found.error", map[string]interface{}{"ChannelName": *data.Channel}, result.Err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
12
app/team.go
12
app/team.go
@@ -592,12 +592,12 @@ func (a *App) GetTeam(teamId string) (*model.Team, *model.AppError) {
|
||||
}
|
||||
|
||||
func (a *App) GetTeamByName(name string) (*model.Team, *model.AppError) {
|
||||
result := <-a.Srv.Store.Team().GetByName(name)
|
||||
if result.Err != nil {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
return nil, result.Err
|
||||
team, err := a.Srv.Store.Team().GetByName(name)
|
||||
if err != nil {
|
||||
err.StatusCode = http.StatusNotFound
|
||||
return nil, err
|
||||
}
|
||||
return result.Data.(*model.Team), nil
|
||||
return team, nil
|
||||
}
|
||||
|
||||
func (a *App) GetTeamByInviteId(inviteId string) (*model.Team, *model.AppError) {
|
||||
@@ -1045,7 +1045,7 @@ func (a *App) InviteNewUsersToTeam(emailList []string, teamId, senderId string)
|
||||
}
|
||||
|
||||
func (a *App) FindTeamByName(name string) bool {
|
||||
if result := <-a.Srv.Store.Team().GetByName(name); result.Err != nil {
|
||||
if _, err := a.Srv.Store.Team().GetByName(name); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
Ссылка в новой задаче
Block a user