Skip to content
17 changes: 17 additions & 0 deletions cmd/picoclaw/tui/configedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,20 @@ func removeAllowFrom(exec Executor, channel string, idx int) error {
ch["allow_from"] = existing
return writeConfigMap(exec, cfg)
}

// replaceAllowFrom replaces an entry by index in a channel's allow_from.
func replaceAllowFrom(exec Executor, channel string, idx int, entry string) error {
cfg, err := readConfigMap(exec)
if err != nil {
return err
}
channels := ensureMap(cfg, "channels")
ch := ensureMap(channels, channel)
existing := getStringSlice(ch, "allow_from")
if idx < 0 || idx >= len(existing) {
return nil
}
existing[idx] = strings.TrimSpace(entry)
ch["allow_from"] = existing
return writeConfigMap(exec, cfg)
}
10 changes: 10 additions & 0 deletions cmd/picoclaw/tui/tab_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,13 @@ func removeUserFromConfig(exec Executor, channel string, idx int) tea.Cmd {
return actionDoneMsg{output: "User removed."}
}
}

// updateUserInConfig replaces an existing allow_from entry by index.
func updateUserInConfig(exec Executor, channel string, idx int, entry string) tea.Cmd {
return func() tea.Msg {
if err := replaceAllowFrom(exec, channel, idx, entry); err != nil {
return actionDoneMsg{output: fmt.Sprintf("Failed to update user: %v", err)}
}
return actionDoneMsg{output: "User updated."}
}
}
Loading