PLT-7622 Improvements to server handling of webapp plugins (#7445)

* Improvements to server handling of webapp plugins

* Fix newline

* Update manifest function names
Этот коммит содержится в:
Joram Wilander
2017-09-15 08:51:46 -04:00
коммит произвёл GitHub
родитель 2a6cd44f23
Коммит 2628022275
12 изменённых файлов: 184 добавлений и 63 удалений

Просмотреть файл

@@ -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)
}
}

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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)
}

Просмотреть файл

@@ -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 {