Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ Hosts read the field from the capability metadata stored when the plugin was
installed or updated, so it takes effect after the plugin is next updated on a
host that reads it.

`AdminFormSection.add_group` and `add_label` turn sections into the slots of a
list the admin grows with a button. Empty means an ordinary section, which is
the behaviour hosts had before the fields existed. Hosts that predate them drop
them as unknown fields when they install a plugin archive, and show every slot
as its own section, so the form still works there. Silo reads a bare plugin
binary's manifest strictly, so a Silo host that predates the fields refuses to
install a binary that declares them; install it from an archive there. The
slots' fields are ordinary config keys, so nothing changes in what the plugin
reads.

`AdminFormField.ordered` says that the order of a multi-select's values
matters. False is the behaviour hosts had before the field existed: the values
are stored in the order they were chosen and cannot be rearranged. Hosts that
predate the field drop it when they install a plugin archive and show the
multi-select as before, and a Silo host that predates it refuses a bare plugin
binary that declares it. The stored value is the same list of values either
way.

`MetadataItem.overview_language` and the `title_language` and
`overview_language` fields on `SeasonRecord` and `EpisodeRecord` (added in
v0.29.0) are plain strings, like the older `MetadataItem.title_language`.
Expand Down
62 changes: 54 additions & 8 deletions pkg/pluginproto/silo/plugin/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions pkg/pluginsdk/manifest/admin_form_rich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,77 @@ func TestForwardReferenceShowWhenPassesValidation(t *testing.T) {
t.Fatalf("Load rejected valid rich admin form with forward-referencing show_when: %v", err)
}
}

// TestSectionAddGroup checks the sections of a list the admin grows: a slot
// needs the label of the button that reveals the next one, and a label needs
// a list.
func TestSectionAddGroup(t *testing.T) {
load := func(sections string) error {
_, err := manifest.Load([]byte(`{
"plugin_id": "silo.example",
"version": "1.0.0",
"silo_api_version": "v1",
"capabilities": [{
"type": "request_router.v1", "id": "arr", "display_name": "X", "description": "Y",
"config_schema": [{
"key": "connection",
"title": "Connection",
"json_schema": "{\"type\":\"object\",\"properties\":{\"a\":{\"type\":\"string\"},\"b\":{\"type\":\"string\"}}}",
"admin_form": {
"fields": [
{"key":"a","label":"A","control":"ADMIN_FORM_CONTROL_TEXT"},
{"key":"b","label":"B","control":"ADMIN_FORM_CONTROL_TEXT"}
],
"sections": ` + sections + `
}
}]
}]
}`))
return err
}
if err := load(`[
{"key":"one","title":"One","field_keys":["a"],"add_group":"slots","add_label":"Add slot"},
{"key":"two","title":"Two","field_keys":["b"],"add_group":"slots","add_label":"Add slot"}]`); err != nil {
t.Fatalf("Load refused a list of slots: %v", err)
}
for name, sections := range map[string]string{
"a slot without a label": `[{"key":"one","title":"One","field_keys":["a"],"add_group":"slots"}]`,
"a label without a list": `[{"key":"one","title":"One","field_keys":["a"],"add_label":"Add slot"}]`,
} {
if err := load(sections); err == nil || !strings.Contains(err.Error(), "add_label") {
t.Fatalf("%s: want an add_label error, got %v", name, err)
}
}
}

