Phase 10, part 7: posting accounts, and who may post to which

Social accounts become posting accounts: several per network, the
company's and each person's own, with their tokens kept per account. The
old sign-ins are adopted as the company's. Admins say who may post to which
(Settings → Posting accounts); a draft can go out from one account or a
copy to several, each recording who posted it and as what. Signing an
account out, or removing its owner, holds the posts scheduled to it and
tells whoever scheduled them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 09:26:34 -07:00
co-authored by Claude Opus 5.5
parent a4dd36f5a4
commit bb4772637c
31 changed files with 1758 additions and 325 deletions
+25 -30
View File
@@ -18,8 +18,8 @@ import (
"supermarket/internal/core"
"supermarket/internal/crm"
"supermarket/internal/inventory"
"supermarket/internal/posting"
"supermarket/internal/profile"
"supermarket/internal/secrets"
)
// Connection is a social account the user signed in to.
@@ -55,28 +55,29 @@ func (e Expiry) Days() int { return int(time.Until(e.At) / (24 * time.Hour)) }
// linkedInExpiry is when the LinkedIn sign-in runs out, or nil if LinkedIn
// isn't connected.
func (s *Server) linkedInExpiry() *Expiry {
if !s.Secrets.Has(secrets.LinkedInAccessToken) {
func (s *Server) linkedInExpiry() *Expiry { return s.companyExpiry(posting.LinkedIn) }
// companyExpiry is when the company's account on a network runs out, or
// nil if it's renewed by itself (or there's none).
func (s *Server) companyExpiry(network string) *Expiry {
s.adoptLegacy()
a, err := posting.Company(s.DB, network)
if err != nil || a == nil || a.Expires.IsZero() {
return nil
}
c := s.connections()["linkedin"]
at := c.Expires
if at.IsZero() {
if c.At.IsZero() {
return nil // a token from the old app: when it was made is unknown
}
at = c.At.Add(linkedInTokenLife)
}
return &Expiry{Network: "LinkedIn", At: at}
return &Expiry{Network: a.Label(), At: a.Expires}
}
// reminders are the sign-ins running out soon, or already, for the
// Overview and Posts.
// Overview and Posts: every account's.
func (s *Server) reminders() []Expiry {
var out []Expiry
for _, e := range []*Expiry{s.linkedInExpiry(), s.linkedInPageExpiry()} {
if e != nil && e.Soon() {
out = append(out, *e)
for _, a := range s.postingAccounts() {
if a.Expires.IsZero() {
continue
}
if e := (Expiry{Network: a.Label(), At: a.Expires}); e.Soon() {
out = append(out, e)
}
}
return out
@@ -140,7 +141,7 @@ func (s *Server) dashboard(w http.ResponseWriter, r *http.Request) {
Detail: ifElse(p.IsSet(), p.Name, "Describe the company, its products and its customers (the AI can draft it from your website)")},
{Label: "Market", Done: len(entries) > 0, Link: "/market",
Detail: inventorySummary(counts)},
{Label: "Social accounts", Done: s.Secrets.Has(secrets.XAccessToken) || s.Secrets.Has(secrets.LinkedInAccessToken) || s.Secrets.Has(secrets.RedditAccessToken),
{Label: "Social accounts", Done: len(s.postingAccounts()) > 0,
Link: "/settings/accounts", Detail: s.connectionSummary(conns)},
{Label: "Federated Core", Done: s.Core != nil, Link: "/settings/core",
Detail: ifElse(s.Core != nil, coreDomain(s.Core), "No Core found; run `configure core` in CoreDesktop")},
@@ -209,20 +210,14 @@ func inventorySummary(c map[string]int) string {
return plural(c[inventory.Partner], "partner") + ", " + plural(c[inventory.Competitor], "competitor") + ", " + plural(c[inventory.Watch], "watched")
}
func (s *Server) connectionSummary(c map[string]Connection) string {
func (s *Server) connectionSummary(map[string]Connection) string {
var parts []string
if a := c["x"].Account; a != "" {
parts = append(parts, "X @"+a)
} else if s.Secrets.Has(secrets.XAccessToken) {
parts = append(parts, "X")
}
if e := s.linkedInExpiry(); e != nil && e.Expired() {
parts = append(parts, "LinkedIn (expired)")
} else if s.Secrets.Has(secrets.LinkedInAccessToken) {
parts = append(parts, "LinkedIn")
}
if a := c["reddit"].Account; a != "" {
parts = append(parts, "Reddit u/"+a)
for _, a := range s.postingAccounts() {
label := a.Label()
if a.Expired(time.Now()) {
label += " (expired)"
}
parts = append(parts, label)
}
if len(parts) == 0 {
return "Connect X, LinkedIn or Reddit"