summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-11-21 14:15:10 -0500
committerGitHub <noreply@github.com>2017-11-21 14:15:10 -0500
commit0bc17001c4423844f76798f12e4277916ca8bd4d (patch)
tree296855f3248c0b5e3e0a3575761f2fbf301a493f /app
parenta6694058a7dc970ce53904f8ac637f7fd2cd772b (diff)
downloadchat-0bc17001c4423844f76798f12e4277916ca8bd4d.tar.gz
chat-0bc17001c4423844f76798f12e4277916ca8bd4d.tar.bz2
chat-0bc17001c4423844f76798f12e4277916ca8bd4d.zip
Do not allow installation of plugins with the same ID (#7870)
Diffstat (limited to 'app')
-rw-r--r--app/plugins.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/app/plugins.go b/app/plugins.go
index 43b7a7451..8f81086df 100644
--- a/app/plugins.go
+++ b/app/plugins.go
@@ -330,23 +330,23 @@ func (a *App) ActivatePlugins() {
// InstallPlugin unpacks and installs a plugin but does not activate it.
func (a *App) InstallPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) {
if a.PluginEnv == nil || !*a.Config().PluginSettings.Enable {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
}
tmpDir, err := ioutil.TempDir("", "plugintmp")
if err != nil {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError)
}
defer os.RemoveAll(tmpDir)
if err := utils.ExtractTarGz(pluginFile, tmpDir); err != nil {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.extract.app_error", nil, err.Error(), http.StatusBadRequest)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.extract.app_error", nil, err.Error(), http.StatusBadRequest)
}
tmpPluginDir := tmpDir
dir, err := ioutil.ReadDir(tmpDir)
if err != nil {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.filesystem.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if len(dir) == 1 && dir[0].IsDir() {
@@ -355,12 +355,23 @@ func (a *App) InstallPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppEr
manifest, _, err := model.FindManifest(tmpPluginDir)
if err != nil {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.manifest.app_error", nil, err.Error(), http.StatusBadRequest)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.manifest.app_error", nil, err.Error(), http.StatusBadRequest)
+ }
+
+ bundles, err := a.PluginEnv.Plugins()
+ if err != nil {
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.install.app_error", nil, err.Error(), http.StatusInternalServerError)
+ }
+
+ for _, bundle := range bundles {
+ if bundle.Manifest.Id == manifest.Id {
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest)
+ }
}
err = utils.CopyDir(tmpPluginDir, filepath.Join(a.PluginEnv.SearchPath(), manifest.Id))
if err != nil {
- return nil, model.NewAppError("UnpackAndActivatePlugin", "app.plugin.mvdir.app_error", nil, err.Error(), http.StatusInternalServerError)
+ return nil, model.NewAppError("InstallPlugin", "app.plugin.mvdir.app_error", nil, err.Error(), http.StatusInternalServerError)
}
// Should add manifest validation and error handling here