MM-15289 Migrate command.GetByTeam to sync by default (#10740)
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
214e9d2ae0
Коммит
171058eb3d
@@ -87,12 +87,11 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *a.Config().ServiceSettings.EnableCommands {
|
if *a.Config().ServiceSettings.EnableCommands {
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
teamCmds := result.Data.([]*model.Command)
|
|
||||||
for _, cmd := range teamCmds {
|
for _, cmd := range teamCmds {
|
||||||
if cmd.AutoComplete && !seen[cmd.Id] {
|
if cmd.AutoComplete && !seen[cmd.Id] {
|
||||||
cmd.Sanitize()
|
cmd.Sanitize()
|
||||||
@@ -110,12 +109,7 @@ func (a *App) ListTeamCommands(teamId string) ([]*model.Command, *model.AppError
|
|||||||
return nil, model.NewAppError("ListTeamCommands", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
return nil, model.NewAppError("ListTeamCommands", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
return a.Srv.Store.Command().GetByTeam(teamId)
|
||||||
if result.Err != nil {
|
|
||||||
return nil, result.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.Data.([]*model.Command), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||||
@@ -140,11 +134,10 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *a.Config().ServiceSettings.EnableCommands {
|
if *a.Config().ServiceSettings.EnableCommands {
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
teamCmds := result.Data.([]*model.Command)
|
|
||||||
for _, cmd := range teamCmds {
|
for _, cmd := range teamCmds {
|
||||||
if !seen[cmd.Trigger] {
|
if !seen[cmd.Trigger] {
|
||||||
cmd.Sanitize()
|
cmd.Sanitize()
|
||||||
@@ -239,9 +232,9 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
|||||||
close(userChan)
|
close(userChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(args.TeamId)
|
teamCmds, err := a.Srv.Store.Command().GetByTeam(args.TeamId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, nil, result.Err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tr := <-teamChan
|
tr := <-teamChan
|
||||||
@@ -264,7 +257,6 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
|||||||
|
|
||||||
var cmd *model.Command
|
var cmd *model.Command
|
||||||
|
|
||||||
teamCmds := result.Data.([]*model.Command)
|
|
||||||
for _, teamCmd := range teamCmds {
|
for _, teamCmd := range teamCmds {
|
||||||
if trigger == teamCmd.Trigger {
|
if trigger == teamCmd.Trigger {
|
||||||
cmd = teamCmd
|
cmd = teamCmd
|
||||||
@@ -456,12 +448,11 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
|||||||
|
|
||||||
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
||||||
|
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(cmd.TeamId)
|
teamCmds, err := a.Srv.Store.Command().GetByTeam(cmd.TeamId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
teamCmds := result.Data.([]*model.Command)
|
|
||||||
for _, existingCommand := range teamCmds {
|
for _, existingCommand := range teamCmds {
|
||||||
if cmd.Trigger == existingCommand.Trigger {
|
if cmd.Trigger == existingCommand.Trigger {
|
||||||
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("CreateCommand", "api.command.duplicate_trigger.app_error", nil, "", http.StatusBadRequest)
|
||||||
@@ -475,7 +466,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = <-a.Srv.Store.Command().Save(cmd)
|
result := <-a.Srv.Store.Command().Save(cmd)
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return nil, result.Err
|
return nil, result.Err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,12 +257,11 @@ func listCommandCmdF(command *cobra.Command, args []string) error {
|
|||||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result := <-a.Srv.Store.Command().GetByTeam(team.Id)
|
commands, err := a.Srv.Store.Command().GetByTeam(team.Id)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
CommandPrintErrorln("Unable to list commands for '" + args[i] + "'")
|
CommandPrintErrorln("Unable to list commands for '" + args[i] + "'")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
commands := result.Data.([]*model.Command)
|
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
commandListItem := fmt.Sprintf("%s: %s (team: %s)", command.Id, command.DisplayName, team.Name)
|
commandListItem := fmt.Sprintf("%s: %s (team: %s)", command.Id, command.DisplayName, team.Name)
|
||||||
CommandPrettyPrintln(commandListItem)
|
CommandPrettyPrintln(commandListItem)
|
||||||
|
|||||||
@@ -76,16 +76,14 @@ func (s SqlCommandStore) Get(id string) store.StoreChannel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) GetByTeam(teamId string) store.StoreChannel {
|
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var commands []*model.Command
|
||||||
var commands []*model.Command
|
|
||||||
|
|
||||||
if _, err := s.GetReplica().Select(&commands, "SELECT * FROM Commands WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
|
if _, err := s.GetReplica().Select(&commands, "SELECT * FROM Commands WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||||
result.Err = model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Data = commands
|
return commands, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) store.StoreChannel {
|
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) store.StoreChannel {
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ type WebhookStore interface {
|
|||||||
type CommandStore interface {
|
type CommandStore interface {
|
||||||
Save(webhook *model.Command) StoreChannel
|
Save(webhook *model.Command) StoreChannel
|
||||||
Get(id string) StoreChannel
|
Get(id string) StoreChannel
|
||||||
GetByTeam(teamId string) StoreChannel
|
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
||||||
GetByTrigger(teamId string, trigger string) StoreChannel
|
GetByTrigger(teamId string, trigger string) StoreChannel
|
||||||
Delete(commandId string, time int64) StoreChannel
|
Delete(commandId string, time int64) StoreChannel
|
||||||
PermanentDeleteByTeam(teamId string) StoreChannel
|
PermanentDeleteByTeam(teamId string) StoreChannel
|
||||||
|
|||||||
@@ -72,18 +72,18 @@ func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
o1 = (<-ss.Command().Save(o1)).Data.(*model.Command)
|
o1 = (<-ss.Command().Save(o1)).Data.(*model.Command)
|
||||||
|
|
||||||
if r1 := <-ss.Command().GetByTeam(o1.TeamId); r1.Err != nil {
|
if r1, err := ss.Command().GetByTeam(o1.TeamId); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.([]*model.Command)[0].CreateAt != o1.CreateAt {
|
if r1[0].CreateAt != o1.CreateAt {
|
||||||
t.Fatal("invalid returned command")
|
t.Fatal("invalid returned command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-ss.Command().GetByTeam("123"); result.Err != nil {
|
if result, err := ss.Command().GetByTeam("123"); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if len(result.Data.([]*model.Command)) != 0 {
|
if len(result) != 0 {
|
||||||
t.Fatal("no commands should have returned")
|
t.Fatal("no commands should have returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,19 +62,28 @@ func (_m *CommandStore) Get(id string) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetByTeam provides a mock function with given fields: teamId
|
// GetByTeam provides a mock function with given fields: teamId
|
||||||
func (_m *CommandStore) GetByTeam(teamId string) store.StoreChannel {
|
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||||
ret := _m.Called(teamId)
|
ret := _m.Called(teamId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 []*model.Command
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
|
||||||
r0 = rf(teamId)
|
r0 = rf(teamId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).([]*model.Command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByTrigger provides a mock function with given fields: teamId, trigger
|
// GetByTrigger provides a mock function with given fields: teamId, trigger
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user