app type transition (#7167)
Этот коммит содержится в:
112
app/webhook.go
112
app/webhook.go
@@ -22,7 +22,7 @@ const (
|
||||
TRIGGERWORDS_STARTS_WITH = 1
|
||||
)
|
||||
|
||||
func handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
|
||||
func (a *App) handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) *model.AppError {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Chan
|
||||
return nil
|
||||
}
|
||||
|
||||
hchan := Srv.Store.Webhook().GetOutgoingByTeam(team.Id, -1, -1)
|
||||
hchan := a.Srv.Store.Webhook().GetOutgoingByTeam(team.Id, -1, -1)
|
||||
result := <-hchan
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
@@ -80,13 +80,13 @@ func handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Chan
|
||||
TriggerWord: triggerWord,
|
||||
FileIds: strings.Join(post.FileIds, ","),
|
||||
}
|
||||
go TriggerWebhook(payload, hook, post, channel)
|
||||
go a.TriggerWebhook(payload, hook, post, channel)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel) {
|
||||
func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingWebhook, post *model.Post, channel *model.Channel) {
|
||||
var body io.Reader
|
||||
var contentType string
|
||||
if hook.ContentType == "application/json" {
|
||||
@@ -109,7 +109,7 @@ func TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingW
|
||||
respProps := model.MapFromJson(resp.Body)
|
||||
|
||||
if text, ok := respProps["text"]; ok {
|
||||
if _, err := CreateWebhookPost(hook.CreatorId, channel, text, respProps["username"], respProps["icon_url"], post.Props, post.Type); err != nil {
|
||||
if _, err := a.CreateWebhookPost(hook.CreatorId, channel, text, respProps["username"], respProps["icon_url"], post.Props, post.Type); err != nil {
|
||||
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err)
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.OutgoingW
|
||||
}
|
||||
}
|
||||
|
||||
func CreateWebhookPost(userId string, channel *model.Channel, text, overrideUsername, overrideIconUrl string, props model.StringInterface, postType string) (*model.Post, *model.AppError) {
|
||||
func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, overrideUsername, overrideIconUrl string, props model.StringInterface, postType string) (*model.Post, *model.AppError) {
|
||||
// parse links into Markdown format
|
||||
linkWithTextRegex := regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
|
||||
text = linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
|
||||
@@ -173,7 +173,7 @@ func CreateWebhookPost(userId string, channel *model.Channel, text, overrideUser
|
||||
post.UpdateAt = 0
|
||||
post.CreateAt = 0
|
||||
post.Message = txt
|
||||
if _, err := CreatePostMissingChannel(post, false); err != nil {
|
||||
if _, err := a.CreatePostMissingChannel(post, false); err != nil {
|
||||
return nil, model.NewAppError("CreateWebhookPost", "api.post.create_webhook_post.creating.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func CreateWebhookPost(userId string, channel *model.Channel, text, overrideUser
|
||||
return firstPost, nil
|
||||
}
|
||||
|
||||
func CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
func (a *App) CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, hook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("CreateIncomingWebhookForChannel", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -197,14 +197,14 @@ func CreateIncomingWebhookForChannel(creatorId string, channel *model.Channel, h
|
||||
hook.UserId = creatorId
|
||||
hook.TeamId = channel.TeamId
|
||||
|
||||
if result := <-Srv.Store.Webhook().SaveIncoming(hook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().SaveIncoming(hook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.IncomingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
func (a *App) UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("UpdateIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -216,70 +216,70 @@ func UpdateIncomingWebhook(oldHook, updatedHook *model.IncomingWebhook) (*model.
|
||||
updatedHook.TeamId = oldHook.TeamId
|
||||
updatedHook.DeleteAt = oldHook.DeleteAt
|
||||
|
||||
if result := <-Srv.Store.Webhook().UpdateIncoming(updatedHook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateIncoming(updatedHook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.IncomingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteIncomingWebhook(hookId string) *model.AppError {
|
||||
func (a *App) DeleteIncomingWebhook(hookId string) *model.AppError {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return model.NewAppError("DeleteIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().DeleteIncoming(hookId, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().DeleteIncoming(hookId, model.GetMillis()); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
InvalidateCacheForWebhook(hookId)
|
||||
a.InvalidateCacheForWebhook(hookId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) {
|
||||
func (a *App) GetIncomingWebhook(hookId string) (*model.IncomingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhook", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetIncoming(hookId, true); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetIncoming(hookId, true); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.IncomingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
func (a *App) GetIncomingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhooksForTeamPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetIncomingByTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetIncomingByTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.IncomingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
func (a *App) GetIncomingWebhooksPage(page, perPage int) ([]*model.IncomingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return nil, model.NewAppError("GetIncomingWebhooksPage", "api.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetIncomingList(page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetIncomingList(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.IncomingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if len(hook.ChannelId) != 0 {
|
||||
cchan := Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
cchan := a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
|
||||
var channel *model.Channel
|
||||
if result := <-cchan; result.Err != nil {
|
||||
@@ -299,7 +299,7 @@ func CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook,
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "api.webhook.create_outgoing.triggers.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingByTeam(hook.TeamId, -1, -1); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingByTeam(hook.TeamId, -1, -1); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
allHooks := result.Data.([]*model.OutgoingWebhook)
|
||||
@@ -314,20 +314,20 @@ func CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.OutgoingWebhook,
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().SaveOutgoing(hook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().SaveOutgoing(hook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("UpdateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if len(updatedHook.ChannelId) > 0 {
|
||||
channel, err := GetChannel(updatedHook.ChannelId)
|
||||
channel, err := a.GetChannel(updatedHook.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -344,7 +344,7 @@ func UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.
|
||||
}
|
||||
|
||||
var result store.StoreResult
|
||||
if result = <-Srv.Store.Webhook().GetOutgoingByTeam(oldHook.TeamId, -1, -1); result.Err != nil {
|
||||
if result = <-a.Srv.Store.Webhook().GetOutgoingByTeam(oldHook.TeamId, -1, -1); result.Err != nil {
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
@@ -365,93 +365,93 @@ func UpdateOutgoingWebhook(oldHook, updatedHook *model.OutgoingWebhook) (*model.
|
||||
updatedHook.TeamId = oldHook.TeamId
|
||||
updatedHook.UpdateAt = model.GetMillis()
|
||||
|
||||
if result = <-Srv.Store.Webhook().UpdateOutgoing(updatedHook); result.Err != nil {
|
||||
if result = <-a.Srv.Store.Webhook().UpdateOutgoing(updatedHook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) GetOutgoingWebhook(hookId string) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoing(hookId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoing(hookId); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) GetOutgoingWebhooksPage(page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingList(page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingList(page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) GetOutgoingWebhooksForChannelPage(channelId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksForChannelPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingByChannel(channelId, page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingByChannel(channelId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) GetOutgoingWebhooksForTeamPage(teamId string, page, perPage int) ([]*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("GetOutgoingWebhooksForTeamPage", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().GetOutgoingByTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().GetOutgoingByTeam(teamId, page*perPage, perPage); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.([]*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteOutgoingWebhook(hookId string) *model.AppError {
|
||||
func (a *App) DeleteOutgoingWebhook(hookId string) *model.AppError {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return model.NewAppError("DeleteOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().DeleteOutgoing(hookId, model.GetMillis()); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().DeleteOutgoing(hookId, model.GetMillis()); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
func (a *App) RegenOutgoingWebhookToken(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) {
|
||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||
return nil, model.NewAppError("RegenOutgoingWebhookToken", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
hook.Token = model.NewId()
|
||||
|
||||
if result := <-Srv.Store.Webhook().UpdateOutgoing(hook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Webhook().UpdateOutgoing(hook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.OutgoingWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError {
|
||||
func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *model.AppError {
|
||||
if !utils.Cfg.ServiceSettings.EnableIncomingWebhooks {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
hchan := Srv.Store.Webhook().GetIncoming(hookId, true)
|
||||
hchan := a.Srv.Store.Webhook().GetIncoming(hookId, true)
|
||||
|
||||
if req == nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.parse.app_error", nil, "", http.StatusBadRequest)
|
||||
@@ -493,22 +493,22 @@ func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *mo
|
||||
|
||||
if len(channelName) != 0 {
|
||||
if channelName[0] == '@' {
|
||||
if result := <-Srv.Store.User().GetByUsername(channelName[1:]); result.Err != nil {
|
||||
if result := <-a.Srv.Store.User().GetByUsername(channelName[1:]); result.Err != nil {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "err="+result.Err.Message, http.StatusBadRequest)
|
||||
} else {
|
||||
if ch, err := GetDirectChannel(hook.UserId, result.Data.(*model.User).Id); err != nil {
|
||||
if ch, err := a.GetDirectChannel(hook.UserId, result.Data.(*model.User).Id); err != nil {
|
||||
return err
|
||||
} else {
|
||||
channel = ch
|
||||
}
|
||||
}
|
||||
} else if channelName[0] == '#' {
|
||||
cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName[1:], true)
|
||||
cchan = a.Srv.Store.Channel().GetByName(hook.TeamId, channelName[1:], true)
|
||||
} else {
|
||||
cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName, true)
|
||||
cchan = a.Srv.Store.Channel().GetByName(hook.TeamId, channelName, true)
|
||||
}
|
||||
} else {
|
||||
cchan = Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
cchan = a.Srv.Store.Channel().Get(hook.ChannelId, true)
|
||||
}
|
||||
|
||||
if channel == nil {
|
||||
@@ -525,21 +525,21 @@ func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *mo
|
||||
return model.NewLocAppError("HandleIncomingWebhook", "api.post.create_post.town_square_read_only", nil, "")
|
||||
}
|
||||
|
||||
if channel.Type != model.CHANNEL_OPEN && !HasPermissionToChannel(hook.UserId, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
if channel.Type != model.CHANNEL_OPEN && !a.HasPermissionToChannel(hook.UserId, channel.Id, model.PERMISSION_READ_CHANNEL) {
|
||||
return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
overrideUsername := req.Username
|
||||
overrideIconUrl := req.IconURL
|
||||
|
||||
if _, err := CreateWebhookPost(hook.UserId, channel, text, overrideUsername, overrideIconUrl, req.Props, webhookType); err != nil {
|
||||
if _, err := a.CreateWebhookPost(hook.UserId, channel, text, overrideUsername, overrideIconUrl, req.Props, webhookType); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateCommandWebhook(commandId string, args *model.CommandArgs) (*model.CommandWebhook, *model.AppError) {
|
||||
func (a *App) CreateCommandWebhook(commandId string, args *model.CommandArgs) (*model.CommandWebhook, *model.AppError) {
|
||||
hook := &model.CommandWebhook{
|
||||
CommandId: commandId,
|
||||
UserId: args.UserId,
|
||||
@@ -548,27 +548,27 @@ func CreateCommandWebhook(commandId string, args *model.CommandArgs) (*model.Com
|
||||
ParentId: args.ParentId,
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.CommandWebhook().Save(hook); result.Err != nil {
|
||||
if result := <-a.Srv.Store.CommandWebhook().Save(hook); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
return result.Data.(*model.CommandWebhook), nil
|
||||
}
|
||||
}
|
||||
|
||||
func HandleCommandWebhook(hookId string, response *model.CommandResponse) *model.AppError {
|
||||
func (a *App) HandleCommandWebhook(hookId string, response *model.CommandResponse) *model.AppError {
|
||||
if response == nil {
|
||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.parse.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
var hook *model.CommandWebhook
|
||||
if result := <-Srv.Store.CommandWebhook().Get(hookId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.CommandWebhook().Get(hookId); result.Err != nil {
|
||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode)
|
||||
} else {
|
||||
hook = result.Data.(*model.CommandWebhook)
|
||||
}
|
||||
|
||||
var cmd *model.Command
|
||||
if result := <-Srv.Store.Command().Get(hook.CommandId); result.Err != nil {
|
||||
if result := <-a.Srv.Store.Command().Get(hook.CommandId); result.Err != nil {
|
||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.command.app_error", nil, "err="+result.Err.Message, http.StatusBadRequest)
|
||||
} else {
|
||||
cmd = result.Data.(*model.Command)
|
||||
@@ -582,10 +582,10 @@ func HandleCommandWebhook(hookId string, response *model.CommandResponse) *model
|
||||
ParentId: hook.ParentId,
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.CommandWebhook().TryUse(hook.Id, 5); result.Err != nil {
|
||||
if result := <-a.Srv.Store.CommandWebhook().TryUse(hook.Id, 5); result.Err != nil {
|
||||
return model.NewAppError("HandleCommandWebhook", "web.command_webhook.invalid.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode)
|
||||
}
|
||||
|
||||
_, err := HandleCommandResponse(cmd, args, response, false)
|
||||
_, err := a.HandleCommandResponse(cmd, args, response, false)
|
||||
return err
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user