From 04749027f62a6c830bdc33b793c24c13b9fb8ba2 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Fri, 3 Aug 2018 13:15:51 -0400 Subject: 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) --- app/file.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'app/file.go') 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 } } -- cgit v1.2.3-1-g7c22