mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-15289 Migrate command.GetByTeam to sync by default (#10740)
This commit is contained in:
committed by
Jesús Espino
parent
214e9d2ae0
commit
171058eb3d
@@ -87,12 +87,11 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnableCommands {
|
||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
for _, cmd := range teamCmds {
|
||||
if cmd.AutoComplete && !seen[cmd.Id] {
|
||||
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)
|
||||
}
|
||||
|
||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
return result.Data.([]*model.Command), nil
|
||||
return a.Srv.Store.Command().GetByTeam(teamId)
|
||||
}
|
||||
|
||||
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 {
|
||||
result := <-a.Srv.Store.Command().GetByTeam(teamId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
for _, cmd := range teamCmds {
|
||||
if !seen[cmd.Trigger] {
|
||||
cmd.Sanitize()
|
||||
@@ -239,9 +232,9 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
close(userChan)
|
||||
}()
|
||||
|
||||
result := <-a.Srv.Store.Command().GetByTeam(args.TeamId)
|
||||
if result.Err != nil {
|
||||
return nil, nil, result.Err
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(args.TeamId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
tr := <-teamChan
|
||||
@@ -264,7 +257,6 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
|
||||
|
||||
var cmd *model.Command
|
||||
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
for _, teamCmd := range teamCmds {
|
||||
if trigger == teamCmd.Trigger {
|
||||
cmd = teamCmd
|
||||
@@ -456,12 +448,11 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
|
||||
|
||||
cmd.Trigger = strings.ToLower(cmd.Trigger)
|
||||
|
||||
result := <-a.Srv.Store.Command().GetByTeam(cmd.TeamId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
teamCmds, err := a.Srv.Store.Command().GetByTeam(cmd.TeamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
teamCmds := result.Data.([]*model.Command)
|
||||
for _, existingCommand := range teamCmds {
|
||||
if cmd.Trigger == existingCommand.Trigger {
|
||||
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 {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
@@ -257,12 +257,11 @@ func listCommandCmdF(command *cobra.Command, args []string) error {
|
||||
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
result := <-a.Srv.Store.Command().GetByTeam(team.Id)
|
||||
if result.Err != nil {
|
||||
commands, err := a.Srv.Store.Command().GetByTeam(team.Id)
|
||||
if err != nil {
|
||||
CommandPrintErrorln("Unable to list commands for '" + args[i] + "'")
|
||||
continue
|
||||
}
|
||||
commands := result.Data.([]*model.Command)
|
||||
for _, command := range commands {
|
||||
commandListItem := fmt.Sprintf("%s: %s (team: %s)", command.Id, command.DisplayName, team.Name)
|
||||
CommandPrettyPrintln(commandListItem)
|
||||
|
||||
@@ -76,16 +76,14 @@ func (s SqlCommandStore) Get(id string) store.StoreChannel {
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlCommandStore) GetByTeam(teamId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var commands []*model.Command
|
||||
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
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 {
|
||||
result.Err = model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
if _, err := s.GetReplica().Select(&commands, "SELECT * FROM Commands WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
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 {
|
||||
|
||||
@@ -406,7 +406,7 @@ type WebhookStore interface {
|
||||
type CommandStore interface {
|
||||
Save(webhook *model.Command) StoreChannel
|
||||
Get(id string) StoreChannel
|
||||
GetByTeam(teamId string) StoreChannel
|
||||
GetByTeam(teamId string) ([]*model.Command, *model.AppError)
|
||||
GetByTrigger(teamId string, trigger string) StoreChannel
|
||||
Delete(commandId string, time int64) 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)
|
||||
|
||||
if r1 := <-ss.Command().GetByTeam(o1.TeamId); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Command().GetByTeam(o1.TeamId); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.([]*model.Command)[0].CreateAt != o1.CreateAt {
|
||||
if r1[0].CreateAt != o1.CreateAt {
|
||||
t.Fatal("invalid returned command")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-ss.Command().GetByTeam("123"); result.Err != nil {
|
||||
t.Fatal(result.Err)
|
||||
if result, err := ss.Command().GetByTeam("123"); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(result.Data.([]*model.Command)) != 0 {
|
||||
if len(result) != 0 {
|
||||
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
|
||||
func (_m *CommandStore) GetByTeam(teamId string) store.StoreChannel {
|
||||
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) {
|
||||
ret := _m.Called(teamId)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
||||
var r0 []*model.Command
|
||||
if rf, ok := ret.Get(0).(func(string) []*model.Command); ok {
|
||||
r0 = rf(teamId)
|
||||
} else {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user