Skip to content

Commit

Permalink
PLT-7709 Add UI settings to plugin manifest (#7794)
Browse files Browse the repository at this point in the history
* Add UI settings to plugin manifest

* Add another test case

* Add options field to setting

* Updates per feedback

* Report diagnostics on if plugins have settings set

* Add regenerate_help_text field
  • Loading branch information
jwilander committed Nov 8, 2017
1 parent 1d1998c commit 5ef7277
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 8 deletions.
10 changes: 10 additions & 0 deletions app/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ func (a *App) trackPlugins() {
totalInactiveCount := -1 // -1 to indicate disabled or error
webappInactiveCount := 0
backendInactiveCount := 0
settingsCount := 0

plugins, _ := a.GetPluginManifests()

Expand All @@ -513,6 +514,10 @@ func (a *App) trackPlugins() {
if plugin.Backend != nil {
backendActiveCount += 1
}

if plugin.SettingsSchema != nil {
settingsCount += 1
}
}

totalInactiveCount = len(plugins.Inactive)
Expand All @@ -525,6 +530,10 @@ func (a *App) trackPlugins() {
if plugin.Backend != nil {
backendInactiveCount += 1
}

if plugin.SettingsSchema != nil {
settingsCount += 1
}
}
}

Expand All @@ -535,6 +544,7 @@ func (a *App) trackPlugins() {
"inactive_plugins": totalInactiveCount,
"inactive_webapp_plugins": webappInactiveCount,
"inactive_backend_plugins": backendInactiveCount,
"plugins_with_settings": settingsCount,
})
}
}
Expand Down
43 changes: 36 additions & 7 deletions model/manifest.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model
Expand All @@ -13,13 +13,42 @@ import (
"gopkg.in/yaml.v2"
)

const (
PLUGIN_CONFIG_TYPE_TEXT = "text"
PLUGIN_CONFIG_TYPE_BOOL = "bool"
PLUGIN_CONFIG_TYPE_RADIO = "radio"
PLUGIN_CONFIG_TYPE_DROPDOWN = "dropdown"
PLUGIN_CONFIG_TYPE_GENERATED = "generated"
)

type PluginOption struct {
DisplayName string `json:"display_name" yaml:"display_name"`
Value string `json:"value" yaml:"value"`
}

type PluginSetting struct {
DisplayName string `json:"display_name" yaml:"display_name"`
Type string `json:"type" yaml:"type"`
HelpText string `json:"help_text" yaml:"help_text"`
RegenerateHelpText string `json:"regenerate_help_text,omitempty" yaml:"regenerate_help_text,omitempty"`
Default interface{} `json:"default" yaml:"default"`
Options []*PluginOption `json:"options,omitempty" yaml:"options,omitempty"`
}

type PluginSettingsSchema struct {
Header string `json:"header" yaml:"header"`
Footer string `json:"footer" yaml:"footer"`
Settings map[string]*PluginSetting `json:"settings" yaml:"settings"`
}

type Manifest struct {
Id string `json:"id" yaml:"id"`
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"`
Id string `json:"id" yaml:"id"`
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"`
SettingsSchema *PluginSettingsSchema `json:"settings_schema,omitempty" yaml:"settings_schema,omitempty"`
}

type ManifestBackend struct {
Expand Down
96 changes: 95 additions & 1 deletion model/manifest_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
Expand Down Expand Up @@ -64,6 +67,25 @@ func TestManifestUnmarshal(t *testing.T) {
Webapp: &ManifestWebapp{
BundlePath: "thebundlepath",
},
SettingsSchema: &PluginSettingsSchema{
Header: "theheadertext",
Footer: "thefootertext",
Settings: map[string]*PluginSetting{
"thesetting": &PluginSetting{
DisplayName: "thedisplayname",
Type: PLUGIN_CONFIG_TYPE_DROPDOWN,
HelpText: "thehelptext",
RegenerateHelpText: "theregeneratehelptext",
Options: []*PluginOption{
&PluginOption{
DisplayName: "theoptiondisplayname",
Value: "thevalue",
},
},
Default: "thedefault",
},
},
},
}

var yamlResult Manifest
Expand All @@ -73,6 +95,19 @@ backend:
executable: theexecutable
webapp:
bundle_path: thebundlepath
settings_schema:
header: theheadertext
footer: thefootertext
settings:
thesetting:
display_name: thedisplayname
type: dropdown
help_text: thehelptext
regenerate_help_text: theregeneratehelptext
options:
- display_name: theoptiondisplayname
value: thevalue
default: thedefault
`), &yamlResult))
assert.Equal(t, expected, yamlResult)

Expand All @@ -84,7 +119,26 @@ webapp:
},
"webapp": {
"bundle_path": "thebundlepath"
}
},
"settings_schema": {
"header": "theheadertext",
"footer": "thefootertext",
"settings": {
"thesetting": {
"display_name": "thedisplayname",
"type": "dropdown",
"help_text": "thehelptext",
"regenerate_help_text": "theregeneratehelptext",
"options": [
{
"display_name": "theoptiondisplayname",
"value": "thevalue"
}
],
"default": "thedefault"
}
}
}
}`), &jsonResult))
assert.Equal(t, expected, jsonResult)
}
Expand Down Expand Up @@ -115,6 +169,25 @@ func TestManifestJson(t *testing.T) {
Webapp: &ManifestWebapp{
BundlePath: "thebundlepath",
},
SettingsSchema: &PluginSettingsSchema{
Header: "theheadertext",
Footer: "thefootertext",
Settings: map[string]*PluginSetting{
"thesetting": &PluginSetting{
DisplayName: "thedisplayname",
Type: PLUGIN_CONFIG_TYPE_DROPDOWN,
HelpText: "thehelptext",
RegenerateHelpText: "theregeneratehelptext",
Options: []*PluginOption{
&PluginOption{
DisplayName: "theoptiondisplayname",
Value: "thevalue",
},
},
Default: "thedefault",
},
},
},
}

json := manifest.ToJson()
Expand Down Expand Up @@ -159,13 +232,33 @@ func TestManifestClientManifest(t *testing.T) {
Webapp: &ManifestWebapp{
BundlePath: "thebundlepath",
},
SettingsSchema: &PluginSettingsSchema{
Header: "theheadertext",
Footer: "thefootertext",
Settings: map[string]*PluginSetting{
"thesetting": &PluginSetting{
DisplayName: "thedisplayname",
Type: PLUGIN_CONFIG_TYPE_DROPDOWN,
HelpText: "thehelptext",
RegenerateHelpText: "theregeneratehelptext",
Options: []*PluginOption{
&PluginOption{
DisplayName: "theoptiondisplayname",
Value: "thevalue",
},
},
Default: "thedefault",
},
},
},
}

sanitized := manifest.ClientManifest()

assert.NotEmpty(t, sanitized.Id)
assert.NotEmpty(t, sanitized.Version)
assert.NotEmpty(t, sanitized.Webapp)
assert.NotEmpty(t, sanitized.SettingsSchema)
assert.Empty(t, sanitized.Name)
assert.Empty(t, sanitized.Description)
assert.Empty(t, sanitized.Backend)
Expand All @@ -176,4 +269,5 @@ func TestManifestClientManifest(t *testing.T) {
assert.NotEmpty(t, manifest.Name)
assert.NotEmpty(t, manifest.Description)
assert.NotEmpty(t, manifest.Backend)
assert.NotEmpty(t, manifest.SettingsSchema)
}

0 comments on commit 5ef7277

Please sign in to comment.