mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Differentiate between installed and activated states for plugins (#7706)
This commit is contained in:
@@ -3150,12 +3150,12 @@ func (c *Client4) UploadPlugin(file io.Reader) (*Manifest, *Response) {
|
||||
|
||||
// GetPlugins will return a list of plugin manifests for currently active plugins.
|
||||
// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE.
|
||||
func (c *Client4) GetPlugins() ([]*Manifest, *Response) {
|
||||
func (c *Client4) GetPlugins() (*PluginsResponse, *Response) {
|
||||
if r, err := c.DoApiGet(c.GetPluginsRoute(), ""); err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return ManifestListFromJson(r.Body), BuildResponse(r)
|
||||
return PluginsResponseFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3180,3 +3180,25 @@ func (c *Client4) GetWebappPlugins() ([]*Manifest, *Response) {
|
||||
return ManifestListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// ActivatePlugin will activate an plugin installed.
|
||||
// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE.
|
||||
func (c *Client4) ActivatePlugin(id string) (bool, *Response) {
|
||||
if r, err := c.DoApiPost(c.GetPluginRoute(id)+"/activate", ""); err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// DeactivatePlugin will deactivate an active plugin.
|
||||
// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE.
|
||||
func (c *Client4) DeactivatePlugin(id string) (bool, *Response) {
|
||||
if r, err := c.DoApiPost(c.GetPluginRoute(id)+"/deactivate", ""); err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,9 +504,14 @@ type JobSettings struct {
|
||||
RunScheduler *bool
|
||||
}
|
||||
|
||||
type PluginState struct {
|
||||
Enable bool
|
||||
}
|
||||
|
||||
type PluginSettings struct {
|
||||
Enable *bool
|
||||
Plugins map[string]interface{}
|
||||
Enable *bool
|
||||
Plugins map[string]interface{}
|
||||
PluginStates map[string]*PluginState
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -1454,6 +1459,10 @@ func (o *Config) SetDefaults() {
|
||||
o.PluginSettings.Plugins = make(map[string]interface{})
|
||||
}
|
||||
|
||||
if o.PluginSettings.PluginStates == nil {
|
||||
o.PluginSettings.PluginStates = make(map[string]*PluginState)
|
||||
}
|
||||
|
||||
o.defaultWebrtcSettings()
|
||||
}
|
||||
|
||||
|
||||
31
model/plugins_response.go
Normal file
31
model/plugins_response.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type PluginsResponse struct {
|
||||
Active []*Manifest `json:"active"`
|
||||
Inactive []*Manifest `json:"inactive"`
|
||||
}
|
||||
|
||||
func (m *PluginsResponse) ToJson() string {
|
||||
b, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func PluginsResponseFromJson(data io.Reader) *PluginsResponse {
|
||||
decoder := json.NewDecoder(data)
|
||||
var m PluginsResponse
|
||||
err := decoder.Decode(&m)
|
||||
if err == nil {
|
||||
return &m
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
31
model/plugins_response_test.go
Normal file
31
model/plugins_response_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPluginsResponseJson(t *testing.T) {
|
||||
manifest := &Manifest{
|
||||
Id: "theid",
|
||||
Backend: &ManifestBackend{
|
||||
Executable: "theexecutable",
|
||||
},
|
||||
Webapp: &ManifestWebapp{
|
||||
BundlePath: "thebundlepath",
|
||||
},
|
||||
}
|
||||
|
||||
response := &PluginsResponse{
|
||||
Active: []*Manifest{manifest},
|
||||
Inactive: []*Manifest{},
|
||||
}
|
||||
|
||||
json := response.ToJson()
|
||||
newResponse := PluginsResponseFromJson(strings.NewReader(json))
|
||||
assert.Equal(t, newResponse, response)
|
||||
assert.Equal(t, newResponse.ToJson(), json)
|
||||
assert.Equal(t, PluginsResponseFromJson(strings.NewReader("junk")), (*PluginsResponse)(nil))
|
||||
}
|
||||
Reference in New Issue
Block a user