Give an organization's managers a page of their own
A member of an organization can be its manager (users join --org X --role manager, or the star on the people page). /org shows a manager their organization: usage over time by team, project or person, its teams and projects with limits and 30-day spend, and its members, each once with every place they belong. Read-only; administrators see every organization. Only what was spent in the organization's projects is shown — UsageBucketsIn filters by where a request was spent. Found on the way: - Usage by org, team and project, and the quotas page's spend, joined through api_keys and so dropped every chat-page request, which has no key row. They now read usage.project_id; keys no longer move between projects, so the two agree. - /org was not exempt from API-key auth and answered browsers with a JSON error. A router test now drives the session pages through the middleware; it fails without the fix. Membership queries, org-scoped usage and the reworked joins pass the PostgreSQL store tests on 16. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
098886e0e4
commit
e493b2f53d
21 files changed
+716
-48
No files matched your search
@@ -65,6 +65,8 @@ type AccountPages struct {
|
||||
personalOff bool
|
||||
// personalDefaults is what personal use falls under by default.
|
||||
personalDefaults *store.Limits
|
||||
// orgs is set when /org is mounted, so the menu can offer it to managers.
|
||||
orgs OrgViewer
|
||||
// priced says whether a budget can ever be spent against.
|
||||
priced Priced
|
||||
// registry browses a model registry, or is nil where there is no way out.
|
||||
|
||||
@@ -35,6 +35,11 @@ type QuotaAdmin interface {
|
||||
UsageByUser(ctx context.Context, since time.Time) ([]store.UserUsage, error)
|
||||
}
|
||||
|
||||
// scopeUsage is what spend per branch is read from.
|
||||
type scopeUsage interface {
|
||||
UsageByScope(ctx context.Context, scope store.Scope, since time.Time) ([]store.ScopeUsage, error)
|
||||
}
|
||||
|
||||
// personRow is one person's own limits: across all their keys and projects.
|
||||
type personRow struct {
|
||||
ID, Email string
|
||||
@@ -288,7 +293,7 @@ func (p *AccountPages) renderQuotas(w http.ResponseWriter, r *http.Request,
|
||||
}
|
||||
|
||||
// spendByScope is what each group has used in the window, keyed like a limit.
|
||||
func (p *AccountPages) spendByScope(ctx context.Context, s QuotaAdmin,
|
||||
func (p *AccountPages) spendByScope(ctx context.Context, s scopeUsage,
|
||||
since time.Time,
|
||||
) map[string]int64 {
|
||||
out := map[string]int64{}
|
||||
|
||||
+26
-21
@@ -134,27 +134,7 @@ func (p *AccountPages) renderUsage(w http.ResponseWriter, r *http.Request,
|
||||
return
|
||||
}
|
||||
|
||||
d.Requests = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Requests)
|
||||
}), "", 4)
|
||||
d.Tokens = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Prompt + b.Completion)
|
||||
}), "", 4)
|
||||
d.Spend = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
// Shown in whole units, as every other spend figure is: a budget is
|
||||
// written in units and a chart in micros would not compare with it.
|
||||
return float64(b.CostMicros) / 1e6
|
||||
}), "", 4)
|
||||
|
||||
for _, u := range rows {
|
||||
d.Rows = append(d.Rows, usageRow{
|
||||
Name: displayName(u),
|
||||
Requests: u.Requests,
|
||||
Tokens: u.Tokens(),
|
||||
Spend: unitsOf(u.CostMicros),
|
||||
Errors: u.Errors,
|
||||
})
|
||||
}
|
||||
d.Requests, d.Tokens, d.Spend, d.Rows = usageCharts(rows)
|
||||
render(w, "admin_usage", d)
|
||||
}
|
||||
|
||||
@@ -207,3 +187,28 @@ func groupLabel(g store.Grouping) string {
|
||||
return string(g)
|
||||
}
|
||||
}
|
||||
|
||||
// usageCharts draws usage over time three ways, with the table beneath them.
|
||||
func usageCharts(rows []store.UsageSeries) (req, tok, spend TimeSeries, table []usageRow) {
|
||||
req = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Requests)
|
||||
}), "", 4)
|
||||
tok = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
return float64(b.Prompt + b.Completion)
|
||||
}), "", 4)
|
||||
spend = LineChartTotals(seriesOf(rows, func(b store.Bucket) float64 {
|
||||
// Shown in whole units, as every other spend figure is: a budget is
|
||||
// written in units and a chart in micros would not compare with it.
|
||||
return float64(b.CostMicros) / 1e6
|
||||
}), "", 4)
|
||||
for _, u := range rows {
|
||||
table = append(table, usageRow{
|
||||
Name: displayName(u),
|
||||
Requests: u.Requests,
|
||||
Tokens: u.Tokens(),
|
||||
Spend: unitsOf(u.CostMicros),
|
||||
Errors: u.Errors,
|
||||
})
|
||||
}
|
||||
return req, tok, spend, table
|
||||
}
|
||||
@@ -170,6 +170,25 @@ func (p *AccountPages) RegisterAdminUsers(mux *http.ServeMux, s AccountAdmin) {
|
||||
return "added to " + scopeLabel(ctx, s, store.Scope(scope), scopeID), nil
|
||||
}))
|
||||
|
||||
// Managing is a role on an organization membership: it lets the person see
|
||||
// that organization's page, and nothing else changes.
|
||||
mux.HandleFunc("POST /admin/users/{id}/role", p.adminAction(s,
|
||||
func(ctx context.Context, admin store.User, id string, r *http.Request) (string, error) {
|
||||
scope, scopeID, ok := strings.Cut(r.FormValue("scope"), ":")
|
||||
role := r.FormValue("role")
|
||||
if !ok || store.Scope(scope) != store.ScopeOrg || (role != store.RoleManager && role != store.RoleMember) {
|
||||
return "", errors.New("a manager is a role in an organization")
|
||||
}
|
||||
if err := s.AddMembership(ctx, id, store.ScopeOrg, scopeID, role, admin.Email, time.Now()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
label := scopeLabel(ctx, s, store.ScopeOrg, scopeID)
|
||||
if role == store.RoleManager {
|
||||
return "now manages " + label, nil
|
||||
}
|
||||
return "no longer manages " + label, nil
|
||||
}))
|
||||
|
||||
mux.HandleFunc("POST /admin/users/{id}/leave", p.adminAction(s,
|
||||
func(ctx context.Context, _ store.User, id string, r *http.Request) (string, error) {
|
||||
scope, scopeID, ok := strings.Cut(r.FormValue("scope"), ":")
|
||||
|
||||
@@ -24,6 +24,9 @@ type Nav struct {
|
||||
Mirror, Quotas bool
|
||||
// CSRF signs the sign-out form.
|
||||
CSRF string
|
||||
// Org offers the organization page: to an administrator, and to anyone
|
||||
// who manages an organization.
|
||||
Org bool
|
||||
}
|
||||
|
||||
type navKey struct{}
|
||||
@@ -37,6 +40,13 @@ func (p *AccountPages) navFor(r *http.Request, user store.User, current string)
|
||||
Quotas: p.hasQuotas,
|
||||
CSRF: csrfFor(r),
|
||||
}
|
||||
if p.orgs != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
// OrgViewer is what an organization's page reads. Nothing on it writes.
|
||||
type OrgViewer interface {
|
||||
ManagesOrg(ctx context.Context, userID, orgID string) (bool, error)
|
||||
ManagedOrgs(ctx context.Context, userID string) ([]store.Org, error)
|
||||
AllOrgs(ctx context.Context) ([]store.Org, error)
|
||||
Tree(ctx context.Context) ([]store.TreeOrg, error)
|
||||
AllMemberships(ctx context.Context) ([]store.Membership, error)
|
||||
Users(ctx context.Context, state store.UserState) ([]store.User, error)
|
||||
AllLimits(ctx context.Context) (map[string]store.Limits, error)
|
||||
UsageBucketsIn(ctx context.Context, g store.Grouping, orgID string,
|
||||
since time.Time, width time.Duration) ([]store.UsageSeries, error)
|
||||
UsageByScope(ctx context.Context, scope store.Scope, since time.Time) ([]store.ScopeUsage, error)
|
||||
}
|
||||
|
||||
// orgMember is a person as an organization's page lists them: once, with
|
||||
// every place in the organization they are a member of.
|
||||
type orgMember struct {
|
||||
Email string
|
||||
State store.UserState
|
||||
Places []orgPlace
|
||||
}
|
||||
|
||||
type orgPlace struct{ Where, Role string }
|
||||
|
||||
type orgPageData struct {
|
||||
Nav Nav
|
||||
Org store.Org
|
||||
Orgs []store.Org // the others this person may look at
|
||||
|
||||
Groups []usageGroup
|
||||
Windows []struct {
|
||||
Key, Label string
|
||||
Selected bool
|
||||
}
|
||||
By, Window string
|
||||
|
||||
Requests TimeSeries
|
||||
Tokens TimeSeries
|
||||
Spend TimeSeries
|
||||
Rows []usageRow
|
||||
Priced bool
|
||||
|
||||
Quotas []quotaRow
|
||||
Members []orgMember
|
||||
People int
|
||||
|
||||
Error string
|
||||
Version string
|
||||
Now string
|
||||
}
|
||||
|
||||
// RegisterOrgPages mounts /org: an organization's own view of itself, for the
|
||||
// people who manage it.
|
||||
//
|
||||
// Read-only on purpose. A manager sees their organization's use, members and
|
||||
// limits — what they are accountable for — without being made an administrator
|
||||
// of the whole cluster, and without anything on the page that changes who may
|
||||
// do what. That stays with the cluster's administrators.
|
||||
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) {
|
||||
orgs, err := p.viewableOrgs(r.Context(), s, user)
|
||||
if err != nil || len(orgs) == 0 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, "/org/"+orgs[0].ID, http.StatusSeeOther)
|
||||
}))
|
||||
mux.HandleFunc("GET /org/{id}", p.orgGuard(func(w http.ResponseWriter, r *http.Request, user store.User) {
|
||||
id := r.PathValue("id")
|
||||
if !user.IsAdmin {
|
||||
ok, err := s.ManagesOrg(r.Context(), user.ID, id)
|
||||
if err != nil || !ok {
|
||||
// 404 rather than 403, like /admin: it does not confirm the
|
||||
// organization exists to someone who may not see it.
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
p.renderOrg(w, r, s, user, id, priced)
|
||||
}))
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if user.IsAdmin {
|
||||
return s.AllOrgs(ctx)
|
||||
}
|
||||
return s.ManagedOrgs(ctx, user.ID)
|
||||
}
|
||||
|
||||
func (p *AccountPages) orgGuard(next func(http.ResponseWriter, *http.Request, store.User)) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
noStore(w)
|
||||
_, user, ok := p.session(r)
|
||||
if !ok {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
next(w, p.withNav(r, user), user)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *AccountPages) renderOrg(w http.ResponseWriter, r *http.Request, s OrgViewer,
|
||||
user store.User, orgID string, priced Priced,
|
||||
) {
|
||||
ctx := r.Context()
|
||||
by := store.Grouping(r.URL.Query().Get("by"))
|
||||
if by != store.GroupByProject && by != store.GroupByUser {
|
||||
by = store.GroupByTeam
|
||||
}
|
||||
win := windowFor(r.URL.Query().Get("window"))
|
||||
d := orgPageData{
|
||||
Nav: navFrom(r, "org"),
|
||||
By: string(by), Window: win.Key,
|
||||
Priced: priced != nil && priced.AnythingPriced(),
|
||||
Version: p.version,
|
||||
Now: time.Now().UTC().Format(time.RFC3339),
|
||||
}
|
||||
for _, g := range []store.Grouping{store.GroupByTeam, store.GroupByProject, store.GroupByUser} {
|
||||
d.Groups = append(d.Groups, usageGroup{Key: string(g), Label: groupLabel(g), Selected: g == by})
|
||||
}
|
||||
for _, uw := range usageWindows {
|
||||
d.Windows = append(d.Windows, struct {
|
||||
Key, Label string
|
||||
Selected bool
|
||||
}{uw.Key, uw.Label, uw.Key == win.Key})
|
||||
}
|
||||
|
||||
d.Orgs, _ = p.viewableOrgs(ctx, s, user)
|
||||
tree, err := s.Tree(ctx)
|
||||
if err != nil {
|
||||
p.log.Error("could not read the tree", "err", err)
|
||||
d.Error = "could not read the organization"
|
||||
}
|
||||
var mine []store.TreeOrg
|
||||
inOrg := map[string]string{} // scope:id -> path within the org
|
||||
for _, o := range tree {
|
||||
if o.ID != orgID {
|
||||
continue
|
||||
}
|
||||
d.Org = store.Org{ID: o.ID, Name: o.Name}
|
||||
mine = []store.TreeOrg{o}
|
||||
inOrg["org:"+o.ID] = "the whole organization"
|
||||
for _, t := range o.Teams {
|
||||
inOrg["team:"+t.ID] = t.Name
|
||||
for _, pr := range t.Projects {
|
||||
inOrg["project:"+pr.ID] = t.Name + " / " + pr.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
if d.Org.ID == "" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
const quotaWindow = 30 * 24 * time.Hour
|
||||
if limits, err := s.AllLimits(ctx); err == nil {
|
||||
d.Quotas = quotaRows(mine, limits, p.spendByScope(ctx, s, time.Now().Add(-quotaWindow)))
|
||||
}
|
||||
|
||||
users, _ := s.Users(ctx, "")
|
||||
byID := map[string]store.User{}
|
||||
for _, u := range users {
|
||||
byID[u.ID] = u
|
||||
}
|
||||
ms, _ := s.AllMemberships(ctx)
|
||||
byPerson := map[string]*orgMember{}
|
||||
for _, m := range ms {
|
||||
where, ok := inOrg[string(m.Scope)+":"+m.ScopeID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
om := byPerson[m.UserID]
|
||||
if om == nil {
|
||||
u := byID[m.UserID]
|
||||
om = &orgMember{Email: u.Email, State: u.State}
|
||||
byPerson[m.UserID] = om
|
||||
}
|
||||
om.Places = append(om.Places, orgPlace{Where: where, Role: m.Role})
|
||||
}
|
||||
for _, om := range byPerson {
|
||||
d.Members = append(d.Members, *om)
|
||||
}
|
||||
sort.Slice(d.Members, func(i, j int) bool { return d.Members[i].Email < d.Members[j].Email })
|
||||
d.People = len(byPerson)
|
||||
|
||||
rows, err := s.UsageBucketsIn(ctx, by, orgID, time.Now().Add(-win.Span), win.Width)
|
||||
if err != nil {
|
||||
p.log.Error("could not read an organization's usage", "org", orgID, "err", err)
|
||||
d.Error = "could not read usage"
|
||||
}
|
||||
d.Requests, d.Tokens, d.Spend, d.Rows = usageCharts(rows)
|
||||
render(w, "org", d)
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
// fakeOrgs: Acme (managed by u1) and Scania.
|
||||
type fakeOrgs struct{ managers map[string]string } // org -> manager user id
|
||||
|
||||
func (f fakeOrgs) ManagesOrg(_ context.Context, user, org string) (bool, error) {
|
||||
return f.managers[org] == user, nil
|
||||
}
|
||||
func (f fakeOrgs) ManagedOrgs(_ context.Context, user string) ([]store.Org, error) {
|
||||
var out []store.Org
|
||||
for _, o := range []store.Org{{ID: "org-a", Name: "Acme"}, {ID: "org-s", Name: "Scania"}} {
|
||||
if f.managers[o.ID] == user {
|
||||
out = append(out, o)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (f fakeOrgs) AllOrgs(context.Context) ([]store.Org, error) {
|
||||
return []store.Org{{ID: "org-a", Name: "Acme"}, {ID: "org-s", Name: "Scania"}}, nil
|
||||
}
|
||||
func (f fakeOrgs) Tree(context.Context) ([]store.TreeOrg, error) {
|
||||
return []store.TreeOrg{
|
||||
{ID: "org-a", Name: "Acme", Teams: []store.TreeTeam{{ID: "t1", Name: "ml",
|
||||
Projects: []store.TreeProject{{ID: "p1", Name: "training"}}}}},
|
||||
{ID: "org-s", Name: "Scania"},
|
||||
}, nil
|
||||
}
|
||||
func (f fakeOrgs) AllMemberships(context.Context) ([]store.Membership, error) {
|
||||
return []store.Membership{
|
||||
{UserID: "u1", Scope: store.ScopeOrg, ScopeID: "org-a", Role: store.RoleManager},
|
||||
{UserID: "u2", Scope: store.ScopeProject, ScopeID: "p1", Role: store.RoleMember},
|
||||
{UserID: "u3", Scope: store.ScopeOrg, ScopeID: "org-s", Role: store.RoleMember},
|
||||
}, nil
|
||||
}
|
||||
func (f fakeOrgs) Users(context.Context, store.UserState) ([]store.User, error) {
|
||||
return []store.User{{ID: "u1", Email: "boss@acme"}, {ID: "u2", Email: "dev@acme"}, {ID: "u3", Email: "lars@scania"}}, nil
|
||||
}
|
||||
func (f fakeOrgs) AllLimits(context.Context) (map[string]store.Limits, error) {
|
||||
return map[string]store.Limits{}, nil
|
||||
}
|
||||
func (f fakeOrgs) UsageBucketsIn(context.Context, store.Grouping, string, time.Time, time.Duration) ([]store.UsageSeries, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (f fakeOrgs) UsageByScope(context.Context, store.Scope, time.Time) ([]store.ScopeUsage, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func orgPage(t *testing.T, user store.User) *http.ServeMux {
|
||||
t.Helper()
|
||||
p := NewAccountPages(fakeAccounts{user: user}, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
mux := http.NewServeMux()
|
||||
p.RegisterOrgPages(mux, fakeOrgs{managers: map[string]string{"org-a": "u1"}}, nil)
|
||||
return mux
|
||||
}
|
||||
|
||||
func TestAnOrganizationsManagerSeesItAndNothingElse(t *testing.T) {
|
||||
mux := orgPage(t, store.User{ID: "u1", Email: "boss@acme"})
|
||||
w := mirrorGet(t, mux, "/org/org-a")
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("the manager was refused their own organization: %d", w.Code)
|
||||
}
|
||||
body := w.Body.String()
|
||||
for _, want := range []string{"<h1>Acme</h1>", "dev@acme", "training", `href="/org"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("the page lacks %q", want)
|
||||
}
|
||||
}
|
||||
if strings.Contains(body, "lars@scania") {
|
||||
t.Error("another organization's member is on the page")
|
||||
}
|
||||
if w := mirrorGet(t, mux, "/org/org-s"); w.Code != http.StatusNotFound {
|
||||
t.Errorf("a manager of Acme could open Scania: %d", w.Code)
|
||||
}
|
||||
if w := mirrorGet(t, mux, "/org"); w.Code != http.StatusSeeOther || w.Header().Get("Location") != "/org/org-a" {
|
||||
t.Errorf("/org should lead to the organization they manage: %d %q", w.Code, w.Header().Get("Location"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSomebodyWhoManagesNothingGetsNoOrganizationPage(t *testing.T) {
|
||||
mux := orgPage(t, store.User{ID: "u2", Email: "dev@acme"})
|
||||
for _, path := range []string{"/org", "/org/org-a"} {
|
||||
if w := mirrorGet(t, mux, path); w.Code != http.StatusNotFound {
|
||||
t.Errorf("%s: %d, want 404", path, w.Code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnAdministratorSeesEveryOrganization(t *testing.T) {
|
||||
mux := orgPage(t, store.User{ID: "admin", Email: "a@x", IsAdmin: true})
|
||||
w := mirrorGet(t, mux, "/org/org-s")
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "lars@scania") {
|
||||
t.Errorf("an administrator could not see Scania: %d", w.Code)
|
||||
}
|
||||
}
|
||||
@@ -444,3 +444,4 @@ td.where { max-width: 26rem; }
|
||||
h3.limits-for { font-size: .92rem; margin: 1rem 0 .4rem; }
|
||||
table.narrow-table { max-width: 30rem; }
|
||||
.q-act a + a { margin-left: .8rem; }
|
||||
.chip-role { font-size: .68rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
|
||||
@@ -283,7 +283,16 @@ access than it had, so they need a shell on the control plane —
|
||||
<td>{{$u.Email}}{{if $u.IsAdmin}} <span class="tag">admin</span>{{end}}</td>
|
||||
<td class="state state-{{$u.State}}">{{$u.State}}</td>
|
||||
<td class="where">
|
||||
{{range $u.Memberships}}<span class="chip-m">{{.Path}}
|
||||
{{range $u.Memberships}}<span class="chip-m">{{.Path}}{{if eq .Role "manager"}} <b class="chip-role">manager</b>{{end}}
|
||||
{{if eq (printf "%s" .Scope) "org"}}
|
||||
<form method="post" action="/admin/users/{{$u.ID}}/role" class="inline">
|
||||
<input type="hidden" name="csrf" value="{{$d.CSRF}}">
|
||||
<input type="hidden" name="scope" value="org:{{.ScopeID}}">
|
||||
<input type="hidden" name="role" value="{{if eq .Role "manager"}}member{{else}}manager{{end}}">
|
||||
<button type="submit" class="chip-x" title="{{if eq .Role "manager"}}Stop managing {{.Path}}{{else}}Make manager of {{.Path}}: can see its page{{end}}"
|
||||
aria-label="{{if eq .Role "manager"}}Stop managing{{else}}Make manager{{end}}">{{if eq .Role "manager"}}☆{{else}}★{{end}}</button>
|
||||
</form>
|
||||
{{end}}
|
||||
<form method="post" action="/admin/users/{{$u.ID}}/leave" class="inline"
|
||||
hx-confirm="Take {{$u.Email}} out of {{.Path}}? Keys they made there are revoked.">
|
||||
<input type="hidden" name="csrf" value="{{$d.CSRF}}">
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
page you are on is marked, not offered, so moving between pages reads as
|
||||
moving within one program. */}}
|
||||
{{define "nav"}}<nav class="menu" aria-label="Main">
|
||||
{{- if and .Org (not .Admin)}}
|
||||
<a href="/org"{{if eq .Current "org"}} aria-current="page"{{end}}>Organization</a>
|
||||
<span class="menu-gap" aria-hidden="true"></span>
|
||||
{{- end}}
|
||||
{{- if .Admin}}
|
||||
<a href="/admin"{{if eq .Current "cluster"}} aria-current="page"{{end}}>Cluster</a>
|
||||
<a href="/admin/users"{{if eq .Current "people"}} aria-current="page"{{end}}>People</a>
|
||||
@@ -12,6 +16,9 @@
|
||||
{{- 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}}
|
||||
<span class="menu-gap" aria-hidden="true"></span>
|
||||
{{- end}}
|
||||
<a href="/chat"{{if eq .Current "chat"}} aria-current="page"{{end}}>Chat</a>
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
{{define "org"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{.Org.Name}} · llmgw</title><link rel="stylesheet" href="/_static/base.css">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>{{.Org.Name}}</h1>
|
||||
<p class="sub">{{.People}} {{if eq .People 1}}person{{else}}people{{end}} ·
|
||||
use, members and limits across the organization</p>
|
||||
{{template "nav" .Nav}}
|
||||
</header>
|
||||
|
||||
{{if gt (len .Orgs) 1}}
|
||||
<div class="filters">
|
||||
<span class="filter-label">Organization</span>
|
||||
{{range .Orgs}}<a class="chip{{if eq .ID $.Org.ID}} on{{end}}" href="/org/{{.ID}}">{{.Name}}</a>{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .Error}}<p class="error">{{.Error}}</p>{{end}}
|
||||
|
||||
<h2>Use</h2>
|
||||
<div class="filters">
|
||||
<span class="filter-label">Group by</span>
|
||||
{{range .Groups}}<a class="chip{{if .Selected}} on{{end}}"
|
||||
href="/org/{{$.Org.ID}}?by={{.Key}}&window={{$.Window}}">{{.Label}}</a>{{end}}
|
||||
<span class="filter-label">Window</span>
|
||||
{{range .Windows}}<a class="chip{{if .Selected}} on{{end}}"
|
||||
href="/org/{{$.Org.ID}}?by={{$.By}}&window={{.Key}}">{{.Label}}</a>{{end}}
|
||||
</div>
|
||||
|
||||
<div class="chart-row">
|
||||
{{template "tschart" dict "t" .Requests "title" "Requests"
|
||||
"note" "Requests made in this organization's projects."}}
|
||||
{{template "tschart" dict "t" .Tokens "title" "Tokens"
|
||||
"note" "Prompt and completion together."}}
|
||||
</div>
|
||||
{{if .Priced}}
|
||||
<div class="chart-row">
|
||||
{{template "tschart" dict "t" .Spend "title" "Spend" "note" "In whole units, the ones a budget is written in."}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .Rows}}
|
||||
<table class="compact">
|
||||
<tr><th>{{if eq .By "user"}}Person{{else if eq .By "project"}}Project{{else}}Team{{end}}</th>
|
||||
<th class="num">Requests</th><th class="num">Tokens</th><th class="num">Spend</th><th class="num">Errors</th></tr>
|
||||
{{range .Rows}}<tr>
|
||||
<td>{{.Name}}</td><td class="num">{{compact .Requests}}</td><td class="num">{{compact .Tokens}}</td>
|
||||
<td class="num">{{.Spend}}</td><td class="num">{{if .Errors}}{{.Errors}}{{else}}—{{end}}</td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
{{else}}<p class="empty">Nothing used in this window.</p>{{end}}
|
||||
<p class="note">Only what was spent in this organization's projects. What its
|
||||
people do elsewhere — in another organization, or on their own — is not shown.</p>
|
||||
|
||||
<h2>Teams, projects and limits</h2>
|
||||
{{if .Quotas}}
|
||||
<table class="quota-tree">
|
||||
<tr><th>Where</th><th class="num">Requests/min</th><th class="num">Tokens/min</th>
|
||||
<th class="num">Budget</th><th>Spent · 30 days</th></tr>
|
||||
{{range .Quotas}}
|
||||
<tr class="q-depth-{{.Indent}}">
|
||||
<td class="q-where"><span class="q-name">{{.Path}}</span> <span class="q-kind">{{.Scope}}</span>
|
||||
{{if .Models}}<div class="q-sub">only <code>{{.Models}}</code></div>{{end}}
|
||||
{{if .Shadowed}}<div class="q-sub q-warn">{{.Shadowed}}</div>{{end}}</td>
|
||||
<td class="num">{{template "quota-value" dict "Own" .RPM "Up" .RPMUp "From" .RPMFrom}}</td>
|
||||
<td class="num">{{template "quota-value" dict "Own" .TPM "Up" .TPMUp "From" .TPMFrom}}</td>
|
||||
<td class="num">{{if .Budget}}{{.Budget}}{{if .Period}}<span class="q-per">/{{.Period}}</span>{{end}}
|
||||
{{else}}{{template "quota-value" dict "Own" "" "Up" .BudgetUp "From" .BudgetFrom}}{{end}}</td>
|
||||
<td class="q-spent"><span class="q-spend">{{.Spend}}</span>
|
||||
{{if .HasPct}}<span class="q-meter{{if ge .Percent 90}} hot{{end}}"><i style="width:{{pct .Percent 100}}%"></i></span>
|
||||
<span class="q-pct">{{.Percent}}%</span>{{end}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
<p class="note">Limits are set by the cluster's administrators.</p>
|
||||
{{end}}
|
||||
|
||||
<h2>Members</h2>
|
||||
{{if .Members}}
|
||||
<table class="compact">
|
||||
<tr><th>Person</th><th>Member of</th><th>State</th></tr>
|
||||
{{range .Members}}<tr>
|
||||
<td>{{.Email}}</td>
|
||||
<td>{{range .Places}}<span class="chip-m">{{.Where}}{{if eq .Role "manager"}} <b class="chip-role">manager</b>{{end}}</span>{{end}}</td>
|
||||
<td class="state state-{{.State}}">{{.State}}</td>
|
||||
</tr>{{end}}
|
||||
</table>
|
||||
{{else}}<p class="empty">Nobody is a member yet.</p>{{end}}
|
||||
|
||||
<footer><span>llmgw {{.Version}}</span><span>{{.Now}}</span></footer>
|
||||
</div></body></html>{{end}}
|
||||
Reference in new issue
Block a user