From 866e938a12bfdf21641e65fbef04e14d60b7bb33 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 12 Jan 2021 09:30:48 -0800 Subject: [PATCH] MM-31699 Don't downgrade plugins with feature flag for on-prem (#16639) * Don't downgrade plugins with feature flag for on-prem * Update app/plugin.go Co-authored-by: Christopher Poile * Short circut for plugin doesn't exist. Co-authored-by: Christopher Poile --- app/plugin.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/plugin.go b/app/plugin.go index 52da0ccb7a..4baefec1d9 100644 --- a/app/plugin.go +++ b/app/plugin.go @@ -909,11 +909,33 @@ func (a *App) installFeatureFlagPlugins() { // Check if we already installed this version as InstallMarketplacePlugin can't handle re-installs well. pluginStatus, err := a.Srv().GetPluginStatus(pluginId) - if err == nil && pluginStatus.Version == version { + pluginExists := err == nil + if pluginExists && pluginStatus.Version == version { continue } if version != "" && version != "control" { + // If we are on-prem skip installation if this is a downgrade + license := a.Srv().License() + inCloud := license != nil && *license.Features.Cloud + if !inCloud && pluginExists { + parsedVersion, err := semver.Parse(version) + if err != nil { + a.Log().Debug("Bad version from feature flag", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", version)) + return + } + parsedExistingVersion, err := semver.Parse(pluginStatus.Version) + if err != nil { + a.Log().Debug("Bad version from plugin manifest", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", pluginStatus.Version)) + return + } + + if parsedVersion.LTE(parsedExistingVersion) { + a.Log().Debug("Skip installation because given version was a downgrade and on-prem installations should not downgrade.", mlog.String("plugin_id", pluginId), mlog.Err(err), mlog.String("version", pluginStatus.Version)) + return + } + } + _, err := a.InstallMarketplacePlugin(&model.InstallMarketplacePluginRequest{ Id: pluginId, Version: version,