diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-09-15 08:51:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 08:51:46 -0400 |
commit | 2628022275ef64fde95545abe4634b4bd7177844 (patch) | |
tree | 25d451b81d720f44aa09b20389be7fbb75b7864e /model | |
parent | 2a6cd44f23e1b3207debaa73801f0c63a2c81126 (diff) | |
download | chat-2628022275ef64fde95545abe4634b4bd7177844.tar.gz chat-2628022275ef64fde95545abe4634b4bd7177844.tar.bz2 chat-2628022275ef64fde95545abe4634b4bd7177844.zip |
PLT-7622 Improvements to server handling of webapp plugins (#7445)
* Improvements to server handling of webapp plugins
* Fix newline
* Update manifest function names
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 11 | ||||
-rw-r--r-- | model/manifest.go | 18 | ||||
-rw-r--r-- | model/manifest_test.go | 48 | ||||
-rw-r--r-- | model/websocket_message.go | 2 |
4 files changed, 77 insertions, 2 deletions
diff --git a/model/client4.go b/model/client4.go index c06975697..44c4cf6c9 100644 --- a/model/client4.go +++ b/model/client4.go @@ -3088,3 +3088,14 @@ func (c *Client4) RemovePlugin(id string) (bool, *Response) { return CheckStatusOK(r), BuildResponse(r) } } + +// GetWebappPlugins will return a list of plugins that the webapp should download. +// WARNING: PLUGINS ARE STILL EXPERIMENTAL. THIS FUNCTION IS SUBJECT TO CHANGE. +func (c *Client4) GetWebappPlugins() ([]*Manifest, *Response) { + if r, err := c.DoApiGet(c.GetPluginsRoute()+"/webapp", ""); err != nil { + return nil, BuildErrorResponse(r, err) + } else { + defer closeBody(r) + return ManifestListFromJson(r.Body), BuildResponse(r) + } +} diff --git a/model/manifest.go b/model/manifest.go index e61ccc8ad..b466660af 100644 --- a/model/manifest.go +++ b/model/manifest.go @@ -12,8 +12,9 @@ import ( type Manifest struct { Id string `json:"id" yaml:"id"` - Name string `json:"name" yaml:"name"` - Description string `json:"description" yaml:"description"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Description string `json:"description,omitempty" yaml:"description,omitempty"` + Version string `json:"version" yaml:"version"` Backend *ManifestBackend `json:"backend,omitempty" yaml:"backend,omitempty"` Webapp *ManifestWebapp `json:"webapp,omitempty" yaml:"webapp,omitempty"` } @@ -66,6 +67,19 @@ func ManifestListFromJson(data io.Reader) []*Manifest { } } +func (m *Manifest) HasClient() bool { + return m.Webapp != nil +} + +func (m *Manifest) ClientManifest() *Manifest { + cm := new(Manifest) + *cm = *m + cm.Name = "" + cm.Description = "" + cm.Backend = nil + return cm +} + // FindManifest will find and parse the manifest in a given directory. // // In all cases other than a does-not-exist error, path is set to the path of the manifest file that was diff --git a/model/manifest_test.go b/model/manifest_test.go index 46975cf47..1ec43a217 100644 --- a/model/manifest_test.go +++ b/model/manifest_test.go @@ -129,3 +129,51 @@ func TestManifestJson(t *testing.T) { assert.Equal(t, newManifestList, manifestList) assert.Equal(t, ManifestListToJson(newManifestList), json) } + +func TestManifestHasClient(t *testing.T) { + manifest := &Manifest{ + Id: "theid", + Backend: &ManifestBackend{ + Executable: "theexecutable", + }, + Webapp: &ManifestWebapp{ + BundlePath: "thebundlepath", + }, + } + + assert.True(t, manifest.HasClient()) + + manifest.Webapp = nil + assert.False(t, manifest.HasClient()) +} + +func TestManifestClientManifest(t *testing.T) { + manifest := &Manifest{ + Id: "theid", + Name: "thename", + Description: "thedescription", + Version: "0.0.1", + Backend: &ManifestBackend{ + Executable: "theexecutable", + }, + Webapp: &ManifestWebapp{ + BundlePath: "thebundlepath", + }, + } + + sanitized := manifest.ClientManifest() + + assert.NotEmpty(t, sanitized.Id) + assert.NotEmpty(t, sanitized.Version) + assert.NotEmpty(t, sanitized.Webapp) + assert.Empty(t, sanitized.Name) + assert.Empty(t, sanitized.Description) + assert.Empty(t, sanitized.Backend) + + assert.NotEmpty(t, manifest.Id) + assert.NotEmpty(t, manifest.Version) + assert.NotEmpty(t, manifest.Webapp) + assert.NotEmpty(t, manifest.Name) + assert.NotEmpty(t, manifest.Description) + assert.NotEmpty(t, manifest.Backend) +} diff --git a/model/websocket_message.go b/model/websocket_message.go index 6b8c03427..6c55da6f0 100644 --- a/model/websocket_message.go +++ b/model/websocket_message.go @@ -39,6 +39,8 @@ const ( WEBSOCKET_EVENT_RESPONSE = "response" WEBSOCKET_EVENT_EMOJI_ADDED = "emoji_added" WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed" + WEBSOCKET_EVENT_PLUGIN_ACTIVATED = "plugin_activated" // EXPERIMENTAL - SUBJECT TO CHANGE + WEBSOCKET_EVENT_PLUGIN_DEACTIVATED = "plugin_deactivated" // EXPERIMENTAL - SUBJECT TO CHANGE ) type WebSocketMessage interface { |