diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-02 01:36:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-02 01:36:54 -0700 |
commit | 65817e13c7900ea81947e40e177459cfea8acee4 (patch) | |
tree | 8dfc88db36844e4186b4110753be8de976da6371 /app/webhook.go | |
parent | c6bf235ec2a8613d8ef35607e2aeb8c0cb629f45 (diff) | |
download | chat-65817e13c7900ea81947e40e177459cfea8acee4.tar.gz chat-65817e13c7900ea81947e40e177459cfea8acee4.tar.bz2 chat-65817e13c7900ea81947e40e177459cfea8acee4.zip |
PLT-6965 jira integration (plus plugin scaffolding) (#6918)
* plugin scaffolding / jira integration
* add vendored testify packages
* webhook fix
* don't change i18n ids
* support configuration watching
* add basic jira plugin configuration to admin console
* fix eslint errors
* fix another eslint warning
* polish
* undo unintentional config.json commit >:(
* test fix
* add jira plugin diagnostics, remove dm support, add bot tag, generate web-safe secrets
* rebase, implement requested changes
* requested changes
* remove tests and minimize makefile change
* add missing license headers
* add missing comma
* remove bad line from Makefile
Diffstat (limited to 'app/webhook.go')
-rw-r--r-- | app/webhook.go | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/app/webhook.go b/app/webhook.go index e92805608..29f642ea8 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -490,48 +490,43 @@ func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *mo var channel *model.Channel var cchan store.StoreChannel - var directUserId string if len(channelName) != 0 { if channelName[0] == '@' { if result := <-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 { - directUserId = result.Data.(*model.User).Id - channelName = model.GetDMNameFromIds(directUserId, hook.UserId) + if ch, err := GetDirectChannel(hook.UserId, result.Data.(*model.User).Id); err != nil { + return err + } else { + channel = ch + } } } else if channelName[0] == '#' { - channelName = channelName[1:] + cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName[1:], true) + } else { + cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName, true) } - - cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName, true) } else { cchan = Srv.Store.Channel().Get(hook.ChannelId, true) } - overrideUsername := req.Username - overrideIconUrl := req.IconURL - - result := <-cchan - if result.Err != nil && result.Err.Id == store.MISSING_CHANNEL_ERROR && directUserId != "" { - newChanResult := <-Srv.Store.Channel().CreateDirectChannel(directUserId, hook.UserId) - if newChanResult.Err != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+newChanResult.Err.Message, http.StatusBadRequest) + if channel == nil { + result := <-cchan + if result.Err != nil { + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode) } else { - channel = newChanResult.Data.(*model.Channel) - InvalidateCacheForUser(directUserId) - InvalidateCacheForUser(hook.UserId) + channel = result.Data.(*model.Channel) } - } else if result.Err != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode) - } else { - channel = result.Data.(*model.Channel) } if channel.Type != model.CHANNEL_OPEN && !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, hook.TeamId, channel.Id, text, overrideUsername, overrideIconUrl, req.Props, webhookType); err != nil { return err } |