summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-10-25 08:17:17 -0400
committerGitHub <noreply@github.com>2017-10-25 08:17:17 -0400
commit16b845c0d77535ea306339f7a8bd22fc72f8a3c5 (patch)
treee768b8d1ca5cc3f2e55207ea73c5954b37f708ed /model
parent9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae (diff)
downloadchat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.gz
chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.bz2
chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.zip
Differentiate between installed and activated states for plugins (#7706)
Diffstat (limited to 'model')
-rw-r--r--model/client4.go26
-rw-r--r--model/config.go13
-rw-r--r--model/plugins_response.go31
-rw-r--r--model/plugins_response_test.go31
4 files changed, 97 insertions, 4 deletions
diff --git a/model/client4.go b/model/client4.go
index dc5a25bec..1c20954d8 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -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)
+ }
+}
diff --git a/model/config.go b/model/config.go
index d3446f533..a93defa7f 100644
--- a/model/config.go
+++ b/model/config.go
@@ -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()
}
diff --git a/model/plugins_response.go b/model/plugins_response.go
new file mode 100644
index 000000000..d726e491e
--- /dev/null
+++ b/model/plugins_response.go
@@ -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
+ }
+}
diff --git a/model/plugins_response_test.go b/model/plugins_response_test.go
new file mode 100644
index 000000000..9129c68f7
--- /dev/null
+++ b/model/plugins_response_test.go
@@ -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))
+}