MM-47249: Blocklist focalboard plugin in product mode (#21243)

We prevent the plugin from starting if in product mode,
and also give pretty errors to make it clear to the users.

https://mattermost.atlassian.net/browse/MM-47249

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-10-08 10:21:22 +05:30
коммит произвёл GitHub
родитель a28183b078
Коммит 9bf94bf6c1
4 изменённых файлов: 33 добавлений и 3 удалений

Просмотреть файл

@@ -156,6 +156,11 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
*cfg.PluginSettings.MarketplaceURL = *appCfg.PluginSettings.MarketplaceURL
}
if cfg.PluginSettings.PluginStates[model.PluginIdFocalboard].Enable && cfg.FeatureFlags.BoardsProduct {
c.Err = model.NewAppError("EnablePlugin", "app.plugin.product_mode.app_error", map[string]any{"Name": model.PluginIdFocalboard}, "", http.StatusInternalServerError)
return
}
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
c.Err = appErr
return

Просмотреть файл

@@ -130,6 +130,23 @@ func (ch *Channels) syncPluginsActiveState() {
}
if pluginEnabled {
// Disable focalboard in product mode.
if pluginID == model.PluginIdFocalboard && ch.cfgSvc.Config().FeatureFlags.BoardsProduct {
msg := "Plugin cannot run in product mode. Disabling."
mlog.Warn(msg, mlog.String("plugin_id", model.PluginIdFocalboard))
// This is a mini-version of ch.disablePlugin.
// We don't call that directly, because that will recursively call
// this method.
ch.cfgSvc.UpdateConfig(func(cfg *model.Config) {
cfg.PluginSettings.PluginStates[pluginID] = &model.PluginState{Enable: false}
})
pluginsEnvironment.SetPluginError(pluginID, msg)
ch.unregisterPluginCommands(pluginID)
disabledPlugins = append(disabledPlugins, plugin)
continue
}
enabledPlugins = append(enabledPlugins, plugin)
} else {
disabledPlugins = append(disabledPlugins, plugin)
@@ -438,6 +455,10 @@ func (ch *Channels) enablePlugin(id string) *model.AppError {
return model.NewAppError("EnablePlugin", "app.plugin.not_installed.app_error", nil, "", http.StatusNotFound)
}
if id == model.PluginIdFocalboard && ch.cfgSvc.Config().FeatureFlags.BoardsProduct {
return model.NewAppError("EnablePlugin", "app.plugin.product_mode.app_error", map[string]any{"Name": model.PluginIdFocalboard}, "", http.StatusInternalServerError)
}
ch.cfgSvc.UpdateConfig(func(cfg *model.Config) {
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
})

Просмотреть файл

@@ -5915,6 +5915,10 @@
"id": "app.plugin.not_installed.app_error",
"translation": "Plugin is not installed."
},
{
"id": "app.plugin.product_mode.app_error",
"translation": "Plugin {{.Name}} cannot be enabled in product mode."
},
{
"id": "app.plugin.remove.app_error",
"translation": "Unable to delete plugin."

Просмотреть файл

@@ -137,7 +137,7 @@ func (env *Environment) IsActive(id string) bool {
return env.GetPluginState(id) == model.PluginStateRunning
}
func (env *Environment) setPluginError(id string, err string) {
func (env *Environment) SetPluginError(id string, err string) {
if rp, ok := env.registeredPlugins.Load(id); ok {
p := rp.(registeredPlugin)
p.Error = err
@@ -233,9 +233,9 @@ func (env *Environment) GetManifest(pluginId string) (*model.Manifest, error) {
func (env *Environment) Activate(id string) (manifest *model.Manifest, activated bool, reterr error) {
defer func() {
if reterr != nil {
env.setPluginError(id, reterr.Error())
env.SetPluginError(id, reterr.Error())
} else {
env.setPluginError(id, "")
env.SetPluginError(id, "")
}
}()