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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a28183b078
Коммит
9bf94bf6c1
@@ -156,6 +156,11 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
*cfg.PluginSettings.MarketplaceURL = *appCfg.PluginSettings.MarketplaceURL
|
*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 {
|
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
|
||||||
c.Err = appErr
|
c.Err = appErr
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -130,6 +130,23 @@ func (ch *Channels) syncPluginsActiveState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pluginEnabled {
|
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)
|
enabledPlugins = append(enabledPlugins, plugin)
|
||||||
} else {
|
} else {
|
||||||
disabledPlugins = append(disabledPlugins, plugin)
|
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)
|
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) {
|
ch.cfgSvc.UpdateConfig(func(cfg *model.Config) {
|
||||||
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
|
cfg.PluginSettings.PluginStates[id] = &model.PluginState{Enable: true}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5915,6 +5915,10 @@
|
|||||||
"id": "app.plugin.not_installed.app_error",
|
"id": "app.plugin.not_installed.app_error",
|
||||||
"translation": "Plugin is not installed."
|
"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",
|
"id": "app.plugin.remove.app_error",
|
||||||
"translation": "Unable to delete plugin."
|
"translation": "Unable to delete plugin."
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (env *Environment) IsActive(id string) bool {
|
|||||||
return env.GetPluginState(id) == model.PluginStateRunning
|
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 {
|
if rp, ok := env.registeredPlugins.Load(id); ok {
|
||||||
p := rp.(registeredPlugin)
|
p := rp.(registeredPlugin)
|
||||||
p.Error = err
|
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) {
|
func (env *Environment) Activate(id string) (manifest *model.Manifest, activated bool, reterr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if reterr != nil {
|
if reterr != nil {
|
||||||
env.setPluginError(id, reterr.Error())
|
env.SetPluginError(id, reterr.Error())
|
||||||
} else {
|
} else {
|
||||||
env.setPluginError(id, "")
|
env.SetPluginError(id, "")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user