Add Configuration Actions tab for shell and script action definitions.

Admins can manage built-in and custom actions with placeholders, ENV vars, and actions.create/update/delete permissions.
This commit is contained in:
2026-07-18 19:18:13 +02:00
parent 77be394407
commit c90a47c3ea
17 changed files with 1770 additions and 9 deletions
+68
View File
@@ -0,0 +1,68 @@
package settings
import (
"os"
"path/filepath"
"testing"
)
func TestLoadActionsOrSeedCreatesBuiltins(t *testing.T) {
dir := t.TempDir()
store, err := LoadActionsOrSeed(dir)
if err != nil {
t.Fatalf("LoadActionsOrSeed: %v", err)
}
if len(store.Actions) != 3 {
t.Fatalf("expected 3 builtins, got %d", len(store.Actions))
}
for _, action := range store.Actions {
if !action.Builtin {
t.Fatalf("expected builtin action, got %#v", action)
}
}
path := filepath.Join(dir, ActionsFileName)
if _, err := os.Stat(path); err != nil {
t.Fatalf("expected actions.json to exist: %v", err)
}
reloaded, err := LoadActions(dir)
if err != nil {
t.Fatalf("LoadActions: %v", err)
}
if len(reloaded.Actions) != 3 {
t.Fatalf("reloaded len = %d", len(reloaded.Actions))
}
}
func TestActionsRoundTrip(t *testing.T) {
dir := t.TempDir()
store := ActionStore{
Actions: append(DefaultBuiltinActions(), Action{
ID: "aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee",
Name: "Custom",
Description: "A custom shell action",
Kind: ActionKindShell,
Body: "echo hello",
Env: []ActionEnvVar{
{Name: "APP_HOME", Value: "/opt/app"},
},
Builtin: false,
}),
}
if err := SaveActions(dir, store); err != nil {
t.Fatalf("SaveActions: %v", err)
}
loaded, err := LoadActions(dir)
if err != nil {
t.Fatalf("LoadActions: %v", err)
}
if len(loaded.Actions) != 4 {
t.Fatalf("loaded len = %d", len(loaded.Actions))
}
custom := loaded.Actions[3]
if custom.Name != "Custom" || len(custom.Env) != 1 || custom.Env[0].Name != "APP_HOME" {
t.Fatalf("custom = %#v", custom)
}
}