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:
@@ -22,10 +22,10 @@ type service struct {
|
||||
|
||||
var services = []service{
|
||||
{"ai", "AI provider", "Writing: posts, pages, briefs, the profile draft", "/settings/ai", []string{secrets.AnthropicAPIKey, secrets.OpenAIAPIKey}},
|
||||
{"x", "X", "Posting, and reading partners' posts", "/settings/accounts#network-X", []string{secrets.XAccessToken, secrets.XBearerToken}},
|
||||
{"linkedin", "LinkedIn", "Posting as a person", "/settings/accounts#network-LinkedIn", []string{secrets.LinkedInAccessToken}},
|
||||
{"linkedin_page", "LinkedIn page", "Posting as the company's page", "/settings/accounts", []string{secrets.LinkedInPageAccessToken}},
|
||||
{"reddit", "Reddit", "Posting to subreddits", "/settings/accounts#network-Reddit", []string{secrets.RedditAccessToken}},
|
||||
{"x", "X", "Posting, and reading partners' posts", "/settings/accounts#network-X", []string{secrets.XBearerToken}},
|
||||
{"linkedin", "LinkedIn", "Posting as a person", "/settings/accounts#network-LinkedIn", nil},
|
||||
{"linkedin_page", "LinkedIn page", "Posting as the company's page", "/settings/accounts", nil},
|
||||
{"reddit", "Reddit", "Posting to subreddits", "/settings/accounts#network-Reddit", nil},
|
||||
{"youtube", "YouTube", "Reading partners' videos", "/settings/accounts", []string{secrets.YouTubeAPIKey}},
|
||||
{"google", "Google Search Console", "SEO: what ranks, the morning check", "/settings/search", []string{secrets.GoogleRefreshToken}},
|
||||
{"bing", "Bing Webmaster", "SEO: links to the sites", "/settings/search", []string{secrets.BingAPIKey}},
|
||||
@@ -111,6 +111,25 @@ func (s *Server) setSecrets(r *http.Request, updates map[string]string) error {
|
||||
return s.DB.PutJSON(connChangesKey, changes)
|
||||
}
|
||||
|
||||
// recordConnection records who connected (or removed) a service, for
|
||||
// sign-ins kept outside the secrets' names (posting accounts).
|
||||
func (s *Server) recordConnection(r *http.Request, service string, set bool) {
|
||||
changes := map[string]connChange{}
|
||||
_, _ = s.DB.GetJSON(connChangesKey, &changes)
|
||||
v := viewerOf(r)
|
||||
who, id := "you", int64(0)
|
||||
if v.User != nil {
|
||||
who, id = v.User.Name, v.User.ID
|
||||
if who == "" {
|
||||
who = v.User.Email
|
||||
}
|
||||
}
|
||||
changes[service] = connChange{By: who, UserID: id, At: time.Now().UTC(), Removed: !set}
|
||||
if err := s.DB.PutJSON(connChangesKey, changes); err != nil {
|
||||
s.Log.Warn("connections: recording a change", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// serviceSet says whether any of a service's secrets is set.
|
||||
func (s *Server) serviceSet(id string) bool {
|
||||
for _, sv := range services {
|
||||
@@ -162,12 +181,34 @@ func (s *Server) connectionsPage(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = s.DB.GetJSON(connChangesKey, &changes)
|
||||
_, _ = s.DB.GetJSON(connChecksKey, &checks)
|
||||
signins := s.connections()
|
||||
// The posting networks count their accounts.
|
||||
postingCount := map[string]int{"x": 0, "linkedin": 0, "linkedin_page": 0, "reddit": 0}
|
||||
postingNames := map[string]string{}
|
||||
for _, a := range s.postingAccounts() {
|
||||
if s.working(a) {
|
||||
postingCount[a.Network]++
|
||||
if postingNames[a.Network] != "" {
|
||||
postingNames[a.Network] += ", "
|
||||
}
|
||||
postingNames[a.Network] += a.Name
|
||||
}
|
||||
}
|
||||
var rows []connRow
|
||||
for _, sv := range services {
|
||||
row := connRow{service: sv, State: "missing"}
|
||||
if s.serviceSet(sv.ID) {
|
||||
row.State = "connected"
|
||||
}
|
||||
if n, ok := postingCount[sv.ID]; ok {
|
||||
reading := row.State == "connected" // X's key for reading posts
|
||||
row.State, row.Detail = "missing", ""
|
||||
switch {
|
||||
case n > 0:
|
||||
row.State, row.Detail = "connected", postingNames[sv.ID]
|
||||
case reading:
|
||||
row.State, row.Detail = "connected", "Reading only: no account to post to"
|
||||
}
|
||||
}
|
||||
if sv.ID == "ai" {
|
||||
row.State = "missing"
|
||||
if cfg, err := ai.LoadConfig(s.DB); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user