summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api4/plugin.go2
-rw-r--r--app/plugin.go21
-rw-r--r--app/plugin_install.go14
-rw-r--r--cmd/mattermost/commands/plugin.go2
-rw-r--r--i18n/en.json4
5 files changed, 37 insertions, 6 deletions
diff --git a/api4/plugin.go b/api4/plugin.go
index 90ea25b2d..5bedb57d0 100644
--- a/api4/plugin.go
+++ b/api4/plugin.go
@@ -66,7 +66,7 @@ func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
- manifest, unpackErr := c.App.InstallPlugin(file)
+ manifest, unpackErr := c.App.InstallPlugin(file, false)
if unpackErr != nil {
c.Err = unpackErr
diff --git a/app/plugin.go b/app/plugin.go
index 8fce76f39..8838e31a9 100644
--- a/app/plugin.go
+++ b/app/plugin.go
@@ -6,11 +6,13 @@ package app
import (
"net/http"
"os"
+ "path/filepath"
"strings"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/plugin"
+ "github.com/mattermost/mattermost-server/utils"
)
func (a *App) SyncPluginsActiveState() {
@@ -101,6 +103,25 @@ func (a *App) InitPlugins(pluginDir, webappPluginDir string) {
a.Plugins = env
}
+ prepackagedPluginsDir, found := utils.FindDir("prepackaged_plugins")
+ if found {
+ if err := filepath.Walk(prepackagedPluginsDir, func(walkPath string, info os.FileInfo, err error) error {
+ if !strings.HasSuffix(walkPath, ".tar.gz") {
+ return nil
+ }
+
+ if fileReader, err := os.Open(walkPath); err != nil {
+ mlog.Error("Failed to open prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath))
+ } else if _, err := a.InstallPlugin(fileReader, true); err != nil {
+ mlog.Error("Failed to unpack prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath))
+ }
+
+ return nil
+ }); err != nil {
+ mlog.Error("Failed to complete unpacking prepackaged plugins", mlog.Err(err))
+ }
+ }
+
// Sync plugin active state when config changes. Also notify plugins.
a.RemoveConfigListener(a.PluginConfigListenerId)
a.PluginConfigListenerId = a.AddConfigListener(func(*model.Config, *model.Config) {
diff --git a/app/plugin_install.go b/app/plugin_install.go
index f96c75f06..b97fbc5d5 100644
--- a/app/plugin_install.go
+++ b/app/plugin_install.go
@@ -17,11 +17,11 @@ import (
)
// InstallPlugin unpacks and installs a plugin but does not enable or activate it.
-func (a *App) InstallPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
- return a.installPlugin(pluginFile)
+func (a *App) InstallPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
+ return a.installPlugin(pluginFile, replace)
}
-func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
+func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
if a.Plugins == nil || !*a.Config().PluginSettings.Enable {
return nil, model.NewAppError("installPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
@@ -63,7 +63,13 @@ func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppEr
// Check that there is no plugin with the same ID
for _, bundle := range bundles {
if bundle.Manifest != nil && bundle.Manifest.Id == manifest.Id {
- return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest)
+ if !replace {
+ return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest)
+ }
+
+ if err := a.RemovePlugin(manifest.Id); err != nil {
+ return nil, model.NewAppError("installPlugin", "app.plugin.install_id_failed_remove.app_error", nil, "", http.StatusBadRequest)
+ }
}
}
diff --git a/cmd/mattermost/commands/plugin.go b/cmd/mattermost/commands/plugin.go
index 56a57ddf1..810e972ad 100644
--- a/cmd/mattermost/commands/plugin.go
+++ b/cmd/mattermost/commands/plugin.go
@@ -83,7 +83,7 @@ func pluginAddCmdF(command *cobra.Command, args []string) error {
return err
}
- if _, err := a.InstallPlugin(fileReader); err != nil {
+ if _, err := a.InstallPlugin(fileReader, false); err != nil {
CommandPrintErrorln("Unable to add plugin: " + args[i] + ". Error: " + err.Error())
} else {
CommandPrettyPrintln("Added plugin: " + plugin)
diff --git a/i18n/en.json b/i18n/en.json
index 629bebc8b..986dfc81b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -3075,6 +3075,10 @@
"translation": "Unable to install plugin. A plugin with the same ID is already installed."
},
{
+ "id": "app.plugin.install_id_failed_remove.app_error",
+ "translation": "Unable to install plugin. A plugin with the same ID is already installed and failed to be removed."
+ },
+ {
"id": "app.plugin.invalid_id.app_error",
"translation": "Plugin Id must be at least {{.Min}} characters, at most {{.Max}} characters and match {{.Regex}}."
},