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:
@@ -11,7 +11,7 @@ import (
|
||||
linkedinapi "supermarket/internal/api/linkedin"
|
||||
"supermarket/internal/content"
|
||||
"supermarket/internal/oauth"
|
||||
"supermarket/internal/secrets"
|
||||
"supermarket/internal/posting"
|
||||
)
|
||||
|
||||
// Posting as the company page needs a second LinkedIn app with the
|
||||
@@ -56,7 +56,7 @@ func (s *Server) liPage() *linkedinapi.Org {
|
||||
}
|
||||
|
||||
func (s *Server) pageSetup() *pageSetup {
|
||||
p := &pageSetup{Scopes: s.liPageScopes(), Signed: s.Secrets.Has(secrets.LinkedInPageAccessToken), Chosen: s.liPage()}
|
||||
p := &pageSetup{Scopes: s.liPageScopes(), Signed: s.companyPage() != nil, Chosen: s.liPage()}
|
||||
s.DB.GetJSON(liPageOrgsKey, &p.Orgs)
|
||||
s.DB.GetJSON(liPageNoteKey, &p.Note)
|
||||
s.DB.GetJSON(content.LinkedInDefaultKey, &p.Default)
|
||||
@@ -64,19 +64,13 @@ func (s *Server) pageSetup() *pageSetup {
|
||||
}
|
||||
|
||||
// linkedInPageExpiry is when the page's sign-in runs out, or nil.
|
||||
func (s *Server) linkedInPageExpiry() *Expiry {
|
||||
if !s.Secrets.Has(secrets.LinkedInPageAccessToken) {
|
||||
return nil
|
||||
}
|
||||
c := s.connections()[liPageProvider]
|
||||
at := c.Expires
|
||||
if at.IsZero() {
|
||||
if c.At.IsZero() {
|
||||
return nil
|
||||
}
|
||||
at = c.At.Add(linkedInTokenLife)
|
||||
}
|
||||
return &Expiry{Network: liPageNetwork, At: at}
|
||||
func (s *Server) linkedInPageExpiry() *Expiry { return s.companyExpiry(posting.LinkedInPage) }
|
||||
|
||||
// companyPage is the company's LinkedIn page account, or nil.
|
||||
func (s *Server) companyPage() *posting.Account {
|
||||
s.adoptLegacy()
|
||||
a, _ := posting.Company(s.DB, posting.LinkedInPage)
|
||||
return a
|
||||
}
|
||||
|
||||
// pageOrgs lists the pages the page sign-in may post for, and keeps them.
|
||||
@@ -120,7 +114,10 @@ func (s *Server) linkedInPageSave(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
switch r.PostFormValue("do") {
|
||||
case "refresh":
|
||||
tok := s.Secrets.Get(secrets.LinkedInPageAccessToken)
|
||||
tok := ""
|
||||
if a := s.companyPage(); a != nil {
|
||||
tok = s.Secrets.Get(posting.AccessName(a.ID))
|
||||
}
|
||||
if tok == "" {
|
||||
redirect(w, r, "/settings/accounts", "")
|
||||
return
|
||||
@@ -171,6 +168,12 @@ func (s *Server) linkedInPageSave(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if a, o := s.companyPage(), s.liPage(); a != nil && o != nil && a.External != o.URN {
|
||||
if err := posting.Rename(s.DB, a.ID, o.Name, o.URN); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
redirect(w, r, "/settings/accounts", "saved")
|
||||
}
|
||||
|
||||
@@ -190,7 +193,7 @@ var errNoMe = errors.New("this draft posts as you, but LinkedIn isn't connected:
|
||||
// liPageIfSignedIn is the chosen page when the page app is signed in, for
|
||||
// the "post as" choice on LinkedIn drafts.
|
||||
func (s *Server) liPageIfSignedIn() *linkedinapi.Org {
|
||||
if !s.Secrets.Has(secrets.LinkedInPageAccessToken) {
|
||||
if s.companyPage() == nil {
|
||||
return nil
|
||||
}
|
||||
return s.liPage()
|
||||
|
||||
Reference in New Issue
Block a user