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)
privateChan := make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
openChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_OPEN)
openChan <- store.StoreResult{Data: count, Err: err2}
close(openChan)
}()
go func() {
count, err := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
privateChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.Channel().AnalyticsTypeCount(teamId, model.CHANNEL_PRIVATE)
privateChan <- store.StoreResult{Data: count, Err: err2}
close(privateChan)
}()
@@ -61,15 +61,15 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if teamId == "" {
userInactiveChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.User().AnalyticsGetInactiveUsersCount()
userInactiveChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.User().AnalyticsGetInactiveUsersCount()
userInactiveChan <- store.StoreResult{Data: count, Err: err2}
close(userInactiveChan)
}()
} else {
userChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamId})
userChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.User().Count(model.UserCountOptions{TeamId: teamId})
userChan <- store.StoreResult{Data: count, Err: err2}
close(userChan)
}()
}
@@ -78,30 +78,30 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if !skipIntensiveQueries {
postChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false)
postChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, false)
postChan <- store.StoreResult{Data: count, Err: err2}
close(postChan)
}()
}
teamCountChan := make(chan store.StoreResult, 1)
go func() {
teamCount, err := a.Srv().Store.Team().AnalyticsTeamCount(false)
teamCountChan <- store.StoreResult{Data: teamCount, Err: err}
teamCount, err2 := a.Srv().Store.Team().AnalyticsTeamCount(false)
teamCountChan <- store.StoreResult{Data: teamCount, Err: err2}
close(teamCountChan)
}()
dailyActiveChan := make(chan store.StoreResult, 1)
go func() {
dailyActive, err := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err}
dailyActive, err2 := a.Srv().Store.User().AnalyticsActiveCount(DAY_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
dailyActiveChan <- store.StoreResult{Data: dailyActive, Err: err2}
close(dailyActiveChan)
}()
monthlyActiveChan := make(chan store.StoreResult, 1)
go func() {
monthlyActive, err := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err}
monthlyActive, err2 := a.Srv().Store.User().AnalyticsActiveCount(MONTH_MILLISECONDS, model.UserCountOptions{IncludeBotAccounts: false, IncludeDeleted: false})
monthlyActiveChan <- store.StoreResult{Data: monthlyActive, Err: err2}
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 a.Cluster() != nil && *a.Config().ClusterSettings.Enable {
stats, err := a.Cluster().GetClusterStats()
if err != nil {
return nil, err
stats, err2 := a.Cluster().GetClusterStats()
if err2 != nil {
return nil, err2
}
totalSockets := a.TotalWebsocketConnections()
@@ -231,29 +231,29 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
iHookChan := make(chan store.StoreResult, 1)
go func() {
c, err := a.Srv().Store.Webhook().AnalyticsIncomingCount(teamId)
iHookChan <- store.StoreResult{Data: c, Err: err}
c, err2 := a.Srv().Store.Webhook().AnalyticsIncomingCount(teamId)
iHookChan <- store.StoreResult{Data: c, Err: err2}
close(iHookChan)
}()
oHookChan := make(chan store.StoreResult, 1)
go func() {
c, err := a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamId)
oHookChan <- store.StoreResult{Data: c, Err: err}
c, err2 := a.Srv().Store.Webhook().AnalyticsOutgoingCount(teamId)
oHookChan <- store.StoreResult{Data: c, Err: err2}
close(oHookChan)
}()
commandChan := make(chan store.StoreResult, 1)
go func() {
c, err := a.Srv().Store.Command().AnalyticsCommandCount(teamId)
commandChan <- store.StoreResult{Data: c, Err: err}
c, nErr := a.Srv().Store.Command().AnalyticsCommandCount(teamId)
commandChan <- store.StoreResult{Data: c, NErr: nErr}
close(commandChan)
}()
sessionChan := make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.Session().AnalyticsSessionCount()
sessionChan <- store.StoreResult{Data: count, NErr: err}
count, err2 := a.Srv().Store.Session().AnalyticsSessionCount()
sessionChan <- store.StoreResult{Data: count, NErr: err2}
close(sessionChan)
}()
@@ -263,15 +263,15 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
if !skipIntensiveQueries {
fileChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false)
fileChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, true, false)
fileChan <- store.StoreResult{Data: count, Err: err2}
close(fileChan)
}()
hashtagChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true)
hashtagChan <- store.StoreResult{Data: count, Err: err}
count, err2 := a.Srv().Store.Post().AnalyticsPostCount(teamId, false, true)
hashtagChan <- store.StoreResult{Data: count, Err: err2}
close(hashtagChan)
}()
}
@@ -309,8 +309,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
rows[3].Value = float64(r.Data.(int64))
r = <-commandChan
if r.Err != nil {
return nil, r.Err
if r.NErr != nil {
return nil, model.NewAppError("GetAnalytics", "app.analytics.getanalytics.internal_error", nil, err.Error(), http.StatusInternalServerError)
}
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 {
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
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 {
@@ -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 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) {
@@ -146,7 +151,7 @@ func (a *App) ListAllCommands(teamId string, T goi18n.TranslateFunc) ([]*model.C
if *a.Config().ServiceSettings.EnableCommands {
teamCmds, err := a.Srv().Store.Command().GetByTeam(teamId)
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 {
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)
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
@@ -602,7 +607,7 @@ func (a *App) CreateCommand(cmd *model.Command) (*model.Command, *model.AppError
teamCmds, err := a.Srv().Store.Command().GetByTeam(cmd.TeamId)
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 {
@@ -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) {
@@ -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)
}
cmd, err := a.Srv().Store.Command().Get(commandId)
command, err := a.Srv().Store.Command().Get(commandId)
if err != nil {
err.StatusCode = http.StatusNotFound
return nil, err
var nfErr *store.ErrNotFound
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 cmd, nil
return command, nil
}
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.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 {
@@ -657,7 +691,16 @@ func (a *App) MoveCommand(team *model.Team, command *model.Command) *model.AppEr
_, err := a.Srv().Store.Command().Update(command)
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
@@ -670,7 +713,21 @@ func (a *App) RegenCommandToken(cmd *model.Command) (*model.Command, *model.AppE
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 {
@@ -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 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 {
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 {

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

@@ -1473,7 +1473,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError {
}
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 {

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

@@ -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)
}
cmd, err := a.Srv().Store.Command().Get(hook.CommandId)
if err != nil {
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+err.Message, http.StatusBadRequest)
cmd, cmdErr := a.Srv().Store.Command().Get(hook.CommandId)
if cmdErr != nil {
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{

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

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

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

@@ -2978,6 +2978,10 @@
"id": "app.admin.test_site_url.failure",
"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",
"translation": "We encountered an error finding the audits."
@@ -3138,6 +3142,46 @@
"id": "app.cluster.404.app_error",
"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",
"translation": "Unable to save emoji."
@@ -4078,6 +4122,10 @@
"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."
},
{
"id": "app.team.permanentdeleteteam.internal_error",
"translation": "Unable to delete team."
},
{
"id": "app.team.rename_team.name_occupied",
"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",
"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",
"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."
},
{
"id": "store.sql_command.analytics_command_count.app_error",
"translation": "Unable to count the commands."
},
{
"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.get.missing.app_error",
"translation": "Command does not exist."
},
{
"id": "store.sql_command.save.get.app_error",
"translation": "Unable to get the command."
},
{
"id": "store.sql_command.save.get_team.app_error",
"translation": "Unable to get the commands."
},
{
"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.update.missing.app_error",
"translation": "Command does not exist."
},
{
"id": "store.sql_command_webhooks.get.app_error",

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

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

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

@@ -4,12 +4,13 @@
package sqlstore
import (
"net/http"
sq "github.com/Masterminds/squirrel"
"database/sql"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store"
sq "github.com/Masterminds/squirrel"
"github.com/pkg/errors"
)
type SqlCommandStore struct {
@@ -51,9 +52,9 @@ func (s SqlCommandStore) createIndexesIfNotExists() {
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 {
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()
@@ -62,42 +63,45 @@ func (s SqlCommandStore) Save(command *model.Command) (*model.Command, *model.Ap
}
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
}
func (s SqlCommandStore) Get(id string) (*model.Command, *model.AppError) {
func (s SqlCommandStore) Get(id string) (*model.Command, error) {
var command model.Command
sql, args, err := s.commandsQuery.
query, args, err := s.commandsQuery.
Where(sq.Eq{"Id": id, "DeleteAt": 0}).ToSql()
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 {
return nil, model.NewAppError("SqlCommandStore.Get", "store.sql_command.save.get.app_error", nil, "id="+id+", err="+err.Error(), http.StatusInternalServerError)
if err = s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
return nil, store.NewErrNotFound("Command", id)
} else if err != nil {
return nil, errors.Wrapf(err, "selectone: command_id=%s", id)
}
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
sql, args, err := s.commandsQuery.
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0}).ToSql()
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 {
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
}
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 triggerStr string
if s.DriverName() == "mysql" {
@@ -106,66 +110,69 @@ func (s SqlCommandStore) GetByTrigger(teamId string, trigger string) (*model.Com
triggerStr = "\"trigger\""
}
sql, args, err := s.commandsQuery.
query, args, err := s.commandsQuery.
Where(sq.Eq{"TeamId": teamId, "DeleteAt": 0, triggerStr: trigger}).ToSql()
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 {
return nil, model.NewAppError("SqlCommandStore.GetByTrigger", "store.sql_command.get_by_trigger.app_error", nil, "teamId="+teamId+", trigger="+trigger+", err="+err.Error(), http.StatusInternalServerError)
if err := s.GetReplica().SelectOne(&command, query, args...); err == sql.ErrNoRows {
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
}
func (s SqlCommandStore) Delete(commandId string, time int64) *model.AppError {
func (s SqlCommandStore) Delete(commandId string, time int64) error {
sql, args, err := s.getQueryBuilder().
Update("Commands").
SetMap(sq.Eq{"DeleteAt": time, "UpdateAt": time}).
Where(sq.Eq{"Id": commandId}).ToSql()
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...)
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
}
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) *model.AppError {
func (s SqlCommandStore) PermanentDeleteByTeam(teamId string) error {
sql, args, err := s.getQueryBuilder().
Delete("Commands").
Where(sq.Eq{"TeamId": teamId}).ToSql()
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...)
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
}
func (s SqlCommandStore) PermanentDeleteByUser(userId string) *model.AppError {
func (s SqlCommandStore) PermanentDeleteByUser(userId string) error {
sql, args, err := s.getQueryBuilder().
Delete("Commands").
Where(sq.Eq{"CreatorId": userId}).ToSql()
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...)
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
}
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()
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 {
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
}
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
query := s.getQueryBuilder().
Select("COUNT(*)").
From("Commands").
@@ -191,12 +198,12 @@ func (s SqlCommandStore) AnalyticsCommandCount(teamId string) (int64, *model.App
sql, args, err := query.ToSql()
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...)
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
}

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

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

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

@@ -4,6 +4,7 @@
package storetest
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
@@ -32,10 +33,10 @@ func testCommandStoreSave(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger"
_, err := ss.Command().Save(&o1)
require.Nil(t, err, "couldn't save item")
_, nErr := ss.Command().Save(&o1)
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")
}
@@ -47,15 +48,17 @@ func testCommandStoreGet(t *testing.T, ss store.Store) {
o1.URL = "http://nowhere.com/"
o1.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id)
require.Nil(t, err)
r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
_, err = ss.Command().Get("123")
require.NotNil(t, err, "Mising id should have failed")
_, err := ss.Command().Get("123")
require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().GetByTeam(o1.TeamId)
require.Nil(t, err)
r1, nErr := ss.Command().GetByTeam(o1.TeamId)
require.Nil(t, nErr)
require.NotEmpty(t, r1, "no command returned")
require.Equal(t, r1[0].CreateAt, o1.CreateAt, "invalid returned command")
result, err := ss.Command().GetByTeam("123")
require.Nil(t, err)
result, nErr := ss.Command().GetByTeam("123")
require.Nil(t, nErr)
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.Trigger = "trigger1"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
_, err = ss.Command().Save(o2)
require.Nil(t, err)
_, nErr = ss.Command().Save(o2)
require.Nil(t, nErr)
var r1 *model.Command
r1, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.Nil(t, err)
r1, nErr = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.Nil(t, nErr)
require.Equal(t, r1.Id, o1.Id, "invalid returned command")
err = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, err)
nErr = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, nErr)
_, err = ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.NotNil(t, err, "no commands should have returned")
_, err := ss.Command().GetByTrigger(o1.TeamId, o1.Trigger)
require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id)
require.Nil(t, err)
r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, err)
nErr = ss.Command().Delete(o1.Id, model.GetMillis())
require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed")
_, err := ss.Command().Get(o1.Id)
require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id)
require.Nil(t, err)
r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().PermanentDeleteByTeam(o1.TeamId)
require.Nil(t, err)
nErr = ss.Command().PermanentDeleteByTeam(o1.TeamId)
require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed")
_, err := ss.Command().Get(o1.Id)
require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().Get(o1.Id)
require.Nil(t, err)
r1, nErr := ss.Command().Get(o1.Id)
require.Nil(t, nErr)
require.Equal(t, r1.CreateAt, o1.CreateAt, "invalid returned command")
err = ss.Command().PermanentDeleteByUser(o1.CreatorId)
require.Nil(t, err)
nErr = ss.Command().PermanentDeleteByUser(o1.CreatorId)
require.Nil(t, nErr)
_, err = ss.Command().Get(o1.Id)
require.NotNil(t, err, "Missing id should have failed")
_, err := ss.Command().Get(o1.Id)
require.NotNil(t, err)
var nfErr *store.ErrNotFound
require.True(t, errors.As(err, &nfErr))
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
o1.Token = model.NewId()
_, err = ss.Command().Update(o1)
require.Nil(t, err)
_, nErr = ss.Command().Update(o1)
require.Nil(t, nErr)
o1.URL = "junk"
_, err = ss.Command().Update(o1)
require.NotNil(t, err, "should have failed - bad URL")
_, err := ss.Command().Update(o1)
require.NotNil(t, err)
}
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.Trigger = "trigger"
o1, err := ss.Command().Save(o1)
require.Nil(t, err)
o1, nErr := ss.Command().Save(o1)
require.Nil(t, nErr)
r1, err := ss.Command().AnalyticsCommandCount("")
require.Nil(t, err)
r1, nErr := ss.Command().AnalyticsCommandCount("")
require.Nil(t, nErr)
require.NotZero(t, r1, "should be at least 1 command")
r2, err := ss.Command().AnalyticsCommandCount(o1.TeamId)
require.Nil(t, err)
r2, nErr := ss.Command().AnalyticsCommandCount(o1.TeamId)
require.Nil(t, nErr)
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
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppError) {
func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, error) {
ret := _m.Called(teamId)
var r0 int64
@@ -25,36 +25,32 @@ func (_m *CommandStore) AnalyticsCommandCount(teamId string) (int64, *model.AppE
r0 = ret.Get(0).(int64)
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// 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)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, int64) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(string, int64) error); ok {
r0 = rf(commandId, time)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
r0 = ret.Error(0)
}
return r0
}
// 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)
var r0 *model.Command
@@ -66,20 +62,18 @@ func (_m *CommandStore) Get(id string) (*model.Command, *model.AppError) {
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(id)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// 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)
var r0 []*model.Command
@@ -91,20 +85,18 @@ func (_m *CommandStore) GetByTeam(teamId string) ([]*model.Command, *model.AppEr
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(teamId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// 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)
var r0 *model.Command
@@ -116,52 +108,46 @@ func (_m *CommandStore) GetByTrigger(teamId string, trigger string) (*model.Comm
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string, string) error); ok {
r1 = rf(teamId, trigger)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// 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)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(teamId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
r0 = ret.Error(0)
}
return r0
}
// 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)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(userId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
r0 = ret.Error(0)
}
return r0
}
// 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)
var r0 *model.Command
@@ -173,20 +159,18 @@ func (_m *CommandStore) Save(webhook *model.Command) (*model.Command, *model.App
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
r1 = rf(webhook)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1
}
// 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)
var r0 *model.Command
@@ -198,13 +182,11 @@ func (_m *CommandStore) Update(hook *model.Command) (*model.Command, *model.AppE
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.Command) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(*model.Command) error); ok {
r1 = rf(hook)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
r1 = ret.Error(1)
}
return r0, r1

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

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