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,