// TestOrderedIsForMultiSelect checks that only a multi-select can say the
// order of its values matters.
func TestOrderedIsForMultiSelect(t *testing.T) {
load := func(control string) error {
_, err := manifest.Load([]byte(`{
"plugin_id": "silo.example",
"version": "1.0.0",
"silo_api_version": "v1",
"capabilities": [{
"type": "request_router.v1", "id": "arr", "display_name": "X", "description": "Y",
"config_schema": [{
"key": "connection",
"title": "Connection",
"json_schema": "{\"type\":\"object\",\"properties\":{\"folders\":{\"type\":\"array\"}}}",
"admin_form": {
"fields": [
{"key":"folders","label":"Folders","control":"` + control + `","dynamic_options":true,"ordered":true}
]
}
}]
}]
}`))
return err
}
if err := load("ADMIN_FORM_CONTROL_MULTI_SELECT"); err != nil {
t.Fatalf("Load refused an ordered multi-select: %v", err)
}
if err := load("ADMIN_FORM_CONTROL_SELECT"); err == nil || !strings.Contains(err.Error(), "ordered") {
t.Fatalf("want an ordered error for a select, got %v", err)
}
}
16 changes: 16 additions & 0 deletions pkg/pluginsdk/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ func validateRequesterOptions(descriptor *pluginv1.CapabilityDescriptor) error {
// call and asks ListRemoteState for pages of that size.
const MaxWatchSyncBatchSize = 1000

// MaxAdminFormAddLabelRunes limits an admin form section's add_label, in
// characters.
const MaxAdminFormAddLabelRunes = 40

// Limits on RequestRouterWording values, in characters.
const (
MaxRequestWordingLabelRunes = 24
Expand Down Expand Up @@ -808,6 +812,9 @@ func validateConfigSchema(schema *pluginv1.ConfigSchema) error {
return fmt.Errorf("plugin config schema %q admin_form field %q show_when references unknown field %q", schema.GetKey(), key, cond.GetField())
}
}
if field.GetOrdered() && field.GetControl() != pluginv1.AdminFormControl_ADMIN_FORM_CONTROL_MULTI_SELECT {
return fmt.Errorf("plugin config schema %q admin_form field %q ordered is only for a multi-select", schema.GetKey(), key)
}
if eg := field.GetExclusiveGroupField(); eg != "" {
if !hasReference(eg) {
return fmt.Errorf("plugin config schema %q admin_form field %q exclusive_group_field references unknown field %q", schema.GetKey(), key, eg)
Expand All @@ -818,6 +825,15 @@ func validateConfigSchema(schema *pluginv1.ConfigSchema) error {
if section == nil {
continue
}
if section.GetAddGroup() == "" && section.GetAddLabel() != "" {
return fmt.Errorf("plugin config schema %q admin_form section %q add_label needs add_group", schema.GetKey(), section.GetKey())
}
if section.GetAddGroup() != "" {
label := strings.TrimSpace(section.GetAddLabel())
if label == "" || utf8.RuneCountInString(label) > MaxAdminFormAddLabelRunes {
return fmt.Errorf("plugin config schema %q admin_form section %q add_label must be 1 to %d characters", schema.GetKey(), section.GetKey(), MaxAdminFormAddLabelRunes)
}
}
for _, fk := range section.GetFieldKeys() {
if _, ok := seen[fk]; !ok {
return fmt.Errorf("plugin config schema %q admin_form section %q references unknown field %q", schema.GetKey(), section.GetKey(), fk)
Expand Down
22 changes: 22 additions & 0 deletions proto/silo/plugin/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ message AdminFormField {
// group; at most one connection per distinct value of that field may have THIS
// field truthy. Empty = no exclusivity.
string exclusive_group_field = 15;
// ordered says the order of a MULTI_SELECT's values matters, such as
// folders that are filled one after another. The host shows the chosen
// values as a list the admin can put in order, and stores them in that
// order. False = the values are a set, in no particular order. Only valid
// on ADMIN_FORM_CONTROL_MULTI_SELECT.
bool ordered = 16;
}

// AdminFormCondition: the owning field/section is shown only when, for every
Expand Down Expand Up @@ -90,6 +96,22 @@ message AdminFormSection {
bool collapsed_default = 5;
repeated string field_keys = 6;
repeated AdminFormCondition show_when = 7;
// add_group makes the section one slot of a list the admin grows. Sections
// with the same add_group are its slots, in form order. The form shows the
// first slot and every slot up to the last one that holds a value other
// than its fields' defaults, then a button that reveals the next slot. The
// slots' fields are ordinary config keys, so the list is as long as the
// sections the plugin declares. The admin can also change the order of the
// slots: two slots trade places by trading the values of their fields at
// the same position in field_keys, so every slot of a list declares the
// same fields in the same order. A slot whose first field is a text field
// shows that value in its header. The admin can also remove a slot: the
// slots after it move up one place and the last one is emptied. Empty = an
// ordinary section.
string add_group = 8;
// add_label is the text of that button, such as "Add storage group".
// Required when add_group is set.
string add_label = 9;
}

message AdminFormDescriptor {
Expand Down