Send an administrator from /org to the people page's panel

An organization's members, limits and use are a panel of the people page,
where they can also be changed, so the administrator's menu loses its
Organizations entry and /org redirects there. Managers keep /org.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-03 19:15:25 +02:00
1 parent fffed716be
commit febcf251e4
5 files changed
+50 -4

No files matched your search

+23
View File
@@ -3,6 +3,7 @@ package web
import (
"context"
"net/http"
"net/url"
"sort"
"time"
@@ -70,6 +71,9 @@ type orgPageData struct {
func (p *AccountPages) RegisterOrgPages(mux *http.ServeMux, s OrgViewer, priced Priced) {
p.orgs = s
mux.HandleFunc("GET /org", p.orgGuard(func(w http.ResponseWriter, r *http.Request, user store.User) {
if p.toPeople(w, r, user, "") {
return
}
orgs, err := p.viewableOrgs(r.Context(), s, user)
if err == nil && len(orgs) == 0 && user.IsAdmin {
// Said, not a 404: an administrator following the link on a
@@ -89,6 +93,9 @@ func (p *AccountPages) RegisterOrgPages(mux *http.ServeMux, s OrgViewer, priced
}))
mux.HandleFunc("GET /org/{id}", p.orgGuard(func(w http.ResponseWriter, r *http.Request, user store.User) {
id := r.PathValue("id")
if p.toPeople(w, r, user, id) {
return
}
if !user.IsAdmin {
ok, err := s.ManagesOrg(r.Context(), user.ID, id)
if err != nil || !ok {
@@ -102,6 +109,22 @@ func (p *AccountPages) RegisterOrgPages(mux *http.ServeMux, s OrgViewer, priced
}))
}
// toPeople sends an administrator to the people page, which shows an
// organization's members, limits and use beside the whole tree and can change
// them; this page stays for the managers who may not see that one. It says
// whether it did.
func (p *AccountPages) toPeople(w http.ResponseWriter, r *http.Request, user store.User, orgID string) bool {
if !user.IsAdmin || p.peopleStore == nil {
return false
}
to := "/admin/users"
if orgID != "" {
to += "?sel=org:" + url.QueryEscape(orgID)
}
http.Redirect(w, r, to, http.StatusSeeOther)
return true
}
// viewableOrgs is every organization an administrator may look at, or the
// ones a person manages.
func (p *AccountPages) viewableOrgs(ctx context.Context, s OrgViewer, user store.User) ([]store.Org, error) {
+19
View File
@@ -124,3 +124,22 @@ func TestWithNoOrganizationsAnAdministratorIsToldSo(t *testing.T) {
t.Error("the menu links to organizations when there are none")
}
}
func TestAnAdministratorIsSentToThePeoplePageForAnOrganization(t *testing.T) {
// Its members, limits and use are a panel there, beside the whole tree
// and changeable; /org stays for the managers who cannot see that page.
p := NewAccountPages(fakeAccounts{user: store.User{ID: "a", IsAdmin: true}}, nil, nil, "v0",
slog.New(slog.NewTextHandler(io.Discard, nil)))
mux := http.NewServeMux()
p.RegisterAdminUsers(mux, &fakeAdmin{})
p.RegisterOrgPages(mux, fakeOrgs{}, nil)
for path, to := range map[string]string{"/org": "/admin/users", "/org/org-s": "/admin/users?sel=org:org-s"} {
w := mirrorGet(t, mux, path)
if w.Code != http.StatusSeeOther || w.Header().Get("Location") != to {
t.Errorf("%s: %d to %q, want %s", path, w.Code, w.Header().Get("Location"), to)
}
}
if menu := menuRe.FindString(mirrorGet(t, mux, "/admin/users").Body.String()); strings.Contains(menu, `href="/org"`) {
t.Error("the administrator's menu still offers /org beside People")
}
}
+2 -3
View File
@@ -13,9 +13,8 @@
{{- if .Mirror}}
<a href="/admin/mirror"{{if eq .Current "mirror"}} aria-current="page"{{end}}>Mirror</a>
{{- end}}
{{- if .Org}}
<a href="/org"{{if eq .Current "org"}} aria-current="page"{{end}}>Organizations</a>
{{- end}}
{{- /* An organization is a panel of the people page for an administrator;
/org is the managers' view, and leads an administrator there. */}}
<span class="menu-gap" aria-hidden="true"></span>
{{- end}}
<a href="/chat"{{if eq .Current "chat"}} aria-current="page"{{end}}>Chat</a>