diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-08-03 13:15:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 13:15:51 -0400 |
commit | 04749027f62a6c830bdc33b793c24c13b9fb8ba2 (patch) | |
tree | 6b26ba82453ba6ccc2dcab0a721d0539ae19a351 /app/file.go | |
parent | 1ecb98d9f5a6053a1ee1ce262b6a3306192f6616 (diff) | |
download | chat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.tar.gz chat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.tar.bz2 chat-04749027f62a6c830bdc33b793c24c13b9fb8ba2.zip |
MM-11575: change plugin nil semantics (#9212)
* change MessageWillBePosted nil return semantics
* change FileWillBeUploaded nil return semantics
* use LogDebug to verify plugin inputs vs. the confusing Delete(User|Team)
Diffstat (limited to 'app/file.go')
-rw-r--r-- | app/file.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/file.go b/app/file.go index 7a642a956..d2a145c81 100644 --- a/app/file.go +++ b/app/file.go @@ -435,20 +435,27 @@ func (a *App) DoUploadFileExpectModification(now time.Time, rawTeamId string, ra } if a.PluginsReady() { + var rejectionError *model.AppError pluginContext := &plugin.Context{} - var rejectionReason string a.Plugins.RunMultiPluginHook(func(hooks plugin.Hooks) bool { var newBytes bytes.Buffer - info, rejectionReason = hooks.FileWillBeUploaded(pluginContext, info, bytes.NewReader(data), &newBytes) - rejected := info == nil - if !rejected && newBytes.Len() != 0 { + replacementInfo, rejectionReason := hooks.FileWillBeUploaded(pluginContext, info, bytes.NewReader(data), &newBytes) + if rejectionReason != "" { + rejectionError = model.NewAppError("DoUploadFile", "File rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + return false + } + if replacementInfo != nil { + info = replacementInfo + } + if newBytes.Len() != 0 { data = newBytes.Bytes() info.Size = int64(len(data)) } - return !rejected + + return true }, plugin.FileWillBeUploadedId) - if info == nil { - return nil, data, model.NewAppError("DoUploadFile", "File rejected by plugin. "+rejectionReason, nil, "", http.StatusBadRequest) + if rejectionError != nil { + return nil, data, rejectionError } } |