diff --git a/internal/api/apidocs.go b/internal/api/apidocs.go index d215ebb..c9e5ffa 100644 --- a/internal/api/apidocs.go +++ b/internal/api/apidocs.go @@ -72,6 +72,9 @@ var endpoints = []endpoint{ {method: "GET", path: "/api/v1/org/checkers/:id", tag: "Monitors", summary: "What a checker instance is doing", description: "Platform checkers serve every organization; other organizations' work appears only as a count.", resp: checkerActivity{}}, + {method: "GET", path: "/api/v1/org/limits", tag: "Organization", summary: "Limits in effect for the organization and its usage", + description: "0 means unlimited. Creating beyond a limit gives 422 monitor_limit, status_page_limit, region_limit or platform_region_limit.", + resp: usageView{}}, {method: "GET", path: "/api/v1/org/check-types", tag: "Monitors", summary: "Monitor types this installation offers", resp: obj{"types": []string{}}}, {method: "PUT", path: "/api/v1/org/check-types", tag: "Monitors", summary: "Choose the monitor types offered to members", @@ -241,6 +244,16 @@ var endpoints = []endpoint{ {method: "PUT", path: "/api/v1/admin/checker-network", tag: "Platform", summary: "Let platform checkers check private addresses or not", description: "Unset, they may on self-hosted installations and may not in the cloud edition. Applies from each checker's next poll.", perm: "platform admin", req: checkerNetwork{}, status: http.StatusNoContent}, + {method: "GET", path: "/api/v1/admin/limits", tag: "Platform", summary: "Default limits of organizations and accounts", perm: "platform admin", resp: Limits{}}, + {method: "PUT", path: "/api/v1/admin/limits", tag: "Platform", summary: "Set the default limits", + description: "0 means unlimited. Defaults apply at once to every organization and account without an override of its own. Lowering a limit below current usage keeps everything; only new monitors, status pages, regions or organizations are refused.", + perm: "platform admin", req: limitsRequest{}, status: http.StatusNoContent}, + {method: "GET", path: "/api/v1/admin/orgs", tag: "Platform", summary: "Organizations with usage, limits and owner", + description: "Newest first, at most 500. `q` searches name, slug and owner email.", perm: "platform admin", resp: obj{"orgs": []adminOrg{}}}, + {method: "PUT", path: "/api/v1/admin/orgs/:id/limits", tag: "Platform", summary: "Override an organization's limits", + description: "null follows the platform default, 0 means unlimited.", perm: "platform admin", req: orgLimitsView{}, status: http.StatusNoContent}, + {method: "PUT", path: "/api/v1/admin/users/:id/limits", tag: "Platform", summary: "Override how many organizations an account may own", + description: "null follows the platform default, 0 means unlimited.", perm: "platform admin", req: userLimitsRequest{}, status: http.StatusNoContent}, {method: "GET", path: "/api/v1/admin/status-pages", tag: "Platform", summary: "Public and suspended status pages with organization and owner", description: "Newest first, at most 500. `q` searches title, slug, domain, organization and owner email.", perm: "platform admin", resp: obj{"status_pages": []moderatedPage{}}}, diff --git a/internal/api/audit.go b/internal/api/audit.go index 0aaf800..7ee5f26 100644 --- a/internal/api/audit.go +++ b/internal/api/audit.go @@ -93,6 +93,9 @@ var auditActions = map[string]string{ "PUT /api/v1/org/legal/:kind": "org.legal_update", "PUT /api/v1/admin/check-types": "platform.check_types_update", "PUT /api/v1/admin/checker-network": "platform.checker_network_update", + "PUT /api/v1/admin/limits": "platform.limits_update", + "PUT /api/v1/admin/orgs/:id/limits": "platform.org_limits_update", + "PUT /api/v1/admin/users/:id/limits": "platform.user_limits_update", "PUT /api/v1/admin/status-pages/:id/suspension": "platform.status_page_suspension", "DELETE /api/v1/admin/status-pages/:id": "platform.status_page_delete", "PUT /api/v1/admin/orgs/:id/suspension": "platform.org_suspension", diff --git a/internal/api/limits.go b/internal/api/limits.go new file mode 100644 index 0000000..0e3a36a --- /dev/null +++ b/internal/api/limits.go @@ -0,0 +1,411 @@ +package api + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "strconv" + "strings" + "time" + + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" + "git.zb-server.de/ZB-Server/uptimesebi/internal/web" +) + +// Platform admins limit what organizations and accounts may create. The +// platform defaults apply to every organization without an override of its +// own, also after they change. 0 means unlimited. + +const settingLimits = "limits" + +// Limits are the limits in effect for an organization, or the platform +// defaults. +type Limits struct { + Monitors int `json:"monitors"` + StatusPages int `json:"status_pages"` + RegionsPerMonitor int `json:"regions_per_monitor"` + // OwnRegionsCount makes the organization's own checker regions count + // towards RegionsPerMonitor; otherwise only platform regions do. + OwnRegionsCount bool `json:"own_regions_count"` + // OrgsPerAccount limits the organizations an account owns. + OrgsPerAccount int `json:"orgs_per_account"` +} + +func (s *Server) defaultLimits() Limits { + if s.cloud() { + return Limits{OrgsPerAccount: 3} + } + return Limits{} +} + +// platformLimits returns the platform defaults. +func (s *Server) platformLimits(ctx context.Context) Limits { + l, err := s.limits.get(ctx, s.rdb, func(ctx context.Context) (Limits, error) { + l := s.defaultLimits() + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + raw, err := q.GetPlatformSetting(ctx, settingLimits) + if errors.Is(err, pgx.ErrNoRows) { + return nil + } + if err != nil { + return err + } + return json.Unmarshal(raw, &l) + }) + return l, err + }) + if err != nil { + s.log.WarnContext(ctx, "loading limits failed", "error", err) + return s.defaultLimits() + } + return l +} + +// orgLimits applies org's overrides to the platform defaults. +func (s *Server) orgLimits(ctx context.Context, org store.Org) Limits { + l := s.platformLimits(ctx) + override := func(dst *int, v *int32) { + if v != nil { + *dst = int(*v) + } + } + override(&l.Monitors, org.LimitMonitors) + override(&l.StatusPages, org.LimitStatusPages) + override(&l.RegionsPerMonitor, org.LimitRegionsPerMonitor) + if org.LimitOwnRegionsCount != nil { + l.OwnRegionsCount = *org.LimitOwnRegionsCount + } + return l +} + +// limitError reports a reached limit from inside a transaction. +type limitError struct { + code string + max int +} + +func (e limitError) Error() string { return fmt.Sprintf("api: %s (%d)", e.code, e.max) } + +// failLimit answers err if it is a limitError and reports whether it was. +func failLimit(c *gin.Context, err error) bool { + var le limitError + if errors.As(err, &le) { + fail(c, http.StatusUnprocessableEntity, le.code, "Max", le.max) + return true + } + return false +} + +// reserve locks org's usage and fails if count, from countFn, has reached +// max. +func reserve(ctx context.Context, q *store.Queries, org uuid.UUID, max int, code string, countFn func(context.Context, uuid.UUID) (int64, error)) error { + if max == 0 { + return nil + } + if err := q.LockOrgUsage(ctx, org); err != nil { + return err + } + n, err := countFn(ctx, org) + if err != nil { + return err + } + if n >= int64(max) { + return limitError{code, max} + } + return nil +} + +// countedRegions counts the regions that count towards the limit. +func countedRegions(l Limits, regions []uuid.UUID, platform map[uuid.UUID]bool) int { + n := 0 + for _, r := range regions { + if l.OwnRegionsCount || platform[r] { + n++ + } + } + return n +} + +// checkRegions fails if a monitor would use more counted regions than +// allowed. A monitor already beyond a lowered limit may keep its regions +// but not add any. +func checkRegions(l Limits, regions, previous []uuid.UUID, platform map[uuid.UUID]bool) error { + n := countedRegions(l, regions, platform) + if l.RegionsPerMonitor == 0 || n <= l.RegionsPerMonitor || n <= countedRegions(l, previous, platform) { + return nil + } + if l.OwnRegionsCount { + return limitError{"region_limit", l.RegionsPerMonitor} + } + return limitError{"platform_region_limit", l.RegionsPerMonitor} +} + +type usageView struct { + Limits Limits `json:"limits"` + Usage struct { + Monitors int `json:"monitors"` + StatusPages int `json:"status_pages"` + } `json:"usage"` +} + +func (s *Server) orgUsage(ctx context.Context, p *principal) (usageView, error) { + v := usageView{Limits: s.orgLimits(ctx, p.Org)} + v.Limits.OrgsPerAccount = 0 + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + m, err := q.CountMonitors(ctx, p.Org.ID) + if err != nil { + return err + } + pg, err := q.CountStatusPages(ctx, p.Org.ID) + v.Usage.Monitors, v.Usage.StatusPages = int(m), int(pg) + return err + }) + return v, err +} + +func (s *Server) getOrgLimits(c *gin.Context) { + v, err := s.orgUsage(c.Request.Context(), current(c)) + if err != nil { + internalError(c, err) + return + } + c.JSON(http.StatusOK, v) +} + +func (s *Server) adminGetLimits(c *gin.Context) { + c.JSON(http.StatusOK, s.platformLimits(c.Request.Context())) +} + +type limitsRequest struct { + Monitors int `json:"monitors" binding:"min=0,max=1000000"` + StatusPages int `json:"status_pages" binding:"min=0,max=1000000"` + RegionsPerMonitor int `json:"regions_per_monitor" binding:"min=0,max=1000"` + OwnRegionsCount bool `json:"own_regions_count"` + OrgsPerAccount int `json:"orgs_per_account" binding:"min=0,max=100000"` +} + +func (s *Server) adminSetLimits(c *gin.Context) { + var req limitsRequest + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + raw, _ := json.Marshal(Limits(req)) + auditDetail(c, "limits", Limits(req)) + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + return q.SetPlatformSetting(ctx, store.SetPlatformSettingParams{Key: settingLimits, Value: raw}) + }) + if err != nil { + internalError(c, err) + return + } + if err := s.limits.bump(ctx, s.rdb); err != nil { + s.log.ErrorContext(ctx, "announcing limit change failed", "error", err) + } + c.Status(http.StatusNoContent) +} + +// optBool is a JSON boolean that may be null, and also accepts "true", +// "false" and "" from forms. +type optBool struct{ v *bool } + +// UnmarshalJSON implements json.Unmarshaler. +func (o *optBool) UnmarshalJSON(b []byte) error { + switch strings.Trim(string(b), `"`) { + case "null", "": + o.v = nil + case "true": + t := true + o.v = &t + case "false": + f := false + o.v = &f + default: + return errors.New("not a boolean") + } + return nil +} + +// MarshalJSON implements json.Marshaler. +func (o optBool) MarshalJSON() ([]byte, error) { return json.Marshal(o.v) } + +// orgLimitsRequest overrides limits for one organization; null follows the +// platform default. +type orgLimitsRequest struct { + Monitors *int32 `json:"monitors" binding:"omitempty,min=0,max=1000000"` + StatusPages *int32 `json:"status_pages" binding:"omitempty,min=0,max=1000000"` + RegionsPerMonitor *int32 `json:"regions_per_monitor" binding:"omitempty,min=0,max=1000"` + OwnRegionsCount optBool `json:"own_regions_count"` +} + +func (s *Server) adminSetOrgLimits(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + fail(c, http.StatusNotFound, "not_found") + return + } + var req orgLimitsRequest + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + auditDetail(c, "limits", req) + err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + row, err := q.SetOrgLimits(ctx, store.SetOrgLimitsParams{ + ID: id, Monitors: req.Monitors, StatusPages: req.StatusPages, + RegionsPerMonitor: req.RegionsPerMonitor, OwnRegionsCount: req.OwnRegionsCount.v, + }) + auditDetail(c, "slug", row.Slug) + return err + }) + if moderated(c, err) { + c.Status(http.StatusNoContent) + } +} + +type userLimitsRequest struct { + // Orgs limits the organizations the account owns; null follows the + // platform default. + Orgs *int32 `json:"orgs" binding:"omitempty,min=0,max=100000"` +} + +func (s *Server) adminSetUserLimits(c *gin.Context) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + fail(c, http.StatusNotFound, "not_found") + return + } + var req userLimitsRequest + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + auditDetail(c, "orgs", req.Orgs) + err = s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + row, err := q.SetUserOrgLimit(ctx, store.SetUserOrgLimitParams{ID: id, Orgs: req.Orgs}) + auditDetail(c, "email", row.Email) + return err + }) + if moderated(c, err) { + c.Status(http.StatusNoContent) + } +} + +// adminOrg is an organization in the admin list. +type adminOrg struct { + moderatedOrg + Created string `json:"created_at"` + Overrides orgLimitsView `json:"overrides"` + Limits Limits `json:"limits"` + Usage struct { + Monitors int `json:"monitors"` + StatusPages int `json:"status_pages"` + } `json:"usage"` + Owner *adminOwner `json:"owner"` +} + +type orgLimitsView struct { + Monitors *int32 `json:"monitors"` + StatusPages *int32 `json:"status_pages"` + RegionsPerMonitor *int32 `json:"regions_per_monitor"` + OwnRegionsCount *bool `json:"own_regions_count"` +} + +type adminOwner struct { + moderatedUser + // OrgLimit overrides the organizations the account may own. + OrgLimit *int32 `json:"org_limit"` + Orgs int `json:"orgs"` +} + +func (s *Server) adminOrgs(ctx context.Context, search string) ([]adminOrg, error) { + var rows []store.AdminListOrgsRow + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + var err error + rows, err = q.AdminListOrgs(ctx, store.AdminListOrgsParams{ + Search: truncate(strings.TrimSpace(search), 200), MaxRows: moderationRows, + }) + return err + }) + defaults := s.platformLimits(ctx) + out := make([]adminOrg, len(rows)) + for i, r := range rows { + o := &out[i] + o.moderatedOrg = moderatedOrg{r.ID, r.Slug, r.Name, r.SuspendedAt, r.SuspendedReason} + o.Created = r.CreatedAt.Format("2006-01-02") + o.Overrides = orgLimitsView{r.LimitMonitors, r.LimitStatusPages, r.LimitRegionsPerMonitor, r.LimitOwnRegionsCount} + o.Limits = s.orgLimits(ctx, store.Org{LimitMonitors: r.LimitMonitors, LimitStatusPages: r.LimitStatusPages, + LimitRegionsPerMonitor: r.LimitRegionsPerMonitor, LimitOwnRegionsCount: r.LimitOwnRegionsCount}) + o.Limits.OrgsPerAccount = defaults.OrgsPerAccount + o.Usage.Monitors, o.Usage.StatusPages = int(r.Monitors), int(r.StatusPages) + if r.OwnerID != uuid.Nil { + o.Owner = &adminOwner{ + moderatedUser: moderatedUser{r.OwnerID, r.OwnerEmail, r.OwnerDisabledAt, r.OwnerDisabledReason, r.OwnerIsAdmin}, + OrgLimit: r.OwnerLimitOrgs, Orgs: int(r.OwnerOrgs), + } + if r.OwnerLimitOrgs != nil { + o.Limits.OrgsPerAccount = int(*r.OwnerLimitOrgs) + } + } + } + return out, err +} + +func (s *Server) adminListOrgs(c *gin.Context) { + orgs, err := s.adminOrgs(c.Request.Context(), c.Query("q")) + if err != nil { + internalError(c, err) + return + } + c.JSON(http.StatusOK, gin.H{"orgs": orgs}) +} + +func webLimits(l Limits) web.LimitsView { return web.LimitsView(l) } + +func optInt(v *int32) string { + if v == nil { + return "" + } + return strconv.Itoa(int(*v)) +} + +func (s *Server) orgsView(c *gin.Context) (web.OrgsView, error) { + ctx := c.Request.Context() + // The admin page searches organizations with oq; q is the status page + // search. + orgs, err := s.adminOrgs(ctx, c.Query("oq")) + v := web.OrgsView{Search: strings.TrimSpace(c.Query("oq")), Limited: len(orgs) == moderationRows, Defaults: webLimits(s.platformLimits(ctx))} + state := func(at *time.Time, reason string) string { + switch { + case at == nil: + return "" + case reason == "": + return "-" + } + return reason + } + for _, o := range orgs { + row := web.OrgRow{ + ID: o.ID.String(), Name: o.Name, Slug: o.Slug, Created: o.Created, Suspended: state(o.SuspendedAt, o.Reason), + Monitors: o.Usage.Monitors, StatusPages: o.Usage.StatusPages, Limits: webLimits(o.Limits), + MonitorsOverride: optInt(o.Overrides.Monitors), StatusPagesOverride: optInt(o.Overrides.StatusPages), + RegionsOverride: optInt(o.Overrides.RegionsPerMonitor), + } + if o.Overrides.OwnRegionsCount != nil { + row.OwnRegionsOverride = strconv.FormatBool(*o.Overrides.OwnRegionsCount) + } + if o.Owner != nil { + row.Owner = &web.ModeratedTarget{ID: o.Owner.ID.String(), Name: o.Owner.Email, Suspended: state(o.Owner.SuspendedAt, o.Owner.Reason), Admin: o.Owner.Admin} + row.OwnerOrgs, row.OwnerOrgLimit = o.Owner.Orgs, optInt(o.Owner.OrgLimit) + } + v.Orgs = append(v.Orgs, row) + } + return v, err +} diff --git a/internal/api/limits_test.go b/internal/api/limits_test.go new file mode 100644 index 0000000..6f4af7a --- /dev/null +++ b/internal/api/limits_test.go @@ -0,0 +1,157 @@ +package api_test + +import ( + "context" + "net/http" + "strings" + "sync" + "testing" + + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +func TestLimits(t *testing.T) { + e := newEnv(t) + ctx := context.Background() + reset := func() { + _ = e.asSystem(t, func(tx pgx.Tx) error { + _, err := tx.Exec(ctx, `DELETE FROM platform_settings WHERE key = 'limits'`) + return err + }) + } + reset() + t.Cleanup(reset) + admin := e.browser(t) + admin.signup("admin@"+uniq("lim")+".test", uniq("lim-admin-")) + if err := tenant.New(e.dbPool).Tx(ctx, tenant.Global(), func(q *store.Queries) error { + return q.MakeAdmin(ctx, admin.userIDSelf()) + }); err != nil { + t.Fatal(err) + } + setDefaults := func(l map[string]any) { + t.Helper() + if st, body := admin.do("PUT", "/api/v1/admin/limits", l); st != http.StatusNoContent { + t.Fatalf("set defaults = %d %v", st, body) + } + } + setDefaults(map[string]any{"monitors": 2, "status_pages": 1, "regions_per_monitor": 1, "own_regions_count": false, "orgs_per_account": 3}) + + _, p1 := e.platformChecker(t, uniq("eu-")) + _, p2 := e.platformChecker(t, uniq("us-")) + owner := e.browser(t) + orgSlug := uniq("lim-org-") + owner.signup("o@"+uniq("lim")+".test", orgSlug) + _, own := owner.do("POST", "/api/v1/org/regions", map[string]any{"key": uniq("office-"), "name": "Office"}) + o1 := own["id"].(string) + monitor := func(regions ...string) (int, map[string]any) { + return owner.do("POST", "/api/v1/org/monitors", map[string]any{ + "name": "m", "type": "tcp", "target": "example.com:443", "interval_seconds": 60, "regions": regions, + }) + } + + // Monitors, passive ones included. + if st, body := owner.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb", "type": "heartbeat", "interval_seconds": 3600}); st != http.StatusCreated { + t.Fatalf("heartbeat = %d %v", st, body) + } + if st, body := monitor(p1); st != http.StatusCreated { + t.Fatalf("second monitor = %d %v", st, body) + } + st, body := monitor(p1) + expect(t, "third monitor", st, body, http.StatusUnprocessableEntity, "monitor_limit") + if !strings.Contains(body["message"].(string), "2") { + t.Errorf("message lacks the limit: %v", body["message"]) + } + _, usage := owner.do("GET", "/api/v1/org/limits", nil) + if raw := mustJSON(usage); !strings.Contains(raw, `"monitors":2`) || !strings.Contains(raw, `"usage":{"monitors":2,"status_pages":0}`) { + t.Errorf("org limits = %s", raw) + } + + // An override lifts the monitor limit; own regions do not count. + _, orgs := admin.do("GET", "/api/v1/admin/orgs?q="+orgSlug, nil) + org := orgs["orgs"].([]any)[0].(map[string]any) + orgID := org["id"].(string) + setOrg := func(l map[string]any) { + t.Helper() + if st, body := admin.do("PUT", "/api/v1/admin/orgs/"+orgID+"/limits", l); st != http.StatusNoContent { + t.Fatalf("set org limits = %d %v", st, body) + } + } + setOrg(map[string]any{"monitors": 10, "status_pages": nil, "regions_per_monitor": nil, "own_regions_count": nil}) + st, body = monitor(p1, p2) + expect(t, "two platform regions", st, body, http.StatusUnprocessableEntity, "platform_region_limit") + st, mixed := monitor(p1, o1) + expect(t, "platform and own region", st, mixed, http.StatusCreated, "") + + // Once own regions count, the existing monitor keeps both but may not + // grow, and new ones are refused. + setOrg(map[string]any{"monitors": 10, "own_regions_count": "true"}) + st, body = monitor(p1, o1) + expect(t, "own region counted", st, body, http.StatusUnprocessableEntity, "region_limit") + st, body = owner.do("PUT", "/api/v1/org/monitors/"+mixed["id"].(string), map[string]any{ + "name": "renamed", "type": "tcp", "target": "example.com:443", "interval_seconds": 60, "regions": []string{p1, o1}, + }) + expect(t, "edit a monitor beyond a lowered limit", st, body, http.StatusOK, "") + st, body = owner.do("PUT", "/api/v1/org/monitors/"+mixed["id"].(string), map[string]any{ + "name": "renamed", "type": "tcp", "target": "example.com:443", "interval_seconds": 60, "regions": []string{p1, p2, o1}, + }) + expect(t, "grow a monitor beyond the limit", st, body, http.StatusUnprocessableEntity, "region_limit") + + // Status pages; concurrent creations cannot overshoot. + var wg sync.WaitGroup + var mu sync.Mutex + created := 0 + for range 5 { + wg.Add(1) + go func() { + defer wg.Done() + st, _ := owner.do("POST", "/api/v1/org/statuspages", map[string]any{"slug": uniq("p-"), "title": "x"}) + mu.Lock() + defer mu.Unlock() + if st == http.StatusCreated { + created++ + } + }() + } + wg.Wait() + if created != 1 { + t.Errorf("%d status pages created under a limit of 1", created) + } + + // Defaults change for every organization without an override, at once. + other := e.browser(t) + other.signup("x@"+uniq("lim")+".test", uniq("lim-x-")) + setDefaults(map[string]any{"monitors": 1}) + if st, _ := other.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb", "type": "heartbeat", "interval_seconds": 3600}); st != http.StatusCreated { + t.Fatalf("first monitor = %d", st) + } + st, body = other.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb2", "type": "heartbeat", "interval_seconds": 3600}) + expect(t, "default lowered", st, body, http.StatusUnprocessableEntity, "monitor_limit") + setDefaults(map[string]any{"monitors": 0}) + st, body = other.do("POST", "/api/v1/org/monitors", map[string]any{"name": "hb2", "type": "heartbeat", "interval_seconds": 3600}) + expect(t, "default unlimited", st, body, http.StatusCreated, "") + + // Account limits and the admin list. + ownerID := org["owner"].(map[string]any)["id"].(string) + if st, body := admin.do("PUT", "/api/v1/admin/users/"+ownerID+"/limits", map[string]any{"orgs": 5}); st != http.StatusNoContent { + t.Fatalf("set user limit = %d %v", st, body) + } + _, orgs = admin.do("GET", "/api/v1/admin/orgs?q="+orgSlug, nil) + raw := mustJSON(orgs) + for _, want := range []string{`"org_limit":5`, `"orgs":1`, `"monitors":10`, `"own_regions_count":true`, `"usage":{"monitors":3,"status_pages":1}`} { + if !strings.Contains(raw, want) { + t.Errorf("admin org list lacks %s: %s", want, raw) + } + } + if st, _ := owner.do("GET", "/api/v1/admin/orgs", nil); st != http.StatusForbidden { + t.Errorf("non-admin org list = %d", st) + } + if _, _, html := admin.page("/admin?oq=" + orgSlug); !strings.Contains(html, `id="orgs"`) || !strings.Contains(html, orgSlug) { + t.Error("the admin page lacks the organization list") + } + if _, _, html := owner.page("/settings/org"); !strings.Contains(html, "3 / 10") { + t.Error("the organization settings lack the usage") + } +} diff --git a/internal/api/monitors.go b/internal/api/monitors.go index 34d421e..fdd9e0d 100644 --- a/internal/api/monitors.go +++ b/internal/api/monitors.go @@ -34,6 +34,9 @@ type monitorRequest struct { // Confirmations is how many failures in a row make a region count as // down; 0 keeps the default of 2. Confirmations int `json:"confirmations" binding:"min=0,max=10"` + // platform marks the platform regions among those visible, filled by + // validateMonitor. + platform map[uuid.UUID]bool // GroupID places the monitor in a group; nil keeps it at the top level. GroupID *uuid.UUID `json:"group_id"` // AlertGroupIDs defaults on creation and preserves assignments on update @@ -169,6 +172,10 @@ func (s *Server) validateMonitor(c *gin.Context, req *monitorRequest, t groupTre internalError(c, err) return false } + req.platform = map[uuid.UUID]bool{} + for _, k := range known { + req.platform[k.ID] = k.OrgID == nil + } for _, r := range req.Regions { // Row-level security limits known to the org's own and the // platform regions. @@ -270,8 +277,15 @@ func (s *Server) createMonitor(c *gin.Context) { } req.Target = passiveTarget(check.Type(req.Type), req.Target) req.Config = s.sealMonitorConfig(check.Type(req.Type), req.Config, nil) + limits := s.orgLimits(ctx, p.Org) + if err := checkRegions(limits, req.Regions, nil, req.platform); failLimit(c, err) { + return + } var m store.Monitor err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + if err := reserve(ctx, q, p.Org.ID, limits.Monitors, "monitor_limit", q.CountMonitors); err != nil { + return err + } var err error m, err = q.CreateMonitor(ctx, store.CreateMonitorParams{ OrgID: p.Org.ID, Name: req.Name, Type: req.Type, Target: req.Target, @@ -295,6 +309,9 @@ func (s *Server) createMonitor(c *gin.Context) { fail(c, http.StatusUnprocessableEntity, "invalid_alert_group") return } + if failLimit(c, err) { + return + } if err != nil { internalError(c, err) return @@ -380,6 +397,9 @@ func (s *Server) updateMonitor(c *gin.Context) { if old.Type != req.Type && !s.offered(ctx, p.Org, req.Type) { return errCheckTypeDisabled } + if err := checkRegions(s.orgLimits(ctx, p.Org), req.Regions, previous, req.platform); err != nil { + return err + } if old.Type == req.Type { req.Config = s.sealMonitorConfig(check.Type(req.Type), req.Config, old.Config) } else { @@ -418,6 +438,9 @@ func (s *Server) updateMonitor(c *gin.Context) { fail(c, http.StatusUnprocessableEntity, "check_type_disabled") return } + if failLimit(c, err) { + return + } if errors.Is(err, pgx.ErrNoRows) || (err == nil && denied) { fail(c, http.StatusNotFound, "not_found") return diff --git a/internal/api/pages.go b/internal/api/pages.go index 98f3390..ff0adc0 100644 --- a/internal/api/pages.go +++ b/internal/api/pages.go @@ -283,6 +283,11 @@ func (s *Server) ssoSettingsView(c *gin.Context, p *principal, page web.Page, me func (s *Server) orgSettingsView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { v := web.OrgSettings{RequireTOTP: p.Org.RequireTotp, RequireSSO: p.Org.RequireSso} + u, err := s.orgUsage(c.Request.Context(), p) + if err != nil { + return nil, err + } + v.Usage = web.UsageView{Limits: webLimits(u.Limits), Monitors: u.Usage.Monitors, StatusPages: u.Usage.StatusPages} off := s.disabledChecks(c.Request.Context()) for _, t := range check.Types { if !off[string(t)] { @@ -511,7 +516,12 @@ func (s *Server) adminPage(c *gin.Context) { internalError(c, err) return } - web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats), types, s.platformPrivate(ctx), mod)) + orgs, err := s.orgsView(c) + if err != nil { + internalError(c, err) + return + } + web.Render(c, http.StatusOK, web.AdminPage(s.pageFor(c, "admin.title"), me, v, storageView(c, stats), types, s.platformPrivate(ctx), mod, orgs)) } func (s *Server) buildRegionsView(ctx context.Context, regions []store.Region, agents []store.ListAgentsRow, apiBase, next string, manageable func(store.Region) bool) (web.RegionsView, error) { diff --git a/internal/api/server.go b/internal/api/server.go index 07a4892..ca23460 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -49,6 +49,8 @@ type Server struct { // checkerNet caches whether platform checkers may reach private // addresses. checkerNet *versioned[bool] + // limits caches the platform's default limits. + limits *versioned[Limits] } // Deps are the external resources a Server needs. @@ -82,6 +84,7 @@ func New(cfg config.API, d Deps) *Server { legal: newVersioned[[]agentapi.LegalDoc]("legal"), checkTypes: newVersioned[map[string]bool]("check-types"), checkerNet: newVersioned[bool]("checker-network"), + limits: newVersioned[Limits]("limits"), } } @@ -144,6 +147,7 @@ func (s *Server) Mount(r gin.IRouter) { org.DELETE("/alertmanager/receivers/:id", sessionOnly(), can(authz.OrgManage), s.deleteReceiver) org.GET("/alertmanager/alerts", can(authz.MonitorsRead), s.listFiringAlerts) org.GET("/check-types", s.orgCheckTypes) + org.GET("/limits", s.getOrgLimits) org.PUT("/check-types", sessionOnly(), can(authz.OrgManage), s.orgSetCheckTypes) org.GET("/maintenance", s.listMaintenance) org.POST("/maintenance", s.createMaintenance) @@ -167,6 +171,11 @@ func (s *Server) Mount(r gin.IRouter) { admin.GET("/check-types", s.adminListCheckTypes) admin.PUT("/check-types", s.adminSetCheckTypes) admin.GET("/checker-network", s.adminGetCheckerNetwork) + admin.GET("/limits", s.adminGetLimits) + admin.PUT("/limits", s.adminSetLimits) + admin.GET("/orgs", s.adminListOrgs) + admin.PUT("/orgs/:id/limits", s.adminSetOrgLimits) + admin.PUT("/users/:id/limits", s.adminSetUserLimits) admin.GET("/status-pages", s.adminListStatusPages) admin.PUT("/status-pages/:id/suspension", s.adminSuspendStatusPage) admin.DELETE("/status-pages/:id", s.adminDeleteStatusPage) diff --git a/internal/api/statuspages.go b/internal/api/statuspages.go index 102b8d7..bb1b62f 100644 --- a/internal/api/statuspages.go +++ b/internal/api/statuspages.go @@ -472,6 +472,9 @@ func (s *Server) createStatusPage(c *gin.Context) { theme, _ := json.Marshal(req.Theme) var row store.StatusPage err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + if err := reserve(ctx, q, p.Org.ID, s.orgLimits(ctx, p.Org).StatusPages, "status_page_limit", q.CountStatusPages); err != nil { + return err + } var err error row, err = q.CreateStatusPage(ctx, store.CreateStatusPageParams{ OrgID: p.Org.ID, Slug: req.Slug, Title: req.Title, Description: req.Description, @@ -480,6 +483,9 @@ func (s *Server) createStatusPage(c *gin.Context) { }) return err }) + if failLimit(c, err) { + return + } if isUniqueViolation(err, "status_pages_slug_key") { fail(c, http.StatusConflict, "slug_taken") return diff --git a/internal/i18n/i18n_test.go b/internal/i18n/i18n_test.go index 97c64e0..96a84f9 100644 --- a/internal/i18n/i18n_test.go +++ b/internal/i18n/i18n_test.go @@ -170,6 +170,7 @@ func TestDynamicFamilies(t *testing.T) { "moderation.target_": {"page", "org", "owner"}, "moderation.delete_": {"page", "org", "owner"}, "moderation.delete_confirm_": {"page", "org", "owner"}, + "limits.own_": {"true", "false"}, "weekday.": {"0", "1", "2", "3", "4", "5", "6"}, "md.": {"heading", "bold", "italic", "strike", "link", "ul", "ol", "quote", "code", "codeblock", "table", "hr"}, "maintenance.recurrence_": {"none", "daily", "weekly", "monthly"}, diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index 8533485..26599b1 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -97,13 +97,16 @@ "audit.action.platform.check_types_update": "Check-Typen geändert", "audit.action.platform.checker_network_update": "Checker-Netzwerk geändert", "audit.action.platform.legal_update": "Rechtstext der Plattform geändert", + "audit.action.platform.limits_update": "Standard-Limits geändert", "audit.action.platform.org_delete": "Organisation durch Admin gelöscht", + "audit.action.platform.org_limits_update": "Limits einer Organisation geändert", "audit.action.platform.org_suspension": "Organisation gesperrt oder entsperrt", "audit.action.platform.region_create": "Plattform-Region erstellt", "audit.action.platform.region_delete": "Plattform-Region gelöscht", "audit.action.platform.status_page_delete": "Statusseite durch Admin gelöscht", "audit.action.platform.status_page_suspension": "Statusseite gesperrt oder entsperrt", "audit.action.platform.user_delete": "Account durch Admin gelöscht", + "audit.action.platform.user_limits_update": "Limits eines Accounts geändert", "audit.action.platform.user_suspension": "Account gesperrt oder entsperrt", "audit.action.region.create": "Region erstellt", "audit.action.region.delete": "Region gelöscht", @@ -529,6 +532,7 @@ "error.maintenance_overlaps": "Die Wartung würde länger dauern als der Abstand bis zur Wiederholung.", "error.maintenance_without_targets": "Wähle mindestens einen Monitor oder eine Gruppe.", "error.mfa_expired": "Anmeldung abgelaufen, bitte erneut anmelden.", + "error.monitor_limit": "Deine Organisation hat ihr Limit von {{.Max}} Monitoren erreicht.", "error.no_domain": "Lege zuerst eine eigene Domain fest.", "error.no_password": "Konto ohne Passwort.", "error.not_found": "Nicht gefunden.", @@ -539,10 +543,12 @@ "error.owns_shared_orgs": "Du besitzt Organisationen mit weiteren Mitgliedern. Übergib oder lösche sie zuerst.", "error.password_too_short": "Das Passwort braucht mindestens {{.Min}} Zeichen.", "error.permission_escalation": "Du kannst keine Berechtigungen vergeben, die du selbst nicht hast.", + "error.platform_region_limit": "Ein Monitor darf aus höchstens {{.Max}} Plattform-Regionen geprüft werden; eigene Checker-Regionen zählen nicht.", "error.policy_would_lock_you_out": "Deine aktuelle Anmeldung erfüllt diese Richtlinie nicht. Erfülle sie zuerst und aktiviere sie dann.", "error.rate_limited": "Zu viele Versuche, bitte später erneut.", "error.region_in_use": "Die Region wird noch von Monitoren oder Agents genutzt.", "error.region_key_taken": "Eine Region mit diesem Schlüssel gibt es bereits.", + "error.region_limit": "Ein Monitor darf aus höchstens {{.Max}} Regionen geprüft werden.", "error.role_built_in": "Eingebaute Rollen können nicht geändert werden.", "error.role_in_use": "Die Rolle ist noch Mitgliedern zugewiesen.", "error.role_name_taken": "Eine Rolle mit diesem Namen gibt es bereits.", @@ -563,6 +569,7 @@ "error.sso_provider_error": "Der Identity Provider konnte die Anmeldung nicht abschließen.", "error.sso_required_by_org": "Diese Organisation verlangt die Anmeldung über ihren SSO-Provider.", "error.sso_unavailable": "Für diese Organisation ist kein Single Sign-on verfügbar.", + "error.status_page_limit": "Deine Organisation hat ihr Limit von {{.Max}} Statusseiten erreicht.", "error.target_is_admin": "Plattform-Admins können hier nicht gesperrt oder gelöscht werden.", "error.token_lifetime_exceeds_policy": { "one": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tag ablaufen.", @@ -744,6 +751,20 @@ "legal.platform_title": "Impressum & Datenschutz der Plattform", "legal.privacy": "Datenschutz", "legal.url": "Link auf eine bestehende Seite", + "limits.default": "Standard: {{.Value}}", + "limits.intro": "Gelten für jede Organisation und jeden Account ohne eigenen Wert, auch wenn du sie später änderst. 0 heißt unbegrenzt. Ein gesenktes Limit lässt alles Bestehende stehen; nur neue Monitore, Statusseiten, Regionen oder Organisationen werden abgelehnt.", + "limits.monitors": "Monitore", + "limits.org_title": "Kontingent", + "limits.orgs_per_account": "Organisationen pro Account", + "limits.own_false": "zählen nicht", + "limits.own_regions_count": "Eigene Checker-Regionen zählen zum Regionen-Limit", + "limits.own_regions_count_hint": "Aus: Organisationen dürfen beliebig viele eigene Regionen nutzen; begrenzt werden nur Plattform-Regionen.", + "limits.own_regions_free": "Eigene Checker-Regionen zählen nicht zum Regionen-Limit.", + "limits.own_true": "zählen", + "limits.regions_per_monitor": "Regionen pro Monitor", + "limits.status_pages": "Statusseiten", + "limits.title": "Standard-Limits", + "limits.unlimited": "unbegrenzt", "maintenance.delete_confirm": "Dieses Wartungsfenster samt Wiederholungen löschen?", "maintenance.edit": "Wartung bearbeiten", "maintenance.empty": "Keine Wartung geplant.", @@ -1011,6 +1032,13 @@ "org.token_max_days": "Maximale Gültigkeit von API-Tokens (Tage)", "org.token_max_days_hint": "Neue Tokens müssen innerhalb dieses Zeitraums ablaufen. Beim Speichern werden bestehende Tokens gekürzt, die länger gelten würden. Leer lassen für keine Begrenzung.", "org.token_max_days_none": "unbegrenzt", + "orgs.intro": "Alle Organisationen mit Inhaber, Nutzung und Limits. Ein leeres Limit folgt dem Standard.", + "orgs.limits": "Limits dieser Organisation", + "orgs.manage": "Limits, sperren oder löschen …", + "orgs.none": "Keine Organisation gefunden.", + "orgs.owner_orgs": "Organisationen, die der Inhaber besitzen darf (besitzt {{.Count}})", + "orgs.search": "Name, Kürzel oder E-Mail des Inhabers", + "orgs.title": "Organisationen", "page.component.degraded": "Eingeschränkt", "page.component.maintenance": "Wartung", "page.component.operational": "In Betrieb", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index a0294eb..36e4a7a 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -97,13 +97,16 @@ "audit.action.platform.check_types_update": "Check types changed", "audit.action.platform.checker_network_update": "Checker network changed", "audit.action.platform.legal_update": "Platform legal document changed", + "audit.action.platform.limits_update": "Default limits changed", "audit.action.platform.org_delete": "Organization deleted by admin", + "audit.action.platform.org_limits_update": "Organization limits changed", "audit.action.platform.org_suspension": "Organization suspended or reinstated", "audit.action.platform.region_create": "Platform region created", "audit.action.platform.region_delete": "Platform region deleted", "audit.action.platform.status_page_delete": "Status page deleted by admin", "audit.action.platform.status_page_suspension": "Status page suspended or reinstated", "audit.action.platform.user_delete": "Account deleted by admin", + "audit.action.platform.user_limits_update": "Account limits changed", "audit.action.platform.user_suspension": "Account suspended or reinstated", "audit.action.region.create": "Region created", "audit.action.region.delete": "Region deleted", @@ -529,6 +532,7 @@ "error.maintenance_overlaps": "The maintenance would last longer than the time until it repeats.", "error.maintenance_without_targets": "Choose at least one monitor or group.", "error.mfa_expired": "Sign-in expired, please start again.", + "error.monitor_limit": "Your organization has reached its limit of {{.Max}} monitors.", "error.no_domain": "Set a custom domain first.", "error.no_password": "This account has no password.", "error.not_found": "Not found.", @@ -539,10 +543,12 @@ "error.owns_shared_orgs": "You own organizations with other members. Hand them over or delete them first.", "error.password_too_short": "The password needs at least {{.Min}} characters.", "error.permission_escalation": "You cannot grant permissions you do not hold yourself.", + "error.platform_region_limit": "A monitor may be checked from at most {{.Max}} platform regions; your own checker regions do not count.", "error.policy_would_lock_you_out": "Your current sign-in does not meet this policy. Meet it first, then turn it on.", "error.rate_limited": "Too many attempts, please try again later.", "error.region_in_use": "The region is still used by monitors or agents.", "error.region_key_taken": "A region with this key already exists.", + "error.region_limit": "A monitor may be checked from at most {{.Max}} regions.", "error.role_built_in": "Built-in roles cannot be changed.", "error.role_in_use": "The role is still assigned to members.", "error.role_name_taken": "A role with this name already exists.", @@ -563,6 +569,7 @@ "error.sso_provider_error": "The identity provider could not complete the sign-in.", "error.sso_required_by_org": "This organization requires signing in through its SSO provider.", "error.sso_unavailable": "Single sign-on is not available for this organization.", + "error.status_page_limit": "Your organization has reached its limit of {{.Max}} status pages.", "error.target_is_admin": "Platform admins cannot be suspended or deleted here.", "error.token_lifetime_exceeds_policy": { "one": "Tokens in this organization must expire within {{.Count}} day.", @@ -744,6 +751,20 @@ "legal.platform_title": "Platform legal notice & privacy", "legal.privacy": "Privacy policy", "legal.url": "Link to an existing page", + "limits.default": "default: {{.Value}}", + "limits.intro": "Apply to every organization and account without an override of its own, also when you change them later. 0 means unlimited. Lowering a limit keeps everything that exists; only new monitors, status pages, regions or organizations are refused.", + "limits.monitors": "Monitors", + "limits.org_title": "Usage", + "limits.orgs_per_account": "Organizations per account", + "limits.own_false": "do not count", + "limits.own_regions_count": "Own checker regions count towards the region limit", + "limits.own_regions_count_hint": "Off: organizations may add as many of their own regions as they like; only platform regions are limited.", + "limits.own_regions_free": "Your own checker regions do not count towards the region limit.", + "limits.own_true": "count", + "limits.regions_per_monitor": "Regions per monitor", + "limits.status_pages": "Status pages", + "limits.title": "Default limits", + "limits.unlimited": "unlimited", "maintenance.delete_confirm": "Delete this maintenance window and all its repeats?", "maintenance.edit": "Edit maintenance", "maintenance.empty": "No maintenance planned.", @@ -1011,6 +1032,13 @@ "org.token_max_days": "Maximum API token lifetime (days)", "org.token_max_days_hint": "New tokens must expire within this period. Saving shortens existing tokens that would outlive it. Leave empty for no limit.", "org.token_max_days_none": "unlimited", + "orgs.intro": "All organizations with their owner, usage and limits. Leave a limit empty to follow the default.", + "orgs.limits": "Limits of this organization", + "orgs.manage": "Limits, suspend or delete …", + "orgs.none": "No organization matches.", + "orgs.owner_orgs": "Organizations the owner may own (owns {{.Count}})", + "orgs.search": "Name, slug or owner email", + "orgs.title": "Organizations", "page.component.degraded": "Degraded", "page.component.maintenance": "Maintenance", "page.component.operational": "Operational", diff --git a/internal/migrations/sql/00043_limits.sql b/internal/migrations/sql/00043_limits.sql new file mode 100644 index 0000000..9a0eff3 --- /dev/null +++ b/internal/migrations/sql/00043_limits.sql @@ -0,0 +1,18 @@ +-- +goose Up +-- Limits set by platform admins for one organization or account; NULL +-- follows the platform default, 0 means unlimited. +ALTER TABLE orgs ADD COLUMN limit_monitors integer CHECK (limit_monitors >= 0); +ALTER TABLE orgs ADD COLUMN limit_status_pages integer CHECK (limit_status_pages >= 0); +ALTER TABLE orgs ADD COLUMN limit_regions_per_monitor integer CHECK (limit_regions_per_monitor >= 0); +-- Whether the organization's own checker regions count towards +-- limit_regions_per_monitor. +ALTER TABLE orgs ADD COLUMN limit_own_regions_count boolean; +-- Organizations the account may create. +ALTER TABLE users ADD COLUMN limit_orgs integer CHECK (limit_orgs >= 0); + +-- +goose Down +ALTER TABLE users DROP COLUMN limit_orgs; +ALTER TABLE orgs DROP COLUMN limit_own_regions_count; +ALTER TABLE orgs DROP COLUMN limit_regions_per_monitor; +ALTER TABLE orgs DROP COLUMN limit_status_pages; +ALTER TABLE orgs DROP COLUMN limit_monitors; diff --git a/internal/store/limits.sql.go b/internal/store/limits.sql.go new file mode 100644 index 0000000..01dbde2 --- /dev/null +++ b/internal/store/limits.sql.go @@ -0,0 +1,194 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: limits.sql + +package store + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const adminListOrgs = `-- name: AdminListOrgs :many +SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason, + o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count, + (SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors, + (SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages, + coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id, + coalesce(ow.email::text, '')::text AS owner_email, ow.disabled_at AS owner_disabled_at, + coalesce(ow.disabled_reason, '')::text AS owner_disabled_reason, coalesce(ow.is_admin, false)::boolean AS owner_is_admin, + ow.limit_orgs AS owner_limit_orgs, + coalesce(ow.owned, 0)::integer AS owner_orgs +FROM orgs o +LEFT JOIN LATERAL ( + SELECT u.id, u.email, u.disabled_at, u.disabled_reason, u.is_admin, u.limit_orgs, + (SELECT count(*) FROM memberships m2 WHERE m2.user_id = u.id AND m2.is_owner) AS owned + FROM memberships m JOIN users u ON u.id = m.user_id + WHERE m.org_id = o.id AND m.is_owner ORDER BY m.created_at LIMIT 1 +) ow ON true +WHERE $1::text = '' + OR o.name ILIKE '%' || $1 || '%' OR o.slug::text ILIKE '%' || $1 || '%' + OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%' +ORDER BY o.created_at DESC +LIMIT $2 +` + +type AdminListOrgsParams struct { + Search string + MaxRows int32 +} + +type AdminListOrgsRow struct { + ID uuid.UUID + Slug string + Name string + CreatedAt time.Time + SuspendedAt *time.Time + SuspendedReason string + LimitMonitors *int32 + LimitStatusPages *int32 + LimitRegionsPerMonitor *int32 + LimitOwnRegionsCount *bool + Monitors int32 + StatusPages int32 + OwnerID uuid.UUID + OwnerEmail string + OwnerDisabledAt *time.Time + OwnerDisabledReason string + OwnerIsAdmin bool + OwnerLimitOrgs *int32 + OwnerOrgs int32 +} + +// System scope: organizations with their usage, limit overrides and owner, +// newest first, matching search in name, slug or owner email. +func (q *Queries) AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, error) { + rows, err := q.db.Query(ctx, adminListOrgs, arg.Search, arg.MaxRows) + if err != nil { + return nil, err + } + defer rows.Close() + items := []AdminListOrgsRow{} + for rows.Next() { + var i AdminListOrgsRow + if err := rows.Scan( + &i.ID, + &i.Slug, + &i.Name, + &i.CreatedAt, + &i.SuspendedAt, + &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, + &i.Monitors, + &i.StatusPages, + &i.OwnerID, + &i.OwnerEmail, + &i.OwnerDisabledAt, + &i.OwnerDisabledReason, + &i.OwnerIsAdmin, + &i.OwnerLimitOrgs, + &i.OwnerOrgs, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const countMonitors = `-- name: CountMonitors :one +SELECT count(*) FROM monitors WHERE org_id = $1 +` + +func (q *Queries) CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error) { + row := q.db.QueryRow(ctx, countMonitors, orgID) + var count int64 + err := row.Scan(&count) + return count, err +} + +const countStatusPages = `-- name: CountStatusPages :one +SELECT count(*) FROM status_pages WHERE org_id = $1 +` + +func (q *Queries) CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error) { + row := q.db.QueryRow(ctx, countStatusPages, orgID) + var count int64 + err := row.Scan(&count) + return count, err +} + +const lockOrgUsage = `-- name: LockOrgUsage :exec +SELECT pg_advisory_xact_lock(hashtextextended('usage:' || $1::uuid::text, 0)) +` + +// Serializes creations counted against org's limits until the transaction +// ends. +func (q *Queries) LockOrgUsage(ctx context.Context, orgID uuid.UUID) error { + _, err := q.db.Exec(ctx, lockOrgUsage, orgID) + return err +} + +const setOrgLimits = `-- name: SetOrgLimits :one +UPDATE orgs SET limit_monitors = $1, limit_status_pages = $2, + limit_regions_per_monitor = $3, limit_own_regions_count = $4 +WHERE id = $5 +RETURNING id, slug +` + +type SetOrgLimitsParams struct { + Monitors *int32 + StatusPages *int32 + RegionsPerMonitor *int32 + OwnRegionsCount *bool + ID uuid.UUID +} + +type SetOrgLimitsRow struct { + ID uuid.UUID + Slug string +} + +func (q *Queries) SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error) { + row := q.db.QueryRow(ctx, setOrgLimits, + arg.Monitors, + arg.StatusPages, + arg.RegionsPerMonitor, + arg.OwnRegionsCount, + arg.ID, + ) + var i SetOrgLimitsRow + err := row.Scan(&i.ID, &i.Slug) + return i, err +} + +const setUserOrgLimit = `-- name: SetUserOrgLimit :one +UPDATE users SET limit_orgs = $1 WHERE id = $2 +RETURNING id, email +` + +type SetUserOrgLimitParams struct { + Orgs *int32 + ID uuid.UUID +} + +type SetUserOrgLimitRow struct { + ID uuid.UUID + Email string +} + +func (q *Queries) SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error) { + row := q.db.QueryRow(ctx, setUserOrgLimit, arg.Orgs, arg.ID) + var i SetUserOrgLimitRow + err := row.Scan(&i.ID, &i.Email) + return i, err +} diff --git a/internal/store/models.go b/internal/store/models.go index 4cbb1f1..29fa41c 100644 --- a/internal/store/models.go +++ b/internal/store/models.go @@ -275,17 +275,21 @@ type NotificationChannel struct { } type Org struct { - ID uuid.UUID - Slug string - Name string - CreatedAt time.Time - UpdatedAt time.Time - RequireTotp bool - RequireSso bool - ApiTokenMaxDays *int32 - DisabledCheckTypes []string - SuspendedAt *time.Time - SuspendedReason string + ID uuid.UUID + Slug string + Name string + CreatedAt time.Time + UpdatedAt time.Time + RequireTotp bool + RequireSso bool + ApiTokenMaxDays *int32 + DisabledCheckTypes []string + SuspendedAt *time.Time + SuspendedReason string + LimitMonitors *int32 + LimitStatusPages *int32 + LimitRegionsPerMonitor *int32 + LimitOwnRegionsCount *bool } type PlatformSetting struct { @@ -397,6 +401,7 @@ type User struct { Locale *string IsAdmin bool DisabledReason string + LimitOrgs *int32 } type UserIdentity struct { diff --git a/internal/store/orgs.sql.go b/internal/store/orgs.sql.go index bd3dd2d..2cca851 100644 --- a/internal/store/orgs.sql.go +++ b/internal/store/orgs.sql.go @@ -13,7 +13,7 @@ import ( const createOrg = `-- name: CreateOrg :one INSERT INTO orgs (id, slug, name) VALUES ($1, $2, $3) -RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason +RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count ` type CreateOrgParams struct { @@ -37,6 +37,10 @@ func (q *Queries) CreateOrg(ctx context.Context, arg CreateOrgParams) (Org, erro &i.DisabledCheckTypes, &i.SuspendedAt, &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, ) return i, err } @@ -54,7 +58,7 @@ func (q *Queries) DeleteOrg(ctx context.Context, id uuid.UUID) (int64, error) { } const getOrg = `-- name: GetOrg :one -SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs WHERE id = $1 +SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE id = $1 ` func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) { @@ -72,12 +76,16 @@ func (q *Queries) GetOrg(ctx context.Context, id uuid.UUID) (Org, error) { &i.DisabledCheckTypes, &i.SuspendedAt, &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, ) return i, err } const getOrgBySlug = `-- name: GetOrgBySlug :one -SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs WHERE slug = $1 +SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs WHERE slug = $1 ` func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) { @@ -95,12 +103,16 @@ func (q *Queries) GetOrgBySlug(ctx context.Context, slug string) (Org, error) { &i.DisabledCheckTypes, &i.SuspendedAt, &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, ) return i, err } const listOrgs = `-- name: ListOrgs :many -SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason FROM orgs ORDER BY name +SELECT id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count FROM orgs ORDER BY name ` func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) { @@ -124,6 +136,10 @@ func (q *Queries) ListOrgs(ctx context.Context) ([]Org, error) { &i.DisabledCheckTypes, &i.SuspendedAt, &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, ); err != nil { return nil, err } @@ -152,7 +168,7 @@ func (q *Queries) SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabl const updateOrgPolicy = `-- name: UpdateOrgPolicy :one UPDATE orgs SET require_totp = $2, require_sso = $3, api_token_max_days = $4, updated_at = now() WHERE id = $1 -RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason +RETURNING id, slug, name, created_at, updated_at, require_totp, require_sso, api_token_max_days, disabled_check_types, suspended_at, suspended_reason, limit_monitors, limit_status_pages, limit_regions_per_monitor, limit_own_regions_count ` type UpdateOrgPolicyParams struct { @@ -182,6 +198,10 @@ func (q *Queries) UpdateOrgPolicy(ctx context.Context, arg UpdateOrgPolicyParams &i.DisabledCheckTypes, &i.SuspendedAt, &i.SuspendedReason, + &i.LimitMonitors, + &i.LimitStatusPages, + &i.LimitRegionsPerMonitor, + &i.LimitOwnRegionsCount, ) return i, err } diff --git a/internal/store/querier.go b/internal/store/querier.go index 0101cce..b15bd87 100644 --- a/internal/store/querier.go +++ b/internal/store/querier.go @@ -19,6 +19,9 @@ type Querier interface { AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error) AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error + // System scope: organizations with their usage, limit overrides and owner, + // newest first, matching search in name, slug or owner email. + AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, error) // System scope: public status pages and suspended ones, with their // organization and its owner, newest first, matching search in title, // slug, domain, organization or owner email. @@ -42,7 +45,9 @@ type Querier interface { ClearMaintenanceTargets(ctx context.Context, windowID uuid.UUID) error ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error + CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error) CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error) + CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error) CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error) CreateAPIToken(ctx context.Context, arg CreateAPITokenParams) (ApiToken, error) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error) @@ -193,6 +198,9 @@ type Querier interface { // Row-level security limits this to platform regions and the scope's org; // the org's own regions come first. ListVisibleRegions(ctx context.Context) ([]Region, error) + // Serializes creations counted against org's limits until the transaction + // ends. + LockOrgUsage(ctx context.Context, orgID uuid.UUID) error // System scope: windows covering any of the monitors, directly or through // their group or one of its ancestors. MaintenanceForMonitors(ctx context.Context, ids []uuid.UUID) ([]MaintenanceForMonitorsRow, error) @@ -263,6 +271,7 @@ type Querier interface { ScrubAuditEmail(ctx context.Context, email string) error SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error) SetOrgDisabledCheckTypes(ctx context.Context, arg SetOrgDisabledCheckTypesParams) error + SetOrgLimits(ctx context.Context, arg SetOrgLimitsParams) (SetOrgLimitsRow, error) SetPasswordHash(ctx context.Context, arg SetPasswordHashParams) error SetPlatformSetting(ctx context.Context, arg SetPlatformSettingParams) error // Changing the domain drops a previous verification. @@ -270,6 +279,7 @@ type Querier interface { SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error + SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error) // Other instances of the same agent seen in the last day. SiblingInstances(ctx context.Context, agentID uuid.UUID) ([]SiblingInstancesRow, error) StatusPageMonitors(ctx context.Context, pageID uuid.UUID) ([]StatusPageMonitorsRow, error) diff --git a/internal/store/queries/limits.sql b/internal/store/queries/limits.sql new file mode 100644 index 0000000..5795b5a --- /dev/null +++ b/internal/store/queries/limits.sql @@ -0,0 +1,45 @@ +-- name: LockOrgUsage :exec +-- Serializes creations counted against org's limits until the transaction +-- ends. +SELECT pg_advisory_xact_lock(hashtextextended('usage:' || sqlc.arg(org_id)::uuid::text, 0)); + +-- name: CountMonitors :one +SELECT count(*) FROM monitors WHERE org_id = $1; + +-- name: CountStatusPages :one +SELECT count(*) FROM status_pages WHERE org_id = $1; + +-- name: SetOrgLimits :one +UPDATE orgs SET limit_monitors = sqlc.narg(monitors), limit_status_pages = sqlc.narg(status_pages), + limit_regions_per_monitor = sqlc.narg(regions_per_monitor), limit_own_regions_count = sqlc.narg(own_regions_count) +WHERE id = sqlc.arg(id) +RETURNING id, slug; + +-- name: SetUserOrgLimit :one +UPDATE users SET limit_orgs = sqlc.narg(orgs) WHERE id = sqlc.arg(id) +RETURNING id, email; + +-- name: AdminListOrgs :many +-- System scope: organizations with their usage, limit overrides and owner, +-- newest first, matching search in name, slug or owner email. +SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason, + o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count, + (SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors, + (SELECT count(*) FROM status_pages p WHERE p.org_id = o.id)::integer AS status_pages, + coalesce(ow.id, '00000000-0000-0000-0000-000000000000'::uuid)::uuid AS owner_id, + coalesce(ow.email::text, '')::text AS owner_email, ow.disabled_at AS owner_disabled_at, + coalesce(ow.disabled_reason, '')::text AS owner_disabled_reason, coalesce(ow.is_admin, false)::boolean AS owner_is_admin, + ow.limit_orgs AS owner_limit_orgs, + coalesce(ow.owned, 0)::integer AS owner_orgs +FROM orgs o +LEFT JOIN LATERAL ( + SELECT u.id, u.email, u.disabled_at, u.disabled_reason, u.is_admin, u.limit_orgs, + (SELECT count(*) FROM memberships m2 WHERE m2.user_id = u.id AND m2.is_owner) AS owned + FROM memberships m JOIN users u ON u.id = m.user_id + WHERE m.org_id = o.id AND m.is_owner ORDER BY m.created_at LIMIT 1 +) ow ON true +WHERE sqlc.arg(search)::text = '' + OR o.name ILIKE '%' || sqlc.arg(search) || '%' OR o.slug::text ILIKE '%' || sqlc.arg(search) || '%' + OR coalesce(ow.email::text, '') ILIKE '%' || sqlc.arg(search) || '%' +ORDER BY o.created_at DESC +LIMIT sqlc.arg(max_rows); diff --git a/internal/store/users.sql.go b/internal/store/users.sql.go index 549cedc..c01aa50 100644 --- a/internal/store/users.sql.go +++ b/internal/store/users.sql.go @@ -24,7 +24,7 @@ func (q *Queries) AnyUserExists(ctx context.Context) (bool, error) { const createUser = `-- name: CreateUser :one INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4) -RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason +RETURNING id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs ` type CreateUserParams struct { @@ -55,6 +55,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e &i.Locale, &i.IsAdmin, &i.DisabledReason, + &i.LimitOrgs, ) return i, err } @@ -95,7 +96,7 @@ func (q *Queries) EnableTOTP(ctx context.Context, arg EnableTOTPParams) error { } const getUser = `-- name: GetUser :one -SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason FROM users WHERE id = $1 +SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs FROM users WHERE id = $1 ` func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) { @@ -114,12 +115,13 @@ func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) { &i.Locale, &i.IsAdmin, &i.DisabledReason, + &i.LimitOrgs, ) return i, err } const getUserByEmail = `-- name: GetUserByEmail :one -SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason FROM users WHERE email = $1 +SELECT id, email, display_name, password_hash, disabled_at, created_at, updated_at, totp_secret, totp_enabled_at, locale, is_admin, disabled_reason, limit_orgs FROM users WHERE email = $1 ` func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) { @@ -138,6 +140,7 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error &i.Locale, &i.IsAdmin, &i.DisabledReason, + &i.LimitOrgs, ) return i, err } diff --git a/internal/web/admin_orgs.templ b/internal/web/admin_orgs.templ new file mode 100644 index 0000000..e419e44 --- /dev/null +++ b/internal/web/admin_orgs.templ @@ -0,0 +1,221 @@ +package web + +import ( + "context" + "net/url" + "strconv" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// LimitsView holds limits; 0 means unlimited. +type LimitsView struct { + Monitors int + StatusPages int + RegionsPerMonitor int + OwnRegionsCount bool + OrgsPerAccount int +} + +// OrgsView lists organizations for platform admins. +type OrgsView struct { + Search string + Orgs []OrgRow + Limited bool + Defaults LimitsView +} + +// OrgRow is an organization with its usage and limits. Overrides are form +// values: empty follows the default. +type OrgRow struct { + ID, Name, Slug, Created, Suspended string + Monitors, StatusPages int + Limits LimitsView + MonitorsOverride string + StatusPagesOverride string + RegionsOverride string + OwnRegionsOverride string + Owner *ModeratedTarget + OwnerOrgs int + OwnerOrgLimit string +} + +func (v OrgsView) next() string { + if v.Search == "" { + return "/admin#orgs" + } + return "/admin?oq=" + url.QueryEscape(v.Search) + "#orgs" +} + +// limitText shows a limit, or "unlimited". +func limitText(ctx context.Context, n int) string { + if n == 0 { + return i18n.T(ctx, "limits.unlimited") + } + return strconv.Itoa(n) +} + +templ limitsSection(d LimitsView) { +
+ @sectionHeading("limits.title") +

{ i18n.T(ctx, "limits.intro") }

+
+ @formError() +
+ @numberField(i18n.T(ctx, "limits.monitors"), "monitors", d.Monitors, 0, 1000000, "") + @numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "") + @numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "") + @numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "") +
+ @checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount) +

{ i18n.T(ctx, "limits.own_regions_count_hint") }

+ +
+
+} + +// overrideField is a limit an organization may override: empty follows +// the default, shown as placeholder. +templ overrideField(label, name, value string, def int, max int) { + +} + +templ orgsSection(v OrgsView) { +
+ @sectionHeading("orgs.title") +

{ i18n.T(ctx, "orgs.intro") }

+
+ + +
+ if len(v.Orgs) == 0 { +

{ i18n.T(ctx, "orgs.none") }

+ } else { +
+ + + + + + + + + + + + for _, o := range v.Orgs { + + + + + + + + + + + } + +
{ i18n.T(ctx, "moderation.org") }{ i18n.T(ctx, "moderation.owner") }{ i18n.T(ctx, "limits.monitors") }{ i18n.T(ctx, "limits.status_pages") }{ i18n.T(ctx, "moderation.created") }
+ { o.Name } + { o.Slug } + @moderationState(o.Suspended, false) + + if o.Owner != nil { + { o.Owner.Name } + @moderationState(o.Owner.Suspended, false) + } else { + – + } + @usage(o.Monitors, o.Limits.Monitors)@usage(o.StatusPages, o.Limits.StatusPages){ o.Created }
+
+ { i18n.T(ctx, "orgs.manage") } +
+
+

{ i18n.T(ctx, "orgs.limits") }

+ @formError() + @overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000) + @overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000) + @overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000) + + +
+ @moderationActions("org", "/admin/orgs/"+o.ID, o.Suspended, o.Name, v.next()) + if o.Owner != nil && o.Owner.Admin { +

{ i18n.T(ctx, "moderation.owner_is_admin") }

+ } else if o.Owner != nil { +
+
+

{ i18n.T(ctx, "moderation.target_owner") }

+ @formError() + @overrideField(i18n.T(ctx, "orgs.owner_orgs", "Count", o.OwnerOrgs), "orgs", o.OwnerOrgLimit, v.Defaults.OrgsPerAccount, 100000) + +
+ @moderationActions("owner", "/admin/users/"+o.Owner.ID, o.Owner.Suspended, o.Owner.Name, v.next()) +
+ } +
+
+
+
+ if v.Limited { +

{ i18n.T(ctx, "moderation.limited") }

+ } + } +
+} + +// usage shows "used / limit", marking a reached limit. +templ usage(used, max int) { + 0 && used >= max) }>{ strconv.Itoa(used) } / { limitText(ctx, max) } +} + +// UsageView is an organization's usage of its limits. +type UsageView struct { + Limits LimitsView + Monitors, StatusPages int +} + +templ usageSection(u UsageView) { +
+ @sectionHeading("limits.org_title") +
+
{ i18n.T(ctx, "limits.monitors") }
+
@usage(u.Monitors, u.Limits.Monitors)
+
{ i18n.T(ctx, "limits.status_pages") }
+
@usage(u.StatusPages, u.Limits.StatusPages)
+
{ i18n.T(ctx, "limits.regions_per_monitor") }
+
{ limitText(ctx, u.Limits.RegionsPerMonitor) }
+
+ if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount { +

{ i18n.T(ctx, "limits.own_regions_free") }

+ } +
+} diff --git a/internal/web/admin_orgs_templ.go b/internal/web/admin_orgs_templ.go new file mode 100644 index 0000000..ac8b478 --- /dev/null +++ b/internal/web/admin_orgs_templ.go @@ -0,0 +1,1071 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.1118 + +package web + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "context" + "net/url" + "strconv" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// LimitsView holds limits; 0 means unlimited. +type LimitsView struct { + Monitors int + StatusPages int + RegionsPerMonitor int + OwnRegionsCount bool + OrgsPerAccount int +} + +// OrgsView lists organizations for platform admins. +type OrgsView struct { + Search string + Orgs []OrgRow + Limited bool + Defaults LimitsView +} + +// OrgRow is an organization with its usage and limits. Overrides are form +// values: empty follows the default. +type OrgRow struct { + ID, Name, Slug, Created, Suspended string + Monitors, StatusPages int + Limits LimitsView + MonitorsOverride string + StatusPagesOverride string + RegionsOverride string + OwnRegionsOverride string + Owner *ModeratedTarget + OwnerOrgs int + OwnerOrgLimit string +} + +func (v OrgsView) next() string { + if v.Search == "" { + return "/admin#orgs" + } + return "/admin?oq=" + url.QueryEscape(v.Search) + "#orgs" +} + +// limitText shows a limit, or "unlimited". +func limitText(ctx context.Context, n int) string { + if n == 0 { + return i18n.T(ctx, "limits.unlimited") + } + return strconv.Itoa(n) +} + +func limitsSection(d LimitsView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("limits.title").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var2 string + templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 61, Col: 66} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "limits.monitors"), "monitors", d.Monitors, 0, 1000000, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "limits.status_pages"), "status_pages", d.StatusPages, 0, 1000000, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", d.RegionsPerMonitor, 0, 1000, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = numberField(i18n.T(ctx, "limits.orgs_per_account"), "orgs_per_account", d.OrgsPerAccount, 0, 100000, "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "limits.own_regions_count"), "own_regions_count", d.OwnRegionsCount).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_count_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 71, Col: 89} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// overrideField is a limit an organization may override: empty follows +// the default, shown as placeholder. +func overrideField(label, name, value string, def int, max int) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func orgsSection(v OrgsView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("orgs.title").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var12 string + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 99, Col: 74} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(v.Orgs) == 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var17 string + templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.none")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 112, Col: 59} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, o := range v.Orgs { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var18 string + templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.org")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 118, Col: 72} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 119, Col: 74} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var20 string + templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 120, Col: 73} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var21 string + templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 121, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var22 string + templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.created")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 122, Col: 76} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var23 string + templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 129, Col: 17} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var24 string + templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(o.Slug) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 130, Col: 66} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = moderationState(o.Suspended, false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if o.Owner != nil { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var25 string + templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(o.Owner.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 135, Col: 48} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = moderationState(o.Owner.Suspended, false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "–") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = usage(o.Monitors, o.Limits.Monitors).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = usage(o.StatusPages, o.Limits.StatusPages).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(o.Created) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 143, Col: 72} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var27 string + templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.manage")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 148, Col: 96} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var30 string + templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "orgs.limits")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 151, Col: 113} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = overrideField(i18n.T(ctx, "limits.monitors"), "monitors", o.MonitorsOverride, v.Defaults.Monitors, 1000000).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = overrideField(i18n.T(ctx, "limits.status_pages"), "status_pages", o.StatusPagesOverride, v.Defaults.StatusPages, 1000000).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = overrideField(i18n.T(ctx, "limits.regions_per_monitor"), "regions_per_monitor", o.RegionsOverride, v.Defaults.RegionsPerMonitor, 1000).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = moderationActions("org", "/admin/orgs/"+o.ID, o.Suspended, o.Name, v.next()).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if o.Owner != nil && o.Owner.Admin { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var36 string + templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner_is_admin")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 168, Col: 84} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else if o.Owner != nil { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var39 string + templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.target_owner")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 172, Col: 127} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var39)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = overrideField(i18n.T(ctx, "orgs.owner_orgs", "Count", o.OwnerOrgs), "orgs", o.OwnerOrgLimit, v.Defaults.OrgsPerAccount, 100000).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = moderationActions("owner", "/admin/users/"+o.Owner.ID, o.Owner.Suspended, o.Owner.Name, v.next()).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if v.Limited { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var41 string + templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.limited")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 189, Col: 74} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var41)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// usage shows "used / limit", marking a reached limit. +func usage(used, max int) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + { + templ_7745c5c3_ElementWriter := templ_7745c5c3_Buffer + templ_7745c5c3_Buffer := templ.GetBuffer() + var templ_7745c5c3_ElementScripts []templ.ComponentScript + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, " 0 && used >= max)} + templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var43...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var44 string + templ_7745c5c3_Var44, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var43).String()).Resolve(ctx) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 1, Col: 0} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var44) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "\"") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_ElementScripts...) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_ElementWriter) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, ">") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var45 string + templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(used)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 197, Col: 83} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, " / ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var46 string + templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, max)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 197, Col: 109} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// UsageView is an organization's usage of its limits. +type UsageView struct { + Limits LimitsView + Monitors, StatusPages int +} + +func usageSection(u UsageView) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("limits.org_title").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var48 string + templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.monitors")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 210, Col: 39} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = usage(u.Monitors, u.Limits.Monitors).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var49 string + templ_7745c5c3_Var49, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.status_pages")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 212, Col: 43} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var49)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 80, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = usage(u.StatusPages, u.Limits.StatusPages).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 81, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var50 string + templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.regions_per_monitor")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 214, Col: 50} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var51 string + templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(limitText(ctx, u.Limits.RegionsPerMonitor)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 215, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if u.Limits.RegionsPerMonitor > 0 && !u.Limits.OwnRegionsCount { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var52 string + templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "limits.own_regions_free")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/admin_orgs.templ`, Line: 218, Col: 78} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 86, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js index 4a56816..73aeff9 100644 --- a/internal/web/assets/app.js +++ b/internal/web/assets/app.js @@ -55,7 +55,9 @@ continue; } if (el.type === "checkbox") set(el.name, el.checked); - else if (el.dataset.number !== undefined) set(el.name, Number(el.value)); + // [data-number][data-nullable] sends null when left empty. + else if (el.dataset.number !== undefined) + set(el.name, el.value === "" && el.dataset.nullable !== undefined ? null : Number(el.value)); else if (el.dataset.nullable !== undefined) set(el.name, el.value || null); else if (el.dataset.headers !== undefined) set(el.name, Object.fromEntries( diff --git a/internal/web/org.templ b/internal/web/org.templ index f93d018..23d86ac 100644 --- a/internal/web/org.templ +++ b/internal/web/org.templ @@ -390,6 +390,7 @@ type OrgSettings struct { // CheckTypes are the types the platform offers, enabled unless the // organization switched them off. CheckTypes []CheckTypeOption + Usage UsageView } templ OrgSettingsPage(p Page, me Me, v OrgSettings) { @@ -420,6 +421,7 @@ templ OrgSettingsPage(p Page, me Me, v OrgSettings) { @submit(i18n.T(ctx, "common.save")) + @usageSection(v.Usage) @checkTypesSection(v.CheckTypes, "/org/check-types", "/settings/org", "org.check_types_intro") @orgDataSection(me) } diff --git a/internal/web/org_templ.go b/internal/web/org_templ.go index 519f6b6..3a3a761 100644 --- a/internal/web/org_templ.go +++ b/internal/web/org_templ.go @@ -1634,6 +1634,7 @@ type OrgSettings struct { // CheckTypes are the types the platform offers, enabled unless the // organization switched them off. CheckTypes []CheckTypeOption + Usage UsageView } func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { @@ -1696,7 +1697,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var76 string templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.require_totp_hint")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 403, Col: 82} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 404, Col: 82} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76)) if templ_7745c5c3_Err != nil { @@ -1717,7 +1718,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var77 string templ_7745c5c3_Var77, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.require_sso_hint")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 405, Col: 81} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 406, Col: 81} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var77)) if templ_7745c5c3_Err != nil { @@ -1730,7 +1731,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var78 string templ_7745c5c3_Var78, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.token_max_days")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 407, Col: 121} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 408, Col: 121} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var78)) if templ_7745c5c3_Err != nil { @@ -1743,7 +1744,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var79 string templ_7745c5c3_Var79, templ_7745c5c3_Err = templruntime.NewAttributeExpression(maxDaysValue(v.TokenMaxDays)).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 414, Col: 42} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 415, Col: 42} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var79) if templ_7745c5c3_Err != nil { @@ -1756,7 +1757,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var80 string templ_7745c5c3_Var80, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "org.token_max_days_none")).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 415, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 416, Col: 58} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var80) if templ_7745c5c3_Err != nil { @@ -1769,7 +1770,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { var templ_7745c5c3_Var81 string templ_7745c5c3_Var81, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.token_max_days_hint")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 419, Col: 79} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 420, Col: 79} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var81)) if templ_7745c5c3_Err != nil { @@ -1787,6 +1788,10 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = usageSection(v.Usage).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } templ_7745c5c3_Err = checkTypesSection(v.CheckTypes, "/org/check-types", "/settings/org", "org.check_types_intro").Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -1853,7 +1858,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var84 string templ_7745c5c3_Var84, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.invitation_invalid")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 442, Col: 63} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 444, Col: 63} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var84)) if templ_7745c5c3_Err != nil { @@ -1871,7 +1876,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var85 string templ_7745c5c3_Var85, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "invite.summary", "Org", v.OrgName, "Role", v.RoleName)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 444, Col: 96} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 446, Col: 96} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var85)) if templ_7745c5c3_Err != nil { @@ -1884,7 +1889,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var86 string templ_7745c5c3_Var86, templ_7745c5c3_Err = templ.JoinStringErrs(v.Email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 445, Col: 46} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 447, Col: 46} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var86)) if templ_7745c5c3_Err != nil { @@ -1903,7 +1908,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var87 string templ_7745c5c3_Var87, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/invitations/" + v.Token + "/accept").Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 448, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 450, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var87) if templ_7745c5c3_Err != nil { @@ -1933,7 +1938,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var88 string templ_7745c5c3_Var88, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.invitation_email_mismatch")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 453, Col: 82} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 455, Col: 82} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var88)) if templ_7745c5c3_Err != nil { @@ -1946,7 +1951,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var89 string templ_7745c5c3_Var89, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.logout")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 454, Col: 110} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 456, Col: 110} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var89)) if templ_7745c5c3_Err != nil { @@ -1964,7 +1969,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var90 string templ_7745c5c3_Var90, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL("/login?next=/invite/" + v.Token)).ResolveURL(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 456, Col: 62} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 458, Col: 62} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var90) if templ_7745c5c3_Err != nil { @@ -1977,7 +1982,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var91 string templ_7745c5c3_Var91, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "invite.sign_in")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 456, Col: 153} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 458, Col: 153} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var91)) if templ_7745c5c3_Err != nil { @@ -1995,7 +2000,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { var templ_7745c5c3_Var92 string templ_7745c5c3_Var92, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/invitations/" + v.Token + "/signup").Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 458, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 460, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var92) if templ_7745c5c3_Err != nil { @@ -2069,7 +2074,7 @@ func tokenUsage() templ.Component { var templ_7745c5c3_Var94 string templ_7745c5c3_Var94, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.usage")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 479, Col: 31} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 481, Col: 31} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var94)) if templ_7745c5c3_Err != nil { @@ -2082,7 +2087,7 @@ func tokenUsage() templ.Component { var templ_7745c5c3_Var95 string templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "apidocs.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 482, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 484, Col: 98} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var95)) if templ_7745c5c3_Err != nil { diff --git a/internal/web/regions.templ b/internal/web/regions.templ index e44f7b9..36f6b2d 100644 --- a/internal/web/regions.templ +++ b/internal/web/regions.templ @@ -163,7 +163,7 @@ templ RegionsPage(p Page, me Me, v RegionsView) { } } -templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption, platformPrivate bool, mod ModerationView) { +templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption, platformPrivate bool, mod ModerationView, orgs OrgsView) { @consoleShell(p, me) { @settingsHeading("admin.title", "admin.intro")

