Settings: All connections, Posting accounts and Activity open on the local edition

Their admin check wanted someone signed in, so the local owner got a 404.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 15:29:37 -07:00
co-authored by Claude Opus 5.5
parent 1bad4deed6
commit df4759afb5
5 changed files with 28 additions and 4 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ type activityData struct {
const activityPage = 100 const activityPage = 100
func (s *Server) activityPage(w http.ResponseWriter, r *http.Request) { func (s *Server) activityPage(w http.ResponseWriter, r *http.Request) {
if s.admin(w, r) == nil { if !s.adminPage(w, r) {
return return
} }
q := r.URL.Query() q := r.URL.Query()
+1 -1
View File
@@ -185,7 +185,7 @@ type connRow struct {
} }
func (s *Server) connectionsPage(w http.ResponseWriter, r *http.Request) { func (s *Server) connectionsPage(w http.ResponseWriter, r *http.Request) {
if s.admin(w, r) == nil { if !s.adminPage(w, r) {
return return
} }
changes := map[string]connChange{} changes := map[string]connChange{}
+14
View File
@@ -65,3 +65,17 @@ func TestServiceOf(t *testing.T) {
} }
} }
} }
// The local edition has no one signed in: its owner still opens the admin
// pages that don't need an account.
func TestAdminPagesLocal(t *testing.T) {
_, h := newTestServer(t, nil)
for _, p := range []string{"/settings/connections", "/settings/posting", "/settings/activity"} {
if rec := do(h, http.MethodGet, p, nil, nil); rec.Code != http.StatusOK {
t.Errorf("%s: %d, want 200", p, rec.Code)
}
}
if rec := postForm(h, "/settings/posting", url.Values{}); rec.Code != http.StatusSeeOther {
t.Errorf("saving posting accounts: %d, want 303", rec.Code)
}
}
+2 -2
View File
@@ -294,7 +294,7 @@ type postingGrid struct {
} }
func (s *Server) postingPage(w http.ResponseWriter, r *http.Request) { func (s *Server) postingPage(w http.ResponseWriter, r *http.Request) {
if s.admin(w, r) == nil { if !s.adminPage(w, r) {
return return
} }
g := postingGrid{Accounts: s.postingAccounts(), Working: map[int64]bool{}, Owners: map[int64]string{}} g := postingGrid{Accounts: s.postingAccounts(), Working: map[int64]bool{}, Owners: map[int64]string{}}
@@ -321,7 +321,7 @@ func (s *Server) postingPage(w http.ResponseWriter, r *http.Request) {
} }
func (s *Server) postingSave(w http.ResponseWriter, r *http.Request) { func (s *Server) postingSave(w http.ResponseWriter, r *http.Request) {
if s.admin(w, r) == nil { if !s.adminPage(w, r) {
return return
} }
if err := r.ParseForm(); err != nil { if err := r.ParseForm(); err != nil {
+10
View File
@@ -91,6 +91,16 @@ func (s *Server) admin(w http.ResponseWriter, r *http.Request) *viewer {
return v return v
} }
// adminPage says whether the viewer may use an admin page that needs no one
// signed in, as the local edition's owner may; or answers 403.
func (s *Server) adminPage(w http.ResponseWriter, r *http.Request) bool {
if !viewerOf(r).Member.Admin() {
s.forbidden(w, r)
return false
}
return true
}
// forbidden is the answer to a request outside someone's access. // forbidden is the answer to a request outside someone's access.
func (s *Server) forbidden(w http.ResponseWriter, r *http.Request) { func (s *Server) forbidden(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("HX-Request") != "" || !safeMethod(r.Method) { if r.Header.Get("HX-Request") != "" || !safeMethod(r.Method) {