MM-25476: Migrate AppError from command_store.go (#14643)

Automatic Merge
Этот коммит содержится в:
Joshua Bezaleel Abednego
2020-07-16 20:26:07 +07:00
коммит произвёл GitHub
родитель 5ddf8d4099
Коммит 48f0b7fd76
13 изменённых файлов: 353 добавлений и 257 удалений

Просмотреть файл

@@ -46,13 +46,13 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
openChan := make(chan store.StoreResult, 1) openChan := make(chan store.StoreResult, 1)
privateChan := make(chan store.StoreResult, 1) privateChan := make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN) count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
openChan <- store.StoreResult{Data: count, Err: err} openChan <- store.StoreResult{Data: count, Err: err2}
close(openChan) close(openChan)
}() }()
go func() { go func() {
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE) count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
privateChan <- store.StoreResult{Data: count, Err: err} privateChan <- store.StoreResult{Data: count, Err: err2}
close(privateChan) close(privateChan)
}() }()
@@ -61,15 +61,15 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if teamId == "" { if teamId == "" {
userInactiveChan = make(chan store.StoreResult, 1) userInactiveChan = make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.User().AnalyticsGetInactiveUsersCount() count, err2 := a.Srv().Store.User().AnalyticsGetInactiveUsersCount()
userInactiveChan <- store.StoreResult{Data: count, Err: err} userInactiveChan <- store.StoreResult{Data: count, Err: err2}
close(userInactiveChan) close(userInactiveChan)
}() }()
} else { } else {
userChan = make(chan store.StoreResult, 1) userChan = make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamId}) count, err2 := a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamId})
userChan <- store.StoreResult{Data: count, Err: err} userChan <- store.StoreResult{Data: count, Err: err2}
close(userChan) close(userChan)
}() }()
} }
@@ -78,30 +78,30 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if !skipIntensiveQueries { if !skipIntensiveQueries {
postChan = make(chan store.StoreResult, 1) postChan = make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false) count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false)
postChan <- store.StoreResult{Data: count, Err: err} postChan <- store.StoreResult{Data: count, Err: err2}
close(postChan) close(postChan)
}() }()
} }
teamCountChan := make(chan store.StoreResult, 1) teamCountChan := make(chan store.StoreResult, 1)
go func() { go func() {
teamCount, err := a.Srv().Store.Team().AnalyticsTeamCount(false) teamCount, err2 := a.Srv().Store.Team().AnalyticsTeamCount(false)
teamCountChan <- store.StoreResult{Data: teamCount, Err: err} teamCountChan <- store.StoreResult{Data: teamCount, Err: err2}
close(teamCountChan) close(teamCountChan)
}() }()
dailyActiveChan := make(chan store.StoreResult, 1) dailyActiveChan := make(chan store.StoreResult, 1)
go func() { go func() {
dailyActive, err := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}) dailyActive, err2 := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err} dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err2}
close(dailyActiveChan) close(dailyActiveChan)
}() }()
monthlyActiveChan := make(chan store.StoreResult, 1) monthlyActiveChan := make(chan store.StoreResult, 1)
go func() { go func() {
monthlyActive, err := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false}) monthlyActive, err2 := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err} monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err2}
close(monthlyActiveChan) close(monthlyActiveChan)
}() }()
@@ -155,9 +155,9 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
// If in HA mode then aggregate all the stats // If in HA mode then aggregate all the stats
if a.Cluster() != nil && *a.Config().ClusterSettings.Enable { if a.Cluster() != nil && *a.Config().ClusterSettings.Enable {
stats, err := a.Cluster().GetClusterStats() stats, err2 := a.Cluster().GetClusterStats()
if err != nil { if err2 != nil {
return nil, err return nil, err2
} }
totalSockets := a.TotalWebsocketConnections() totalSockets := a.TotalWebsocketConnections()
@@ -231,29 +231,29 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
iHookChan := make(chan store.StoreResult, 1) iHookChan := make(chan store.StoreResult, 1)
go func() { go func() {
c, err := a.Srv().Store.Webhook().AnalyticsIncomingCount(teamId) c, err2 := a.Srv().Store.Webhook().AnalyticsIncomingCount(teamId)
iHookChan <- store.StoreResult{Data: c, Err: err} iHookChan <- store.StoreResult{Data: c, Err: err2}
close(iHookChan) close(iHookChan)
}() }()
oHookChan := make(chan store.StoreResult, 1) oHookChan := make(chan store.StoreResult, 1)
go func() { go func() {
c, err := a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamId) c, err2 := a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamId)
oHookChan <- store.StoreResult{Data: c, Err: err} oHookChan <- store.StoreResult{Data: c, Err: err2}
close(oHookChan) close(oHookChan)
}() }()
commandChan := make(chan store.StoreResult, 1) commandChan := make(chan store.StoreResult, 1)
go func() { go func() {
c, err := a.Srv().Store.Command().AnalyticsCommandCount(teamId) c, nErr := a.Srv().Store.Command().AnalyticsCommandCount(teamId)
commandChan <- store.StoreResult{Data: c, Err: err} commandChan <- store.StoreResult{Data: c, NErr: nErr}
close(commandChan) close(commandChan)
}() }()
sessionChan := make(chan store.StoreResult, 1) sessionChan := make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Session().AnalyticsSessionCount() count, err2 := a.Srv().Store.Session().AnalyticsSessionCount()
sessionChan <- store.StoreResult{Data: count, NErr: err} sessionChan <- store.StoreResult{Data: count, NErr: err2}
close(sessionChan) close(sessionChan)
}() }()
@@ -263,15 +263,15 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if !skipIntensiveQueries { if !skipIntensiveQueries {
fileChan = make(chan store.StoreResult, 1) fileChan = make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false) count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false)
fileChan <- store.StoreResult{Data: count, Err: err} fileChan <- store.StoreResult{Data: count, Err: err2}
close(fileChan) close(fileChan)
}() }()
hashtagChan = make(chan store.StoreResult, 1) hashtagChan = make(chan store.StoreResult, 1)
go func() { go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true) count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true)
hashtagChan <- store.StoreResult{Data: count, Err: err} hashtagChan <- store.StoreResult{Data: count, Err: err2}
close(hashtagChan) close(hashtagChan)
}() }()
} }
@@ -309,8 +309,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
rows[3].Value = float64(r.Data.(int64)) rows[3].Value = float64(r.Data.(int64))
r = <-commandChan r = <-commandChan
if r.Err != nil { if r.NErr != nil {
return nil, r.Err return nil, model.NewAppError("GetAnalytics", "app.analytics.getanalytics.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
rows[4].Value = float64(r.Data.(int64)) rows[4].Value = float64(r.Data.(int64))

Просмотреть файл

@@ -88,7 +88,7 @@ func (a *App) ListAutocompleteCommands(teamId string, T goi18n.TranslateFunc) ([
if *a.Config().ServiceSettings.EnableCommands { if *a.Config().ServiceSettings.EnableCommands {
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId) teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("ListAutocompleteCommands", "app.command.listautocompletecommands.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
for _, cmd := range teamCmds { for _, cmd := range teamCmds {
@@ -119,7 +119,12 @@ 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)
} }
return a.Srv().Store.Command().GetByTeam(teamId) teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
if err != nil {
return nil, model.NewAppError("ListTeamCommands", "app.command.listteamcommands.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
return teamCmds, 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) {
@@ -146,7 +151,7 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
if *a.Config().ServiceSettings.EnableCommands { if *a.Config().ServiceSettings.EnableCommands {
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId) teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("ListAllCommands", "app.command.listallcommands.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
for _, cmd := range teamCmds { for _, cmd := range teamCmds {
if !seen[cmd.Trigger] { if !seen[cmd.Trigger] {
@@ -368,7 +373,7 @@ func (a *App) tryExecuteCustomCommand(args *model.CommandArgs, trigger string, m
teamCmds, err := a.Srv().Store.Command().GetByTeam(args.TeamId) teamCmds, err := a.Srv().Store.Command().GetByTeam(args.TeamId)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, model.NewAppError("tryExecuteCustomCommand", "app.command.tryexecutecustomcommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
tr := <-teamChan tr := <-teamChan
@@ -602,7 +607,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
teamCmds, err := a.Srv().Store.Command().GetByTeam(cmd.TeamId) teamCmds, err := a.Srv().Store.Command().GetByTeam(cmd.TeamId)
if err != nil { if err != nil {
return nil, err return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
for _, existingCommand := range teamCmds { for _, existingCommand := range teamCmds {
@@ -618,7 +623,18 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
} }
} }
return a.Srv().Store.Command().Save(cmd) command, nErr := a.Srv().Store.Command().Save(cmd)
if nErr != nil {
var appErr *model.AppError
switch {
case errors.As(nErr, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("CreateCommand", "app.command.createcommand.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
}
}
return command, nil
} }
func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) { func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
@@ -626,13 +642,17 @@ func (a *App) GetCommand(commandId string) (*model.Command, *model.AppError) {
return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented) return nil, model.NewAppError("GetCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
cmd, err := a.Srv().Store.Command().Get(commandId) command, err := a.Srv().Store.Command().Get(commandId)
if err != nil { if err != nil {
err.StatusCode = http.StatusNotFound var nfErr *store.ErrNotFound
return nil, err switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.get.missing.app_error", map[string]interface{}{"command_id": commandId}, "", http.StatusNotFound)
default:
return nil, model.NewAppError("GetCommand", "app.command.getcommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
} }
return command, nil
return cmd, nil
} }
func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) { func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command, *model.AppError) {
@@ -649,7 +669,21 @@ func (a *App) UpdateCommand(oldCmd, updatedCmd *model.Command) (*model.Command,
updatedCmd.CreatorId = oldCmd.CreatorId updatedCmd.CreatorId = oldCmd.CreatorId
updatedCmd.TeamId = oldCmd.TeamId updatedCmd.TeamId = oldCmd.TeamId
return a.Srv().Store.Command().Update(updatedCmd) command, err := a.Srv().Store.Command().Update(updatedCmd)
if err != nil {
var nfErr *store.ErrNotFound
var appErr *model.AppError
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]interface{}{"command_id": updatedCmd.Id}, "", http.StatusNotFound)
case errors.As(err, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("UpdateCommand", "app.command.updatecommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return command, nil
} }
func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError { func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppError {
@@ -657,7 +691,16 @@ func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppEr
_, err := a.Srv().Store.Command().Update(command) _, err := a.Srv().Store.Command().Update(command)
if err != nil { if err != nil {
return err var nfErr *store.ErrNotFound
var appErr *model.AppError
switch {
case errors.As(err, &nfErr):
return model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]interface{}{"command_id": command.Id}, "", http.StatusNotFound)
case errors.As(err, &appErr):
return appErr
default:
return model.NewAppError("MoveCommand", "app.command.movecommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
} }
return nil return nil
@@ -670,7 +713,21 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
cmd.Token = model.NewId() cmd.Token = model.NewId()
return a.Srv().Store.Command().Update(cmd) command, err := a.Srv().Store.Command().Update(cmd)
if err != nil {
var nfErr *store.ErrNotFound
var appErr *model.AppError
switch {
case errors.As(err, &nfErr):
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.update.missing.app_error", map[string]interface{}{"command_id": cmd.Id}, "", http.StatusNotFound)
case errors.As(err, &appErr):
return nil, appErr
default:
return nil, model.NewAppError("RegenCommandToken", "app.command.regencommandtoken.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return command, nil
} }
func (a *App) DeleteCommand(commandId string) *model.AppError { func (a *App) DeleteCommand(commandId string) *model.AppError {
@@ -678,5 +735,10 @@ func (a *App) DeleteCommand(commandId string) *model.AppError {
return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented) return model.NewAppError("DeleteCommand", "api.command.disabled.app_error", nil, "", http.StatusNotImplemented)
} }
return a.Srv().Store.Command().Delete(commandId, model.GetMillis()) err := a.Srv().Store.Command().Delete(commandId, model.GetMillis())
if err != nil {
return model.NewAppError("DeleteCommand", "app.command.deletecommand.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
return nil
} }

Просмотреть файл

@@ -1384,7 +1384,7 @@ func (a *App) PermanentDeleteTeam(team *model.Team) *model.AppError {
} }
if err := a.Srv().Store.Command().PermanentDeleteByTeam(team.Id); err != nil { if err := a.Srv().Store.Command().PermanentDeleteByTeam(team.Id); err != nil {
return err return model.NewAppError("PermanentDeleteTeam", "app.team.permanentdeleteteam.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.Team().PermanentDelete(team.Id); err != nil { if err := a.Srv().Store.Team().PermanentDelete(team.Id); err != nil {

Просмотреть файл

@@ -1473,7 +1473,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
} }
if err := a.Srv().Store.Command().PermanentDeleteByUser(user.Id); err != nil { if err := a.Srv().Store.Command().PermanentDeleteByUser(user.Id); err != nil {
return err return model.NewAppError("PermanentDeleteUser", "app.user.permanentdeleteuser.internal_error", nil, err.Error(), http.StatusInternalServerError)
} }
if err := a.Srv().Store.Preference().PermanentDeleteByUser(user.Id); err != nil { if err := a.Srv().Store.Preference().PermanentDeleteByUser(user.Id); err != nil {

Просмотреть файл

@@ -724,9 +724,15 @@ func (a *App) HandleCommandWebhook(hookId string, response *model.CommandRespons
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+err.Message, err.StatusCode) return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+err.Message, err.StatusCode)
} }
cmd, err := a.Srv().Store.Command().Get(hook.CommandId) cmd, cmdErr := a.Srv().Store.Command().Get(hook.CommandId)
if err != nil { if cmdErr != nil {
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+err.Message, http.StatusBadRequest) var appErr *model.AppError
switch {
case errors.As(cmdErr, &appErr):
return appErr
default:
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+cmdErr.Error(), http.StatusBadRequest)
}
} }
args := &model.CommandArgs{ args := &model.CommandArgs{

Просмотреть файл

@@ -46,7 +46,7 @@ func getCommandFromCommandArg(a *app.App, commandArg string) *model.Command {
if team == nil { if team == nil {
return nil return nil
} }
var err *model.AppError var err error
command, err = a.Srv().Store.Command().GetByTrigger(team.Id, commandPart) command, err = a.Srv().Store.Command().GetByTrigger(team.Id, commandPart)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())

Просмотреть файл

@@ -2978,6 +2978,10 @@
"id": "app.admin.test_site_url.failure", "id": "app.admin.test_site_url.failure",
"translation": "This is not a valid live URL" "translation": "This is not a valid live URL"
}, },
{
"id": "app.analytics.getanalytics.internal_error",
"translation": "Unable to get the analytics."
},
{ {
"id": "app.audit.get.finding.app_error", "id": "app.audit.get.finding.app_error",
"translation": "We encountered an error finding the audits." "translation": "We encountered an error finding the audits."
@@ -3138,6 +3142,46 @@
"id": "app.cluster.404.app_error", "id": "app.cluster.404.app_error",
"translation": "Cluster API endpoint not found." "translation": "Cluster API endpoint not found."
}, },
{
"id": "app.command.createcommand.internal_error",
"translation": "Unable to save the command."
},
{
"id": "app.command.deletecommand.internal_error",
"translation": "Unable to delete the command."
},
{
"id": "app.command.getcommand.internal_error",
"translation": "Unable to get the command."
},
{
"id": "app.command.listallcommands.internal_error",
"translation": "Unable to list the commands."
},
{
"id": "app.command.listautocompletecommands.internal_error",
"translation": "Unable to list the autocomplete commands."
},
{
"id": "app.command.listteamcommands.internal_error",
"translation": "Unable to list the team commands."
},
{
"id": "app.command.movecommand.internal_error",
"translation": "Unable to move the command."
},
{
"id": "app.command.regencommandtoken.internal_error",
"translation": "Unable to regenerate the command token."
},
{
"id": "app.command.tryexecutecustomcommand.internal_error",
"translation": "Unable to execute the custom command."
},
{
"id": "app.command.updatecommand.internal_error",
"translation": "Unable to update the command."
},
{ {
"id": "app.emoji.create.internal_error", "id": "app.emoji.create.internal_error",
"translation": "Unable to save emoji." "translation": "Unable to save emoji."
@@ -4078,6 +4122,10 @@
"id": "app.team.join_user_to_team.max_accounts.app_error", "id": "app.team.join_user_to_team.max_accounts.app_error",
"translation": "This team has reached the maximum number of allowed accounts. Contact your System Administrator to set a higher limit." "translation": "This team has reached the maximum number of allowed accounts. Contact your System Administrator to set a higher limit."
}, },
{
"id": "app.team.permanentdeleteteam.internal_error",
"translation": "Unable to delete team."
},
{ {
"id": "app.team.rename_team.name_occupied", "id": "app.team.rename_team.name_occupied",
"translation": "Unable to rename the team, the name is already in use." "translation": "Unable to rename the team, the name is already in use."
@@ -4102,6 +4150,10 @@
"id": "app.user.complete_switch_with_oauth.blank_email.app_error", "id": "app.user.complete_switch_with_oauth.blank_email.app_error",
"translation": "Unable to complete SAML login with an empty email address." "translation": "Unable to complete SAML login with an empty email address."
}, },
{
"id": "app.user.permanentdeleteuser.internal_error",
"translation": "Unable to delete user."
},
{ {
"id": "app.user_access_token.disabled", "id": "app.user_access_token.disabled",
"translation": "Personal access tokens are disabled on this server. Please contact your system administrator for details." "translation": "Personal access tokens are disabled on this server. Please contact your system administrator for details."
@@ -6523,40 +6575,16 @@
"translation": "Unable to determine if the user belongs to a list of channels." "translation": "Unable to determine if the user belongs to a list of channels."
}, },
{ {
"id": "store.sql_command.analytics_command_count.app_error", "id": "store.sql_command.get.missing.app_error",
"translation": "Unable to count the commands." "translation": "Command does not exist."
},
{
"id": "store.sql_command.get_by_trigger.app_error",
"translation": "Unable to get the command."
},
{
"id": "store.sql_command.save.delete.app_error",
"translation": "Unable to delete the command."
},
{
"id": "store.sql_command.save.delete_perm.app_error",
"translation": "Unable to delete the command."
}, },
{ {
"id": "store.sql_command.save.get.app_error", "id": "store.sql_command.save.get.app_error",
"translation": "Unable to get the command." "translation": "Unable to get the command."
}, },
{ {
"id": "store.sql_command.save.get_team.app_error", "id": "store.sql_command.update.missing.app_error",
"translation": "Unable to get the commands." "translation": "Command does not exist."
},
{
"id": "store.sql_command.save.saving.app_error",
"translation": "Unable to save the Command."
},
{
"id": "store.sql_command.save.saving_overwrite.app_error",
"translation": "You cannot overwrite an existing Command."
},
{
"id": "store.sql_command.save.update.app_error",
"translation": "Unable to update the command."
}, },
{ {
"id": "store.sql_command_webhooks.get.app_error", "id": "store.sql_command_webhooks.get.app_error",

Просмотреть файл

@@ -2421,7 +2421,7 @@ func (s *OpenTracingLayerClusterDiscoveryStore) SetLastPingAt(discovery *model.C
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) { func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.AnalyticsCommandCount") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.AnalyticsCommandCount")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2439,7 +2439,7 @@ func (s *OpenTracingLayerCommandStore) AnalyticsCommandCount(teamId string) (int
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) *model.AppError { func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Delete") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Delete")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2457,7 +2457,7 @@ func (s *OpenTracingLayerCommandStore) Delete(commandId string, time int64) *mod
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, *model.AppError) { func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Get") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Get")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2475,7 +2475,7 @@ func (s *OpenTracingLayerCommandStore) Get(id string) (*model.Command, *model.Ap
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) { func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTeam") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTeam")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2493,7 +2493,7 @@ func (s *OpenTracingLayerCommandStore) GetByTeam(teamId string) ([]*model.Comman
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) { func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTrigger") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.GetByTrigger")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2511,7 +2511,7 @@ func (s *OpenTracingLayerCommandStore) GetByTrigger(teamId string, trigger strin
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByTeam") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByTeam")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2529,7 +2529,7 @@ func (s *OpenTracingLayerCommandStore) PermanentDeleteByTeam(teamId string) *mod
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) *model.AppError { func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) error {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.PermanentDeleteByUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2547,7 +2547,7 @@ func (s *OpenTracingLayerCommandStore) PermanentDeleteByUser(userId string) *mod
return resultVar0 return resultVar0
} }
func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) { func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Command, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Save") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Save")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -2565,7 +2565,7 @@ func (s *OpenTracingLayerCommandStore) Save(webhook *model.Command) (*model.Comm
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *OpenTracingLayerCommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) { func (s *OpenTracingLayerCommandStore) Update(hook *model.Command) (*model.Command, error) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Update") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "CommandStore.Update")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)

Просмотреть файл

@@ -4,12 +4,13 @@
package sqlstore package sqlstore
import ( import (
"net/http" "database/sql"
sq "github.com/Masterminds/squirrel"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors"
) )
type SqlCommandStore struct { type SqlCommandStore struct {
@@ -51,9 +52,9 @@ func (s SqlCommandStore) createIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_command_delete_at", "Commands", "DeleteAt") s.CreateIndexIfNotExists("idx_command_delete_at", "Commands", "DeleteAt")
} }
func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.AppError) { func (s SqlCommandStore) Save(command *model.Command) (*model.Command, error) {
if len(command.Id) > 0 { if len(command.Id) > 0 {
return nil, model.NewAppError("SqlCommandStore.Save", "store.sql_command.save.saving_overwrite.app_error", nil, "id="+command.Id, http.StatusBadRequest) return nil, store.NewErrInvalidInput("Command", "CommandId", command.Id)
} }
command.PreSave() command.PreSave()
@@ -62,42 +63,45 @@ func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.Ap
} }
if err := s.GetMaster().Insert(command); err != nil { if err := s.GetMaster().Insert(command); err != nil {
return nil, model.NewAppError("SqlCommandStore.Save", "store.sql_command.save.saving.app_error", nil, "id="+command.Id+", "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "insert: command_id=%s", command.Id)
} }
return command, nil return command, nil
} }
func (s SqlCommandStore) Get(id string) (*model.Command, *model.AppError) { func (s SqlCommandStore) Get(id string) (*model.Command, error) {
var command model.Command var command model.Command
sql, args, err := s.commandsQuery. query, args, err := s.commandsQuery.
Where(sq.Eq{"Id": id, "DeleteAt": 0}).ToSql() Where(sq.Eq{"Id": id, "DeleteAt": 0}).ToSql()
if err != nil { if err != nil {
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "commands_tosql")
} }
if err = s.GetReplica().SelectOne(&command, sql, args...); err != nil { if err = s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.save.get.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError) return nil, store.NewErrNotFound("Command", id)
} else if err != nil {
return nil, errors.Wrapf(err, "selectone: command_id=%s", id)
} }
return &command, nil return &command, nil
} }
func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) { func (s SqlCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
var commands []*model.Command var commands []*model.Command
sql, args, err := s.commandsQuery. sql, args, err := s.commandsQuery.
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0}).ToSql() Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0}).ToSql()
if err != nil { if err != nil {
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "commands_tosql")
} }
if _, err := s.GetReplica().Select(&commands, sql, args...); err != nil { if _, err := s.GetReplica().Select(&commands, sql, args...); err != nil {
return nil, model.NewAppError("SqlCommandStore.GetByTeam", "store.sql_command.save.get_team.app_error", nil, "teamId="+teamId+", err="+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "select: team_id=%s", teamId)
} }
return commands, nil return commands, nil
} }
func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) { func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
var command model.Command var command model.Command
var triggerStr string var triggerStr string
if s.DriverName() == "mysql" { if s.DriverName() == "mysql" {
@@ -106,66 +110,69 @@ func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Com
triggerStr = "\"trigger\"" triggerStr = "\"trigger\""
} }
sql, args, err := s.commandsQuery. query, args, err := s.commandsQuery.
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0, triggerStr: trigger}).ToSql() Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0, triggerStr: trigger}).ToSql()
if err != nil { if err != nil {
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "commands_tosql")
} }
if err := s.GetReplica().SelectOne(&command, sql, args...); err != nil { if err := s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql_command.get_by_trigger.app_error", nil, "teamId="+teamId+", trigger="+trigger+", err="+err.Error(), http.StatusInternalServerError) errorId := "teamId=" + teamId + ", trigger=" + trigger
return nil, store.NewErrNotFound("Command", errorId)
} else if err != nil {
return nil, errors.Wrapf(err, "selectone: team_id=%s, trigger=%s", teamId, trigger)
} }
return &command, nil return &command, nil
} }
func (s SqlCommandStore) Delete(commandId string, time int64) *model.AppError { func (s SqlCommandStore) Delete(commandId string, time int64) error {
sql, args, err := s.getQueryBuilder(). sql, args, err := s.getQueryBuilder().
Update("Commands"). Update("Commands").
SetMap(sq.Eq{"DeleteAt": time, "UpdateAt": time}). SetMap(sq.Eq{"DeleteAt": time, "UpdateAt": time}).
Where(sq.Eq{"Id": commandId}).ToSql() Where(sq.Eq{"Id": commandId}).ToSql()
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.Delete", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "commands_tosql")
} }
_, err = s.GetMaster().Exec(sql, args...) _, err = s.GetMaster().Exec(sql, args...)
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.Delete", "store.sql_command.save.delete.app_error", nil, "id="+commandId+", err="+err.Error(), http.StatusInternalServerError) errors.Wrapf(err, "delete: command_id=%s", commandId)
} }
return nil return nil
} }
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) error {
sql, args, err := s.getQueryBuilder(). sql, args, err := s.getQueryBuilder().
Delete("Commands"). Delete("Commands").
Where(sq.Eq{"TeamId": teamId}).ToSql() Where(sq.Eq{"TeamId": teamId}).ToSql()
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.DeleteByTeam", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "commands_tosql")
} }
_, err = s.GetMaster().Exec(sql, args...) _, err = s.GetMaster().Exec(sql, args...)
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.DeleteByTeam", "store.sql_command.save.delete_perm.app_error", nil, "id="+teamId+", err="+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "delete: team_id=%s", teamId)
} }
return nil return nil
} }
func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError { func (s SqlCommandStore) PermanentDeleteByUser(userId string) error {
sql, args, err := s.getQueryBuilder(). sql, args, err := s.getQueryBuilder().
Delete("Commands"). Delete("Commands").
Where(sq.Eq{"CreatorId": userId}).ToSql() Where(sq.Eq{"CreatorId": userId}).ToSql()
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "commands_tosql")
} }
_, err = s.GetMaster().Exec(sql, args...) _, err = s.GetMaster().Exec(sql, args...)
if err != nil { if err != nil {
return model.NewAppError("SqlCommandStore.DeleteByUser", "store.sql_command.save.delete_perm.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError) return errors.Wrapf(err, "delete: user_id=%s", userId)
} }
return nil return nil
} }
func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppError) { func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, error) {
cmd.UpdateAt = model.GetMillis() cmd.UpdateAt = model.GetMillis()
if err := cmd.IsValid(); err != nil { if err := cmd.IsValid(); err != nil {
@@ -173,13 +180,13 @@ func (s SqlCommandStore) Update(cmd *model.Command) (*model.Command, *model.AppE
} }
if _, err := s.GetMaster().Update(cmd); err != nil { if _, err := s.GetMaster().Update(cmd); err != nil {
return nil, model.NewAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error(), http.StatusInternalServerError) return nil, errors.Wrapf(err, "update: command_id=%s", cmd.Id)
} }
return cmd, nil return cmd, nil
} }
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) { func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
query := s.getQueryBuilder(). query := s.getQueryBuilder().
Select("COUNT(*)"). Select("COUNT(*)").
From("Commands"). From("Commands").
@@ -191,12 +198,12 @@ func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.App
sql, args, err := query.ToSql() sql, args, err := query.ToSql()
if err != nil { if err != nil {
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql.build_query.app_error", nil, err.Error(), http.StatusInternalServerError) return 0, errors.Wrapf(err, "commands_tosql")
} }
c, err := s.GetReplica().SelectInt(sql, args...) c, err := s.GetReplica().SelectInt(sql, args...)
if err != nil { if err != nil {
return 0, model.NewAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error(), http.StatusInternalServerError) return 0, errors.Wrapf(err, "unable to count the commands: team_id=%s", teamId)
} }
return c, nil return c, nil
} }

