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:
@@ -136,7 +136,7 @@ type activityData struct {
|
||||
const activityPage = 100
|
||||
|
||||
func (s *Server) activityPage(w http.ResponseWriter, r *http.Request) {
|
||||
if s.admin(w, r) == nil {
|
||||
if !s.adminPage(w, r) {
|
||||
return
|
||||
}
|
||||
q := r.URL.Query()
|
||||
|
||||
@@ -185,7 +185,7 @@ type connRow struct {
|
||||
}
|
||||
|
||||
func (s *Server) connectionsPage(w http.ResponseWriter, r *http.Request) {
|
||||
if s.admin(w, r) == nil {
|
||||
if !s.adminPage(w, r) {
|
||||
return
|
||||
}
|
||||
changes := map[string]connChange{}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ type postingGrid struct {
|
||||
}
|
||||
|
||||
func (s *Server) postingPage(w http.ResponseWriter, r *http.Request) {
|
||||
if s.admin(w, r) == nil {
|
||||
if !s.adminPage(w, r) {
|
||||
return
|
||||
}
|
||||
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) {
|
||||
if s.admin(w, r) == nil {
|
||||
if !s.adminPage(w, r) {
|
||||
return
|
||||
}
|
||||
if err := r.ParseForm(); err != nil {
|
||||
|
||||
@@ -91,6 +91,16 @@ func (s *Server) admin(w http.ResponseWriter, r *http.Request) *viewer {
|
||||
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.
|
||||
func (s *Server) forbidden(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("HX-Request") != "" || !safeMethod(r.Method) {
|
||||
|
||||
Reference in New Issue
Block a user