diff --git a/internal/api/members.go b/internal/api/members.go index 685cf89..acb6985 100644 --- a/internal/api/members.go +++ b/internal/api/members.go @@ -429,6 +429,9 @@ func (s *Server) roleResult(c *gin.Context, err error, code string, ok func()) { type policyRequest struct { RequireTOTP bool `json:"require_totp"` RequireSSO bool `json:"require_sso"` + // APITokenMaxDays limits how long API tokens stay valid; 0 or null + // means no limit. + APITokenMaxDays *int `json:"api_token_max_days" binding:"omitempty,min=0,max=3650"` } func (s *Server) updatePolicy(c *gin.Context) { @@ -457,8 +460,18 @@ func (s *Server) updatePolicy(c *gin.Context) { return errNoSSOProvider } } + var maxDays *int32 + if req.APITokenMaxDays != nil && *req.APITokenMaxDays > 0 { + maxDays = ptr(int32(*req.APITokenMaxDays)) + } var err error - org, err = q.UpdateOrgPolicy(ctx, store.UpdateOrgPolicyParams{ID: p.Org.ID, RequireTotp: req.RequireTOTP, RequireSso: req.RequireSSO}) + org, err = q.UpdateOrgPolicy(ctx, store.UpdateOrgPolicyParams{ + ID: p.Org.ID, RequireTotp: req.RequireTOTP, RequireSso: req.RequireSSO, ApiTokenMaxDays: maxDays, + }) + if err != nil || maxDays == nil { + return err + } + _, err = q.ClampAPITokenExpiry(ctx, store.ClampAPITokenExpiryParams{OrgID: p.Org.ID, MaxDays: *maxDays}) return err }) if errors.Is(err, errNoSSOProvider) { @@ -469,7 +482,7 @@ func (s *Server) updatePolicy(c *gin.Context) { internalError(c, err) return } - c.JSON(http.StatusOK, gin.H{"require_totp": org.RequireTotp, "require_sso": org.RequireSso}) + c.JSON(http.StatusOK, gin.H{"require_totp": org.RequireTotp, "require_sso": org.RequireSso, "api_token_max_days": org.ApiTokenMaxDays}) } var errNoSSOProvider = errors.New("api: no enabled sso provider") diff --git a/internal/api/pages.go b/internal/api/pages.go index 291a2dc..a317e69 100644 --- a/internal/api/pages.go +++ b/internal/api/pages.go @@ -2,6 +2,7 @@ package api import ( "net/http" + "slices" "strings" "time" @@ -268,7 +269,11 @@ func (s *Server) ssoSettingsView(c *gin.Context, p *principal, page web.Page, me } func (s *Server) orgSettingsView(_ *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { - return web.OrgSettingsPage(page, me, web.OrgSettings{RequireTOTP: p.Org.RequireTotp, RequireSSO: p.Org.RequireSso}), nil + v := web.OrgSettings{RequireTOTP: p.Org.RequireTotp, RequireSSO: p.Org.RequireSso} + if p.Org.ApiTokenMaxDays != nil { + v.TokenMaxDays = int(*p.Org.ApiTokenMaxDays) + } + return web.OrgSettingsPage(page, me, v), nil } func (s *Server) membersView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { @@ -337,7 +342,7 @@ func (s *Server) rolesView(c *gin.Context, p *principal, page web.Page, me web.M func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) { ctx := c.Request.Context() - showAll := p.Grants.Can(authz.MembersManage) + showAll := p.Grants.Can(authz.TokensManage) var filter *uuid.UUID if !showAll { filter = &p.UserID @@ -351,10 +356,17 @@ func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web. if err != nil { return nil, err } - v := web.TokensView{Grantable: grantable(p), ShowOwner: showAll} + v := web.TokensView{Grantable: grantable(p), ShowOwner: showAll, ExpiryDays: expiryChoices(p.Org.ApiTokenMaxDays)} + if p.Org.ApiTokenMaxDays != nil { + v.MaxDays = int(*p.Org.ApiTokenMaxDays) + } never := i18n.T(ctx, "tokens.never") for _, r := range rows { - t := web.Token{ID: r.ID.String(), Name: r.Name, Prefix: r.Prefix, UserEmail: r.UserEmail, Permissions: r.Permissions, ExpiresAt: never, LastUsedAt: "–"} + t := web.Token{ + ID: r.ID.String(), Name: r.Name, Prefix: r.Prefix, UserEmail: r.UserEmail, + Permissions: authz.NewSet(r.Permissions...).Strings(), CreatedAt: r.CreatedAt.Format(time.DateOnly), + ExpiresAt: never, LastUsedAt: "–", + } if r.ExpiresAt != nil { t.ExpiresAt = r.ExpiresAt.Format(time.DateOnly) } @@ -366,6 +378,26 @@ func (s *Server) tokensView(c *gin.Context, p *principal, page web.Page, me web. return web.TokensPage(page, me, v), nil } +// expiryChoices returns the token lifetimes to offer, in days, honoring the +// org's limit. 0 stands for no expiry and is only offered without a limit. +func expiryChoices(limit *int32) []int { + defaults := []int{90, 30, 365, 0} + if limit == nil { + return defaults + } + max := int(*limit) + var out []int + for _, d := range defaults { + if d > 0 && d <= max { + out = append(out, d) + } + } + if !slices.Contains(out, max) { + out = append(out, max) + } + return out +} + func toWebMe(m meView) web.Me { out := web.Me{ Email: m.Email, diff --git a/internal/api/permissions_test.go b/internal/api/permissions_test.go index 1ab8964..8262ab1 100644 --- a/internal/api/permissions_test.go +++ b/internal/api/permissions_test.go @@ -209,3 +209,68 @@ func TestPermissions(t *testing.T) { } }) } + +func TestTokenOversightAndLifetimePolicy(t *testing.T) { + e := newEnv(t) + domain := uniq("t") + ".test" + owner := e.browser(t) + owner.signup("owner@"+domain, uniq("tok-")) + editor := e.joinVia(t, owner.invite("editor@"+domain, owner.roleID("editor"))) + + st, body := editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "forever", "permissions": []string{"monitors.read"}}) + expect(t, "editor creates non-expiring token", st, body, http.StatusCreated, "") + editorTokenID := body["id"].(string) + api := &browser{t: t, base: editor.base, hc: e.srv.Client(), bearer: body["token"].(string)} + owner.do("POST", "/api/v1/org/tokens", map[string]any{"name": "own", "permissions": []string{"monitors.read"}}) + + tokenNames := func(b *browser) []string { + _, body := b.do("GET", "/api/v1/org/tokens", nil) + var names []string + for _, tk := range body["tokens"].([]any) { + names = append(names, tk.(map[string]any)["name"].(string)) + } + return names + } + if got := tokenNames(owner); len(got) != 2 { + t.Errorf("owner sees tokens %v, want both", got) + } + if got := tokenNames(editor); len(got) != 1 || got[0] != "forever" { + t.Errorf("editor sees tokens %v, want only own", got) + } + + st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"api_token_max_days": 30}) + expect(t, "set lifetime policy", st, body, http.StatusOK, "") + _, list := owner.do("GET", "/api/v1/org/tokens", nil) + for _, tk := range list["tokens"].([]any) { + tk := tk.(map[string]any) + exp, _ := time.Parse(time.RFC3339Nano, fmtString(tk["expires_at"])) + if exp.IsZero() || exp.After(time.Now().Add(31*24*time.Hour)) { + t.Errorf("token %v expires_at = %v, want within 30 days", tk["name"], tk["expires_at"]) + } + } + + for _, days := range []int{0, 31} { + st, body = editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "x", "permissions": []string{"monitors.read"}, "expires_in_days": days}) + expect(t, "token beyond policy", st, body, http.StatusUnprocessableEntity, "token_lifetime_exceeds_policy") + } + st, body = editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "ok", "permissions": []string{"monitors.read"}, "expires_in_days": 30}) + expect(t, "token within policy", st, body, http.StatusCreated, "") + + st, body = owner.do("DELETE", "/api/v1/org/tokens/"+editorTokenID, nil) + expect(t, "owner revokes editor token", st, body, http.StatusNoContent, "") + st, body = api.do("GET", "/api/v1/org/tokens", nil) + expect(t, "revoked token", st, body, http.StatusUnauthorized, "unauthenticated") + + st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"api_token_max_days": 0}) + if st != http.StatusOK || body["api_token_max_days"] != nil { + t.Errorf("clear lifetime policy = %d %v, want 200 with null", st, body) + } + if got := owner.visit("/settings/tokens"); got.Path != "/settings/tokens" { + t.Errorf("tokens page ended at %s", got) + } +} + +func fmtString(v any) string { + s, _ := v.(string) + return s +} diff --git a/internal/api/tokens.go b/internal/api/tokens.go index d4bc51b..9b7efa0 100644 --- a/internal/api/tokens.go +++ b/internal/api/tokens.go @@ -98,10 +98,10 @@ type tokenView struct { func (s *Server) listTokens(c *gin.Context) { p := current(c) ctx := c.Request.Context() - // Members see their own tokens; members.manage reveals everyone's so - // tokens of departing staff can be revoked. + // Members see their own tokens; tokens.manage reveals everyone's so the + // owner can audit and revoke them. var filter *uuid.UUID - if !p.Grants.Can(authz.MembersManage) { + if !p.Grants.Can(authz.TokensManage) { filter = &p.UserID } var rows []store.ListAPITokensRow @@ -127,7 +127,8 @@ func (s *Server) listTokens(c *gin.Context) { type createTokenRequest struct { Name string `json:"name" binding:"required,max=100"` Permissions []string `json:"permissions" binding:"required,min=1,max=50,dive,max=50"` - // ExpiresInDays of 0 creates a token that does not expire. + // ExpiresInDays of 0 creates a token that does not expire, unless the + // org limits token lifetime. ExpiresInDays int `json:"expires_in_days" binding:"min=0,max=3650"` } @@ -146,6 +147,10 @@ func (s *Server) createToken(c *gin.Context) { fail(c, http.StatusForbidden, "permission_escalation") return } + if limit := p.Org.ApiTokenMaxDays; limit != nil && (req.ExpiresInDays == 0 || req.ExpiresInDays > int(*limit)) { + fail(c, http.StatusUnprocessableEntity, "token_lifetime_exceeds_policy", "Count", int(*limit)) + return + } var expires *time.Time if req.ExpiresInDays > 0 { t := time.Now().AddDate(0, 0, req.ExpiresInDays) @@ -187,7 +192,7 @@ func (s *Server) deleteToken(c *gin.Context) { if err != nil { return err } - if row.UserID != p.UserID && !p.Grants.Can(authz.MembersManage) { + if row.UserID != p.UserID && !p.Grants.Can(authz.TokensManage) { return nil } found = true diff --git a/internal/i18n/i18n_test.go b/internal/i18n/i18n_test.go index 419cb84..16a932c 100644 --- a/internal/i18n/i18n_test.go +++ b/internal/i18n/i18n_test.go @@ -183,6 +183,9 @@ func TestT(t *testing.T) { t.Errorf("T(de, recovery.left, %d) = %q, want %q", n, got, want) } } + if got, want := T(ctx, "error.token_lifetime_exceeds_policy", "Count", 30), "Tokens in dieser Organisation müssen innerhalb von 30 Tagen ablaufen."; got != want { + t.Errorf("T(de, token_lifetime_exceeds_policy, 30) = %q, want %q", got, want) + } if got, want := T(ctx, "no.such.key"), "no.such.key"; got != want { t.Errorf("T(missing) = %q, want %q", got, want) } diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index 16c5876..f610030 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -76,6 +76,10 @@ "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.token_lifetime_exceeds_policy": { + "one": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tag ablaufen.", + "other": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tagen ablaufen." + }, "error.totp_already_enabled": "TOTP ist bereits aktiv.", "error.totp_required_by_org": "Eine deiner Organisationen verlangt TOTP.", "error.totp_setup_expired": "Einrichtung abgelaufen, bitte neu starten.", @@ -108,6 +112,9 @@ "org.require_totp": "Zwei-Faktor-Anmeldung verlangen", "org.require_totp_hint": "Mitglieder, die sich mit Passwort anmelden, brauchen TOTP. Bei SSO-Anmeldungen ist die MFA des Identity Providers zuständig.", "org.title": "Organisation", + "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", "perm.incidents.read": "Incidents sehen", "perm.incidents.write": "Incidents verwalten", "perm.members.manage": "Mitglieder einladen und verwalten", @@ -120,6 +127,7 @@ "perm.roles.manage": "Eigene Rollen verwalten", "perm.statuspages.read": "Statuspages sehen", "perm.statuspages.write": "Statuspages bearbeiten", + "perm.tokens.manage": "Alle API-Tokens sehen und widerrufen", "roles.built_in": "eingebaut", "roles.create": "Rolle anlegen", "roles.delete": "Rolle löschen", @@ -171,15 +179,22 @@ "sso.settings.title": "Single Sign-on", "tokens.copy_now": "Kopiere den Token jetzt. Er wird nicht erneut angezeigt.", "tokens.create": "Token erstellen", + "tokens.created": "Erstellt", "tokens.days": { "one": "{{.Count}} Tag", "other": "{{.Count}} Tage" }, "tokens.expires": "Läuft ab", "tokens.intro": "Tokens handeln in deinem Namen in dieser Organisation. Sie haben nie mehr Rechte als du selbst, auch wenn deine Rechte später schrumpfen.", + "tokens.intro_all": "Du siehst alle API-Tokens dieser Organisation und kannst jeden davon widerrufen. Tokens haben nie mehr Rechte als ihr Inhaber.", "tokens.last_used": "Zuletzt genutzt", "tokens.never": "nie", "tokens.owner": "Inhaber", + "tokens.permissions": "Berechtigungen", + "tokens.policy": { + "one": "Diese Organisation begrenzt API-Tokens auf {{.Count}} Tag.", + "other": "Diese Organisation begrenzt API-Tokens auf {{.Count}} Tage." + }, "tokens.revoke_confirm": "Diesen Token widerrufen? Anfragen damit schlagen sofort fehl.", "tokens.title": "API-Tokens" } diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index 3c38f82..19b7654 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -76,6 +76,10 @@ "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.token_lifetime_exceeds_policy": { + "one": "Tokens in this organization must expire within {{.Count}} day.", + "other": "Tokens in this organization must expire within {{.Count}} days." + }, "error.totp_already_enabled": "TOTP is already active.", "error.totp_required_by_org": "One of your organizations requires TOTP.", "error.totp_setup_expired": "Setup expired, please start again.", @@ -108,6 +112,9 @@ "org.require_totp": "Require two-factor sign-in", "org.require_totp_hint": "Members signing in with a password need TOTP. SSO sign-ins rely on the identity provider's MFA.", "org.title": "Organization", + "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", "perm.incidents.read": "View incidents", "perm.incidents.write": "Manage incidents", "perm.members.manage": "Invite and manage members", @@ -120,6 +127,7 @@ "perm.roles.manage": "Manage custom roles", "perm.statuspages.read": "View status pages", "perm.statuspages.write": "Edit status pages", + "perm.tokens.manage": "View and revoke all API tokens", "roles.built_in": "built-in", "roles.create": "Create role", "roles.delete": "Delete role", @@ -171,15 +179,22 @@ "sso.settings.title": "Single sign-on", "tokens.copy_now": "Copy the token now. It will not be shown again.", "tokens.create": "Create token", + "tokens.created": "Created", "tokens.days": { "one": "{{.Count}} day", "other": "{{.Count}} days" }, "tokens.expires": "Expires", "tokens.intro": "Tokens act on your behalf in this organization. They never exceed your own permissions, even if those shrink later.", + "tokens.intro_all": "You see every API token in this organization and can revoke any of them. Tokens never exceed their owner's permissions.", "tokens.last_used": "Last used", "tokens.never": "never", "tokens.owner": "Owner", + "tokens.permissions": "Permissions", + "tokens.policy": { + "one": "This organization limits API tokens to {{.Count}} day.", + "other": "This organization limits API tokens to {{.Count}} days." + }, "tokens.revoke_confirm": "Revoke this token? Requests using it fail immediately.", "tokens.title": "API tokens" } diff --git a/internal/web/org.templ b/internal/web/org.templ index 83de210..3a975f4 100644 --- a/internal/web/org.templ +++ b/internal/web/org.templ @@ -2,6 +2,7 @@ package web import ( "slices" + "strconv" "git.zb-server.de/ZB-Server/uptimesebi/internal/auth" "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" @@ -257,6 +258,7 @@ type Token struct { Prefix string UserEmail string Permissions []string + CreatedAt string ExpiresAt string LastUsedAt string } @@ -265,12 +267,25 @@ type Token struct { type TokensView struct { Tokens []Token Grantable []string + // ShowOwner is set when the viewer oversees all tokens of the org. ShowOwner bool + // MaxDays is the org's token lifetime limit, 0 if none. + MaxDays int + // ExpiryDays are the lifetimes offered when creating a token; 0 means + // no expiry. + ExpiryDays []int } templ TokensPage(p Page, me Me, v TokensView) { @consoleShell(p, me) { - @settingsHeading("tokens.title", "tokens.intro") + if v.ShowOwner { + @settingsHeading("tokens.title", "tokens.intro_all") + } else { + @settingsHeading("tokens.title", "tokens.intro") + } + if v.MaxDays > 0 { +

{ i18n.T(ctx, "tokens.policy", "Count", v.MaxDays) }

+ } if len(v.Tokens) > 0 { @@ -279,6 +294,8 @@ templ TokensPage(p Page, me Me, v TokensView) { if v.ShowOwner { } + + @@ -286,13 +303,21 @@ templ TokensPage(p Page, me Me, v TokensView) { for _, t := range v.Tokens { - + if v.ShowOwner { } - - + + + +
{ i18n.T(ctx, "tokens.owner") }{ i18n.T(ctx, "tokens.permissions") }{ i18n.T(ctx, "tokens.created") } { i18n.T(ctx, "tokens.expires") } { i18n.T(ctx, "tokens.last_used") }
{ t.Name } { t.Prefix }…{ t.UserEmail }{ t.ExpiresAt }{ t.LastUsedAt } +
    + for _, perm := range t.Permissions { +
  • { i18n.T(ctx, "perm."+perm) }
  • + } +
+
{ t.CreatedAt }{ t.ExpiresAt }{ t.LastUsedAt }
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1304,7 +1408,7 @@ func TokensPage(p Page, me Me, v TokensView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 111, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1320,72 +1424,86 @@ func TokensPage(p Page, me Me, v TokensView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 112, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1393,20 +1511,20 @@ func TokensPage(p Page, me Me, v TokensView) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 133, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1424,6 +1542,8 @@ func TokensPage(p Page, me Me, v TokensView) templ.Component { type OrgSettings struct { RequireTOTP bool RequireSSO bool + // TokenMaxDays is 0 when API token lifetime is unlimited. + TokenMaxDays int } func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { @@ -1443,7 +1563,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var67 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var71 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -1459,7 +1579,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1467,7 +1587,7 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1479,20 +1599,20 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 122, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var68 string - templ_7745c5c3_Var68, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.require_totp_hint")) + var templ_7745c5c3_Var72 string + templ_7745c5c3_Var72, 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: 348, Col: 82} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 378, Col: 82} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var72)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 137, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1500,20 +1620,72 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 124, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var69 string - templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "org.require_sso_hint")) + var templ_7745c5c3_Var73 string + templ_7745c5c3_Var73, 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: 350, Col: 81} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 380, Col: 81} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 125, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 139, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var77 string + templ_7745c5c3_Var77, 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: 394, Col: 79} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var77)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1521,13 +1693,13 @@ func OrgSettingsPage(p Page, me Me, v OrgSettings) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 126, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 144, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var67), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var71), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1563,7 +1735,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var71 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var79 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { @@ -1576,70 +1748,70 @@ func InvitationPage(p Page, v Invitation) templ.Component { } ctx = templ.InitializeContext(ctx) if !v.Valid { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 145, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var72 string - templ_7745c5c3_Var72, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.invitation_invalid")) + var templ_7745c5c3_Var80 string + templ_7745c5c3_Var80, 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: 371, Col: 63} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 415, Col: 63} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var72)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var80)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 128, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 146, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 129, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 147, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var73 string - templ_7745c5c3_Var73, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "invite.summary", "Org", v.OrgName, "Role", v.RoleName)) + var templ_7745c5c3_Var81 string + templ_7745c5c3_Var81, 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: 373, Col: 96} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 417, Col: 96} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var81)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 130, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var74 string - templ_7745c5c3_Var74, templ_7745c5c3_Err = templ.JoinStringErrs(v.Email) + var templ_7745c5c3_Var82 string + templ_7745c5c3_Var82, 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: 374, Col: 46} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 418, Col: 46} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var74)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var82)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } switch { case v.SignedInAs == v.Email: - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "\" data-next=\"/\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1651,87 +1823,87 @@ func InvitationPage(p Page, v Invitation) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 152, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } case v.SignedInAs != "": - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var76 string - templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "error.invitation_email_mismatch")) + var templ_7745c5c3_Var84 string + templ_7745c5c3_Var84, 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: 382, Col: 82} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 426, Col: 82} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var84)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } case v.AccountExists: - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 157, "\" class=\"inline-block bg-ink px-3 py-2 text-sm text-paper\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var79 string - templ_7745c5c3_Var79, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "invite.sign_in")) + var templ_7745c5c3_Var87 string + templ_7745c5c3_Var87, 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: 385, Col: 153} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 429, Col: 153} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var79)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var87)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 158, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } default: - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 160, "\" data-next=\"/\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1751,7 +1923,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 143, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 161, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1759,7 +1931,7 @@ func InvitationPage(p Page, v Invitation) templ.Component { } return nil }) - templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var71), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var79), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1767,4 +1939,11 @@ func InvitationPage(p Page, v Invitation) templ.Component { }) } +func maxDaysValue(d int) string { + if d == 0 { + return "" + } + return strconv.Itoa(d) +} + var _ = templruntime.GeneratedTemplate