Просмотреть файл

@@ -476,15 +476,15 @@ type WebhookStore interface {
} }
type CommandStore interface { type CommandStore interface {
Save(webhook *model.Command) (*model.Command, *model.AppError) Save(webhook *model.Command) (*model.Command, error)
GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) GetByTrigger(teamId string, trigger string) (*model.Command, error)
Get(id string) (*model.Command, *model.AppError) Get(id string) (*model.Command, error)
GetByTeam(teamId string) ([]*model.Command, *model.AppError) GetByTeam(teamId string) ([]*model.Command, error)
Delete(commandId string, time int64) *model.AppError Delete(commandId string, time int64) error
PermanentDeleteByTeam(teamId string) *model.AppError PermanentDeleteByTeam(teamId string) error
PermanentDeleteByUser(userId string) *model.AppError PermanentDeleteByUser(userId string) error
Update(hook *model.Command) (*model.Command, *model.AppError) Update(hook *model.Command) (*model.Command, error)
AnalyticsCommandCount(teamId string) (int64, *model.AppError) AnalyticsCommandCount(teamId string) (int64, error)
} }
type CommandWebhookStore interface { type CommandWebhookStore interface {

Просмотреть файл

@@ -4,6 +4,7 @@
package storetest package storetest
import ( import (
"errors"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@@ -32,10 +33,10 @@ func testCommandStoreSave(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
_, err := ss.Command().Save(&o1) _, nErr := ss.Command().Save(&o1)
require.Nil(t, err, "couldn't save item") require.Nil(t, nErr)
_, err = ss.Command().Save(&o1) _, err := ss.Command().Save(&o1)
require.NotNil(t, err, "shouldn't be able to update from save") require.NotNil(t, err, "shouldn't be able to update from save")
} }
@@ -47,15 +48,17 @@ func testCommandStoreGet(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id) r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command") require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
_, err = ss.Command().Get("123") _, err := ss.Command().Get("123")
require.NotNil(t, err, "Mising id should have failed") require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
} }
func testCommandStoreGetByTeam(t *testing.T, ss store.Store) { func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
@@ -66,16 +69,16 @@ func testCommandStoreGetByTeam(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().GetByTeam(o1.TeamId) r1, nErr := ss.Command().GetByTeam(o1.TeamId)
require.Nil(t, err) require.Nil(t, nErr)
require.NotEmpty(t, r1, "no command returned") require.NotEmpty(t, r1, "no command returned")
require.Equal(t, r1[0].CreateAt, o1.CreateAt, "invalid returned command") require.Equal(t, r1[0].CreateAt, o1.CreateAt, "invalid returned command")
result, err := ss.Command().GetByTeam("123") result, nErr := ss.Command().GetByTeam("123")
require.Nil(t, err) require.Nil(t, nErr)
require.Empty(t, result, "no commands should have returned") require.Empty(t, result, "no commands should have returned")
} }
@@ -94,22 +97,24 @@ func testCommandStoreGetByTrigger(t *testing.T, ss store.Store) {
o2.URL = "http://nowhere.com/" o2.URL = "http://nowhere.com/"
o2.Trigger = "trigger1" o2.Trigger = "trigger1"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Command().Save(o2) _, nErr = ss.Command().Save(o2)
require.Nil(t, err) require.Nil(t, nErr)
var r1 *model.Command var r1 *model.Command
r1, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger) r1, nErr = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r1.Id, o1.Id, "invalid returned command") require.Equal(t, r1.Id, o1.Id, "invalid returned command")
err = ss.Command().Delete(o1.Id, model.GetMillis()) nErr = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger) _, err := ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.NotNil(t, err, "no commands should have returned") require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
} }
func testCommandStoreDelete(t *testing.T, ss store.Store) { func testCommandStoreDelete(t *testing.T, ss store.Store) {
@@ -120,18 +125,20 @@ func testCommandStoreDelete(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id) r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command") require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().Delete(o1.Id, model.GetMillis()) nErr = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id) _, err := ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed") require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
} }
func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) { func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
@@ -142,18 +149,20 @@ func testCommandStoreDeleteByTeam(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id) r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command") require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().PermanentDeleteByTeam(o1.TeamId) nErr = ss.Command().PermanentDeleteByTeam(o1.TeamId)
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id) _, err := ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed") require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
} }
func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) { func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
@@ -164,18 +173,20 @@ func testCommandStoreDeleteByUser(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id) r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command") require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().PermanentDeleteByUser(o1.CreatorId) nErr = ss.Command().PermanentDeleteByUser(o1.CreatorId)
require.Nil(t, err) require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id) _, err := ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed") require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
} }
func testCommandStoreUpdate(t *testing.T, ss store.Store) { func testCommandStoreUpdate(t *testing.T, ss store.Store) {
@@ -186,18 +197,18 @@ func testCommandStoreUpdate(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
o1.Token = model.NewId() o1.Token = model.NewId()
_, err = ss.Command().Update(o1) _, nErr = ss.Command().Update(o1)
require.Nil(t, err) require.Nil(t, nErr)
o1.URL = "junk" o1.URL = "junk"
_, err = ss.Command().Update(o1) _, err := ss.Command().Update(o1)
require.NotNil(t, err, "should have failed - bad URL") require.NotNil(t, err)
} }
func testCommandCount(t *testing.T, ss store.Store) { func testCommandCount(t *testing.T, ss store.Store) {
@@ -208,14 +219,14 @@ func testCommandCount(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/" o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger" o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1) o1, nErr := ss.Command().Save(o1)
require.Nil(t, err) require.Nil(t, nErr)
r1, err := ss.Command().AnalyticsCommandCount("") r1, nErr := ss.Command().AnalyticsCommandCount("")
require.Nil(t, err) require.Nil(t, nErr)
require.NotZero(t, r1, "should be at least 1 command") require.NotZero(t, r1, "should be at least 1 command")
r2, err := ss.Command().AnalyticsCommandCount(o1.TeamId) r2, nErr := ss.Command().AnalyticsCommandCount(o1.TeamId)
require.Nil(t, err) require.Nil(t, nErr)
require.Equal(t, r2, int64(1), "should be 1 command") require.Equal(t, r2, int64(1), "should be 1 command")
} }

Просмотреть файл

@@ -15,7 +15,7 @@ type CommandStore struct {
} }
// AnalyticsCommandCount provides a mock function with given fields: teamId // AnalyticsCommandCount provides a mock function with given fields: teamId
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) { func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
ret := _m.Called(teamId) ret := _m.Called(teamId)
var r0 int64 var r0 int64
@@ -25,36 +25,32 @@ func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppE
r0 = ret.Get(0).(int64) r0 = ret.Get(0).(int64)
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId) r1 = rf(teamId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// Delete provides a mock function with given fields: commandId, time // Delete provides a mock function with given fields: commandId, time
func (_m *CommandStore) Delete(commandId string, time int64) *model.AppError { func (_m *CommandStore) Delete(commandId string, time int64) error {
ret := _m.Called(commandId, time) ret := _m.Called(commandId, time)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string, int64) error); ok {
r0 = rf(commandId, time) r0 = rf(commandId, time)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// Get provides a mock function with given fields: id // Get provides a mock function with given fields: id
func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) { func (_m *CommandStore) Get(id string) (*model.Command, error) {
ret := _m.Called(id) ret := _m.Called(id)
var r0 *model.Command var r0 *model.Command
@@ -66,20 +62,18 @@ func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) {
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(id) r1 = rf(id)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetByTeam provides a mock function with given fields: teamId // GetByTeam provides a mock function with given fields: teamId
func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) { func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
ret := _m.Called(teamId) ret := _m.Called(teamId)
var r0 []*model.Command var r0 []*model.Command
@@ -91,20 +85,18 @@ func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppEr
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId) r1 = rf(teamId)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// GetByTrigger provides a mock function with given fields: teamId, trigger // GetByTrigger provides a mock function with given fields: teamId, trigger
func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) { func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
ret := _m.Called(teamId, trigger) ret := _m.Called(teamId, trigger)
var r0 *model.Command var r0 *model.Command
@@ -116,52 +108,46 @@ func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Comm
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(teamId, trigger) r1 = rf(teamId, trigger)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// PermanentDeleteByTeam provides a mock function with given fields: teamId // PermanentDeleteByTeam provides a mock function with given fields: teamId
func (_m *CommandStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (_m *CommandStore) PermanentDeleteByTeam(teamId string) error {
ret := _m.Called(teamId) ret := _m.Called(teamId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(teamId) r0 = rf(teamId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// PermanentDeleteByUser provides a mock function with given fields: userId // PermanentDeleteByUser provides a mock function with given fields: userId
func (_m *CommandStore) PermanentDeleteByUser(userId string) *model.AppError { func (_m *CommandStore) PermanentDeleteByUser(userId string) error {
ret := _m.Called(userId) ret := _m.Called(userId)
var r0 *model.AppError var r0 error
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(userId) r0 = rf(userId)
} else { } else {
if ret.Get(0) != nil { r0 = ret.Error(0)
r0 = ret.Get(0).(*model.AppError)
}
} }
return r0 return r0
} }
// Save provides a mock function with given fields: webhook // Save provides a mock function with given fields: webhook
func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) { func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, error) {
ret := _m.Called(webhook) ret := _m.Called(webhook)
var r0 *model.Command var r0 *model.Command
@@ -173,20 +159,18 @@ func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, *model.App
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok { if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
r1 = rf(webhook) r1 = rf(webhook)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1
} }
// Update provides a mock function with given fields: hook // Update provides a mock function with given fields: hook
func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) { func (_m *CommandStore) Update(hook *model.Command) (*model.Command, error) {
ret := _m.Called(hook) ret := _m.Called(hook)
var r0 *model.Command var r0 *model.Command
@@ -198,13 +182,11 @@ func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppE
} }
} }
var r1 *model.AppError var r1 error
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok { if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
r1 = rf(hook) r1 = rf(hook)
} else { } else {
if ret.Get(1) != nil { r1 = ret.Error(1)
r1 = ret.Get(1).(*model.AppError)
}
} }
return r0, r1 return r0, r1

