diff options
Diffstat (limited to 'app/plugin_install.go')
-rw-r--r-- | app/plugin_install.go | 14 |
1 files changed, 10 insertions, 4 deletions
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) + } } } |