@@ -171,6 +171,8 @@ templ AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes [] { i18n.T(ctx, "legal.platform_title") }

@moderationSection(mod) + @orgsSection(orgs) + @limitsSection(orgs.Defaults) @regionsBody(v) @checkerNetworkSection(platformPrivate) @checkTypesSection(checkTypes, "/admin/check-types", "/admin", "admin.check_types_intro") diff --git a/internal/web/regions_templ.go b/internal/web/regions_templ.go index 3a66ad4..92467d8 100644 --- a/internal/web/regions_templ.go +++ b/internal/web/regions_templ.go @@ -772,7 +772,7 @@ func RegionsPage(p Page, me Me, v RegionsView) templ.Component { }) } -func AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption, platformPrivate bool, mod ModerationView) templ.Component { +func AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []CheckTypeOption, platformPrivate bool, mod ModerationView, orgs OrgsView) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -839,6 +839,14 @@ func AdminPage(p Page, me Me, v RegionsView, storage StorageView, checkTypes []C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } + templ_7745c5c3_Err = orgsSection(orgs).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = limitsSection(orgs.Defaults).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } templ_7745c5c3_Err = regionsBody(v).Render(ctx, templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err @@ -915,7 +923,7 @@ func checkerNetworkSection(allow bool) templ.Component { var templ_7745c5c3_Var45 string templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.platform_private_hint")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 193, Col: 87} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 195, Col: 87} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var45)) if templ_7745c5c3_Err != nil { @@ -928,7 +936,7 @@ func checkerNetworkSection(allow bool) templ.Component { var templ_7745c5c3_Var46 string templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 194, Col: 129} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 196, Col: 129} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46)) if templ_7745c5c3_Err != nil { @@ -976,7 +984,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var48 string templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, introID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 204, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 206, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48)) if templ_7745c5c3_Err != nil { @@ -989,7 +997,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var49 string templ_7745c5c3_Var49, templ_7745c5c3_Err = templruntime.NewAttributeExpression(api).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 205, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 207, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var49) if templ_7745c5c3_Err != nil { @@ -1002,7 +1010,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var50 string templ_7745c5c3_Var50, templ_7745c5c3_Err = templruntime.NewAttributeExpression(next).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 205, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 207, Col: 59} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var50) if templ_7745c5c3_Err != nil { @@ -1028,7 +1036,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var51 string templ_7745c5c3_Var51, templ_7745c5c3_Err = templruntime.NewAttributeExpression(t.Type).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 210, Col: 58} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 212, Col: 58} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var51) if templ_7745c5c3_Err != nil { @@ -1051,7 +1059,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var52 string templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "monitors.type_"+t.Type)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 211, Col: 44} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 213, Col: 44} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52)) if templ_7745c5c3_Err != nil { @@ -1069,7 +1077,7 @@ func checkTypesSection(types []CheckTypeOption, api, next, introID string) templ var templ_7745c5c3_Var53 string templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.save")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 215, Col: 129} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 217, Col: 129} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53)) if templ_7745c5c3_Err != nil { @@ -1148,7 +1156,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var55 string templ_7745c5c3_Var55, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.intro")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 256, Col: 80} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 258, Col: 80} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var55)) if templ_7745c5c3_Err != nil { @@ -1161,7 +1169,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var56 string templ_7745c5c3_Var56, templ_7745c5c3_Err = templruntime.NewAttributeExpression(v.Search).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 261, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 263, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var56) if templ_7745c5c3_Err != nil { @@ -1174,7 +1182,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var57 string templ_7745c5c3_Var57, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "moderation.search")).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 262, Col: 50} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 264, Col: 50} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var57) if templ_7745c5c3_Err != nil { @@ -1187,7 +1195,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var58 string templ_7745c5c3_Var58, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "moderation.search")).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 263, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 265, Col: 49} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var58) if templ_7745c5c3_Err != nil { @@ -1200,7 +1208,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var59 string templ_7745c5c3_Var59, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.search_button")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 266, Col: 142} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 268, Col: 142} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var59)) if templ_7745c5c3_Err != nil { @@ -1218,7 +1226,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var60 string templ_7745c5c3_Var60, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.none")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 269, Col: 65} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 271, Col: 65} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var60)) if templ_7745c5c3_Err != nil { @@ -1236,7 +1244,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var61 string templ_7745c5c3_Var61, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.page")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 275, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 277, Col: 73} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var61)) if templ_7745c5c3_Err != nil { @@ -1249,7 +1257,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var62 string templ_7745c5c3_Var62, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.org")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 276, Col: 72} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 278, Col: 72} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var62)) if templ_7745c5c3_Err != nil { @@ -1262,7 +1270,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var63 string templ_7745c5c3_Var63, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 277, Col: 74} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 279, Col: 74} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var63)) if templ_7745c5c3_Err != nil { @@ -1275,7 +1283,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var64 string templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.created")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 278, Col: 76} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 280, Col: 76} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64)) if templ_7745c5c3_Err != nil { @@ -1293,7 +1301,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var65 string templ_7745c5c3_Var65, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(pg.URL)).ResolveURL(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 285, Col: 40} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 287, Col: 40} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var65) if templ_7745c5c3_Err != nil { @@ -1306,7 +1314,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var66 string templ_7745c5c3_Var66, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 285, Col: 119} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 287, Col: 119} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var66)) if templ_7745c5c3_Err != nil { @@ -1319,7 +1327,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var67 string templ_7745c5c3_Var67, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Slug) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 286, Col: 67} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 288, Col: 67} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var67)) if templ_7745c5c3_Err != nil { @@ -1340,7 +1348,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var68 string templ_7745c5c3_Var68, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Org.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 290, Col: 22} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 292, Col: 22} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68)) if templ_7745c5c3_Err != nil { @@ -1353,7 +1361,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var69 string templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Org.Detail) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 291, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 293, Col: 73} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69)) if templ_7745c5c3_Err != nil { @@ -1379,7 +1387,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var70 string templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Owner.Name) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 296, Col: 49} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 298, Col: 49} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) if templ_7745c5c3_Err != nil { @@ -1406,7 +1414,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var71 string templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(pg.Created) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 302, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 304, Col: 73} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71)) if templ_7745c5c3_Err != nil { @@ -1419,7 +1427,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var72 string templ_7745c5c3_Var72, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.actions")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 307, Col: 103} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 309, Col: 103} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var72)) if templ_7745c5c3_Err != nil { @@ -1445,7 +1453,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var73 string templ_7745c5c3_Var73, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.owner_is_admin")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 312, Col: 84} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 314, Col: 84} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73)) if templ_7745c5c3_Err != nil { @@ -1478,7 +1486,7 @@ func moderationSection(v ModerationView) templ.Component { var templ_7745c5c3_Var74 string templ_7745c5c3_Var74, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.limited")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 325, Col: 74} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 327, Col: 74} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var74)) if templ_7745c5c3_Err != nil { @@ -1523,7 +1531,7 @@ func moderationState(suspended string, draft bool) templ.Component { var templ_7745c5c3_Var76 string templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.suspended")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 334, Col: 40} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 336, Col: 40} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76)) if templ_7745c5c3_Err != nil { @@ -1541,7 +1549,7 @@ func moderationState(suspended string, draft bool) templ.Component { var templ_7745c5c3_Var77 string templ_7745c5c3_Var77, templ_7745c5c3_Err = templ.JoinStringErrs("· " + suspended) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 336, Col: 60} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 338, Col: 60} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var77)) if templ_7745c5c3_Err != nil { @@ -1564,7 +1572,7 @@ func moderationState(suspended string, draft bool) templ.Component { var templ_7745c5c3_Var78 string templ_7745c5c3_Var78, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "pages.draft")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 340, Col: 81} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 342, Col: 81} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var78)) if templ_7745c5c3_Err != nil { @@ -1605,7 +1613,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var80 string templ_7745c5c3_Var80, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.target_"+kind)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 348, Col: 115} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 350, Col: 115} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var80)) if templ_7745c5c3_Err != nil { @@ -1618,7 +1626,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var81 string templ_7745c5c3_Var81, templ_7745c5c3_Err = templruntime.NewAttributeExpression(api + "/suspension").Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 349, Col: 38} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 351, Col: 38} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var81) if templ_7745c5c3_Err != nil { @@ -1631,7 +1639,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var82 string templ_7745c5c3_Var82, templ_7745c5c3_Err = templruntime.NewAttributeExpression(next).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 349, Col: 75} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 351, Col: 75} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var82) if templ_7745c5c3_Err != nil { @@ -1653,7 +1661,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var83 string templ_7745c5c3_Var83, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.reinstate")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 353, Col: 119} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 355, Col: 119} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var83)) if templ_7745c5c3_Err != nil { @@ -1671,7 +1679,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var84 string templ_7745c5c3_Var84, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "moderation.reason")).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 359, Col: 51} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 361, Col: 51} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var84) if templ_7745c5c3_Err != nil { @@ -1684,7 +1692,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var85 string templ_7745c5c3_Var85, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "moderation.reason")).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 360, Col: 50} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 362, Col: 50} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var85) if templ_7745c5c3_Err != nil { @@ -1697,7 +1705,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var86 string templ_7745c5c3_Var86, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.suspend")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 363, Col: 141} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 365, Col: 141} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var86)) if templ_7745c5c3_Err != nil { @@ -1715,7 +1723,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var87 string templ_7745c5c3_Var87, templ_7745c5c3_Err = templruntime.NewAttributeExpression(api).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 368, Col: 20} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 370, Col: 20} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var87) if templ_7745c5c3_Err != nil { @@ -1728,7 +1736,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var88 string templ_7745c5c3_Var88, templ_7745c5c3_Err = templruntime.NewAttributeExpression(next).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 369, Col: 19} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 371, Col: 19} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var88) if templ_7745c5c3_Err != nil { @@ -1741,7 +1749,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var89 string templ_7745c5c3_Var89, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "moderation.delete_confirm_"+kind, "Name", name)).Resolve(ctx) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 370, Col: 78} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 372, Col: 78} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var89) if templ_7745c5c3_Err != nil { @@ -1754,7 +1762,7 @@ func moderationActions(kind, api, suspended, name, next string) templ.Component var templ_7745c5c3_Var90 string templ_7745c5c3_Var90, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "moderation.delete_"+kind)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 372, Col: 43} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 374, Col: 43} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var90)) if templ_7745c5c3_Err != nil { diff --git a/internal/web/testdata/forms.html b/internal/web/testdata/forms.html index 60dccad..c479291 100644 --- a/internal/web/testdata/forms.html +++ b/internal/web/testdata/forms.html @@ -58,6 +58,11 @@ X-Empty: +
+ + + +