A mode that does not work stops being on the menu
The control-mode picker offered all five paths to everyone, always. When one of them is broken in a deployment — OCPP is, right now — there was nothing to do about it: the superadmin could pick a different mode for the global layer, but the option stayed in every organization's and every user's dropdown, waiting to be chosen. The cascade could impose a mode. It could not withdraw one. So each layer now carries a second, separate thing: a list of the modes it hides from the layers below it. controlModesDisabled sits beside controlMode, on the global layer as a plugin config field and on an organization as part of the same pluginSettings blob its credentials already live in. A superadmin ticking Own CSMS and Proxy CSMS takes both OCPP paths out of every picker underneath; an org admin ticking Modbus takes it out of their own users'. Three decisions are worth naming. A hide-list governs the layers below, not the layer holding it. The superadmin can keep running Proxy globally while hiding it from everyone else, which is what you want while a mode is being repaired rather than retired: the operator testing the fix is the one person who still needs to select it. The alternative, a list that also invalidates its own layer's choice, would have made the panel contradict itself — a mode chosen in one field and switched off in the one below it. But a hidden mode really is hidden, not merely absent from a dropdown. A user who had picked Proxy last month stops resolving to Proxy the moment the superadmin hides it, and falls back to monitoring only. Filtering the picker alone would have left every existing charger on the broken path and quietly disagreed with the list the operator had just filled in. Resolution now walks the layers accumulating what each hides from the next, so a stored value only takes effect if the layers above it still permit it. And off is never hideable. It is what a charger falls back to and what an empty cascade resolves to, so a layer that could take it away could leave the layer below with a picker holding no valid choice at all. It is not among the checkboxes in any of the three clients, and the parser drops it if it arrives anyway. The panel needed a field shape it did not have — several options, any number chosen — so ConfigField grows a "multiselect" type, stored as the comma-separated string that fits the flat map every other field already uses. That is generic: any plugin can declare one now, and the PUT body is unchanged. The phone's field specs grew the same way, a scopeOptions hook that narrows a declared option list to what the server still offers, rather than teaching the integration card about control modes specifically. Both clients clamp a stored mode that has since been hidden back to off before drawing the picker, so the box shows what will actually happen rather than a choice that would be dropped on save. Verified: Go tests pass, both frontends build, flutter analyze is clean, and the panel's new checkbox field was rendered against the real stylesheet. The end-to-end path — superadmin hides a mode, an org admin and then a user reload and find it gone — has not been walked on a live stack; the panel is embedded in the Go binary, so the remote deployment needs a rebuild before any of this is visible there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
d4b9d0870e
commit
3c34b708b9
@@ -334,6 +334,19 @@ func (p *Plugin) Descriptor() plugins.Descriptor {
|
||||
{Value: "own", Label: "Own CSMS (full control)"},
|
||||
{Value: "proxy", Label: "Proxy CSMS (relay + control)"},
|
||||
}},
|
||||
// controlModesDisabled hides modes from the layers *below* this one. It
|
||||
// is how a superadmin takes a mode that is broken or unwanted in this
|
||||
// deployment (OCPP, say) out of every organization's and user's picker
|
||||
// without touching the mode this layer itself runs. Organizations carry
|
||||
// the same field for their own users; see integrations_ankersolix.go.
|
||||
{Key: "controlModesDisabled", Label: "Hidden control modes", Type: "multiselect",
|
||||
Help: "Control modes to hide from organizations and users. A hidden mode disappears from their picker and stops taking effect for them; the mode chosen above, which is this layer's own, is unaffected. Off (monitoring only) can never be hidden — it is what a charger falls back to.",
|
||||
Options: []plugins.SelectOption{
|
||||
{Value: "mqtt", Label: "Anker cloud (works anywhere)"},
|
||||
{Value: "modbus", Label: "Modbus TCP (local network)"},
|
||||
{Value: "own", Label: "Own CSMS (full control)"},
|
||||
{Value: "proxy", Label: "Proxy CSMS (relay + control)"},
|
||||
}},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,31 @@ func TestDescriptor(t *testing.T) {
|
||||
t.Errorf("controlMode is missing option %q", v)
|
||||
}
|
||||
}
|
||||
|
||||
// controlModesDisabled is the superadmin's hide-list: which of the modes the
|
||||
// organizations and users below are offered at all. off is not among them —
|
||||
// monitoring only is the fallback, so no layer may take it away.
|
||||
hide, ok := fields["controlModesDisabled"]
|
||||
if !ok {
|
||||
t.Fatal("controlModesDisabled config field should be present")
|
||||
}
|
||||
if hide.Type != "multiselect" {
|
||||
t.Errorf("controlModesDisabled type = %q, want multiselect", hide.Type)
|
||||
}
|
||||
hideable := map[string]bool{"mqtt": false, "modbus": false, "own": false, "proxy": false}
|
||||
for _, o := range hide.Options {
|
||||
if o.Value == "off" {
|
||||
t.Error("off must not be hideable — it is what a charger falls back to")
|
||||
}
|
||||
if _, known := hideable[o.Value]; known {
|
||||
hideable[o.Value] = true
|
||||
}
|
||||
}
|
||||
for v, seen := range hideable {
|
||||
if !seen {
|
||||
t.Errorf("controlModesDisabled is missing option %q", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistered(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user