diff --git a/internal/web/nav.go b/internal/web/nav.go index b9982ce..b5ac48c 100644 --- a/internal/web/nav.go +++ b/internal/web/nav.go @@ -40,12 +40,17 @@ func (p *AccountPages) navFor(r *http.Request, user store.User, current string) Quotas: p.hasQuotas, CSRF: csrfFor(r), } + // Only when there is an organization to show: a link that leads to "there + // are none" on every page is noise. if p.orgs != nil { + var orgs []store.Org + var err error if user.IsAdmin { - n.Org = true - } else if orgs, err := p.orgs.ManagedOrgs(r.Context(), user.ID); err == nil && len(orgs) > 0 { - n.Org = true + orgs, err = p.orgs.AllOrgs(r.Context()) + } else { + orgs, err = p.orgs.ManagedOrgs(r.Context(), user.ID) } + n.Org = err == nil && len(orgs) > 0 } return n } diff --git a/internal/web/org_page.go b/internal/web/org_page.go index 420fc4b..08e9a49 100644 --- a/internal/web/org_page.go +++ b/internal/web/org_page.go @@ -71,6 +71,16 @@ func (p *AccountPages) RegisterOrgPages(mux *http.ServeMux, s OrgViewer, priced p.orgs = s mux.HandleFunc("GET /org", p.orgGuard(func(w http.ResponseWriter, r *http.Request, user store.User) { 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 + // cluster with no organizations should learn that, and where to + // make one. + render(w, "org-none", struct { + Nav Nav + Version, Now string + }{navFrom(r, "org"), p.version, time.Now().UTC().Format(time.RFC3339)}) + return + } if err != nil || len(orgs) == 0 { http.NotFound(w, r) return diff --git a/internal/web/org_page_test.go b/internal/web/org_page_test.go index 1e419cb..721b4aa 100644 --- a/internal/web/org_page_test.go +++ b/internal/web/org_page_test.go @@ -104,3 +104,23 @@ func TestAnAdministratorSeesEveryOrganization(t *testing.T) { t.Errorf("an administrator could not see Scania: %d", w.Code) } } + +type noOrgs struct{ fakeOrgs } + +func (noOrgs) AllOrgs(context.Context) ([]store.Org, error) { return nil, nil } +func (noOrgs) ManagedOrgs(context.Context, string) ([]store.Org, error) { return nil, nil } + +func TestWithNoOrganizationsAnAdministratorIsToldSo(t *testing.T) { + p := NewAccountPages(fakeAccounts{user: store.User{ID: "a", IsAdmin: true}}, nil, nil, "v0", + slog.New(slog.NewTextHandler(io.Discard, nil))) + mux := http.NewServeMux() + p.RegisterOrgPages(mux, noOrgs{}, nil) + w := mirrorGet(t, mux, "/org") + if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "There are none") { + t.Errorf("an empty cluster answered %d: %s", w.Code, w.Body.String()) + } + // And the menu does not offer a page of nothing. + if strings.Contains(w.Body.String(), `href="/org"`) { + t.Error("the menu links to organizations when there are none") + } +} diff --git a/internal/web/templates/org.html b/internal/web/templates/org.html index 3bd39aa..cfaf5f4 100644 --- a/internal/web/templates/org.html +++ b/internal/web/templates/org.html @@ -91,3 +91,22 @@ people do elsewhere — in another organization, or on their own — is not show {{end}} + + +{{define "org-none"}} + + +Organizations · llmgw +
+
+

Organizations

+

There are none on this cluster

+ {{template "nav" .Nav}} +
+

Everyone uses the gateway on their own, under their personal quota. An +organization, once there is one, gets a page here for its managers: its use by +team, project and person, its limits, and its members.

+

Create one on the people page, then make someone +its manager with the star on their membership.

+ +
{{end}}