Просмотреть файл

@@ -2225,7 +2225,7 @@ func (s *TimerLayerClusterDiscoveryStore) SetLastPingAt(discovery *model.Cluster
return resultVar0 return resultVar0
} }
func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) { func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.AnalyticsCommandCount(teamId) resultVar0, resultVar1 := s.CommandStore.AnalyticsCommandCount(teamId)
@@ -2241,7 +2241,7 @@ func (s *TimerLayerCommandStore) AnalyticsCommandCount(teamId string) (int64, *m
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerCommandStore) Delete(commandId string, time int64) *model.AppError { func (s *TimerLayerCommandStore) Delete(commandId string, time int64) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.CommandStore.Delete(commandId, time) resultVar0 := s.CommandStore.Delete(commandId, time)
@@ -2257,7 +2257,7 @@ func (s *TimerLayerCommandStore) Delete(commandId string, time int64) *model.App
return resultVar0 return resultVar0
} }
func (s *TimerLayerCommandStore) Get(id string) (*model.Command, *model.AppError) { func (s *TimerLayerCommandStore) Get(id string) (*model.Command, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.Get(id) resultVar0, resultVar1 := s.CommandStore.Get(id)
@@ -2273,7 +2273,7 @@ func (s *TimerLayerCommandStore) Get(id string) (*model.Command, *model.AppError
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppError) { func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.GetByTeam(teamId) resultVar0, resultVar1 := s.CommandStore.GetByTeam(teamId)
@@ -2289,7 +2289,7 @@ func (s *TimerLayerCommandStore) GetByTeam(teamId string) ([]*model.Command, *mo
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) { func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*model.Command, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.GetByTrigger(teamId, trigger) resultVar0, resultVar1 := s.CommandStore.GetByTrigger(teamId, trigger)
@@ -2305,7 +2305,7 @@ func (s *TimerLayerCommandStore) GetByTrigger(teamId string, trigger string) (*m
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError { func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.CommandStore.PermanentDeleteByTeam(teamId) resultVar0 := s.CommandStore.PermanentDeleteByTeam(teamId)
@@ -2321,7 +2321,7 @@ func (s *TimerLayerCommandStore) PermanentDeleteByTeam(teamId string) *model.App
return resultVar0 return resultVar0
} }
func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) *model.AppError { func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) error {
start := timemodule.Now() start := timemodule.Now()
resultVar0 := s.CommandStore.PermanentDeleteByUser(userId) resultVar0 := s.CommandStore.PermanentDeleteByUser(userId)
@@ -2337,7 +2337,7 @@ func (s *TimerLayerCommandStore) PermanentDeleteByUser(userId string) *model.App
return resultVar0 return resultVar0
} }
func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, *model.AppError) { func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.Save(webhook) resultVar0, resultVar1 := s.CommandStore.Save(webhook)
@@ -2353,7 +2353,7 @@ func (s *TimerLayerCommandStore) Save(webhook *model.Command) (*model.Command, *
return resultVar0, resultVar1 return resultVar0, resultVar1
} }
func (s *TimerLayerCommandStore) Update(hook *model.Command) (*model.Command, *model.AppError) { func (s *TimerLayerCommandStore) Update(hook *model.Command) (*model.Command, error) {
start := timemodule.Now() start := timemodule.Now()
resultVar0, resultVar1 := s.CommandStore.Update(hook) resultVar0, resultVar1 := s.CommandStore.Update(hook)