From d7d4821e3e877c090a8cbaaaeff43723c55c713b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?=
Date: Sun, 22 Nov 2026 00:49:35 +0100
Subject: [PATCH] feat(api): enforce roles, org sign-in policies, invitations
and api tokens
Every org route resolves a principal from the session or a bearer token
and checks a permission. Nobody can grant, revoke or remove more than
they hold. Tokens are capped by their owner's current rights and cannot
manage credentials. Orgs can require TOTP or SSO; the owner keeps a
password fallback for SSO.
Closes #6
Closes #7
Closes #8
Closes #9
Closes #41
Closes #45
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
---
internal/api/access.go | 153 +++
internal/api/auth.go | 14 +-
internal/api/invitations.go | 339 ++++++
internal/api/me.go | 6 +
internal/api/members.go | 475 ++++++++
internal/api/pages.go | 270 ++++-
internal/api/permissions_test.go | 211 ++++
internal/api/server.go | 36 +-
internal/api/sso.go | 14 +-
internal/api/sso_admin.go | 97 +-
internal/api/sso_test.go | 8 +
internal/api/tokens.go | 206 ++++
internal/i18n/i18n_test.go | 45 +-
internal/i18n/locales/de.json | 86 +-
internal/i18n/locales/en.json | 86 +-
internal/web/assets/app.js | 23 +-
internal/web/auth.templ | 4 +-
internal/web/auth_templ.go | 131 ++-
internal/web/console.templ | 37 +-
internal/web/console_templ.go | 482 ++++----
internal/web/org.templ | 396 +++++++
internal/web/org_templ.go | 1770 ++++++++++++++++++++++++++++++
internal/web/sso.templ | 17 +-
internal/web/sso_templ.go | 210 ++--
24 files changed, 4677 insertions(+), 439 deletions(-)
create mode 100644 internal/api/access.go
create mode 100644 internal/api/invitations.go
create mode 100644 internal/api/members.go
create mode 100644 internal/api/permissions_test.go
create mode 100644 internal/api/tokens.go
create mode 100644 internal/web/org.templ
create mode 100644 internal/web/org_templ.go
diff --git a/internal/api/access.go b/internal/api/access.go
new file mode 100644
index 0000000..076c4e7
--- /dev/null
+++ b/internal/api/access.go
@@ -0,0 +1,153 @@
+package api
+
+import (
+ "context"
+ "errors"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+ "github.com/google/uuid"
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
+)
+
+const ctxPrincipal = "api.principal"
+
+// principal is whoever acts on an organization in this request: a browser
+// session or an API token, together with what it may do there.
+type principal struct {
+ UserID uuid.UUID
+ Org store.Org
+ Grants *authz.Grants
+ // Session is nil for API token requests.
+ Session *auth.Session
+ // TokenID is set for API token requests.
+ TokenID uuid.UUID
+}
+
+func (p *principal) scope() tenant.Scope { return tenant.Org(p.Org.ID, p.UserID) }
+
+func current(c *gin.Context) *principal { return c.MustGet(ctxPrincipal).(*principal) }
+
+// loadGrants returns the member's permissions, or ok=false if userID is not
+// a member of org.
+func loadGrants(ctx context.Context, q *store.Queries, org, userID uuid.UUID) (g *authz.Grants, ok bool, err error) {
+ m, err := q.GetMembership(ctx, store.GetMembershipParams{OrgID: org, UserID: userID})
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil, false, nil
+ }
+ if err != nil {
+ return nil, false, err
+ }
+ rows, err := q.MemberGrants(ctx, store.MemberGrantsParams{OrgID: org, UserID: userID})
+ if err != nil {
+ return nil, false, err
+ }
+ g = &authz.Grants{Owner: m.IsOwner, Org: authz.Set{}, Scoped: map[authz.Resource]authz.Set{}}
+ for _, r := range rows {
+ perms := authz.NewSet(r.Permissions...)
+ if r.ResourceType == nil || r.ResourceID == nil {
+ g.Org = g.Org.Union(perms)
+ continue
+ }
+ res := authz.Resource{Type: authz.ResourceType(*r.ResourceType), ID: *r.ResourceID}
+ g.Scoped[res] = g.Scoped[res].Union(perms)
+ }
+ return g, true, nil
+}
+
+// policyViolation returns the error code if sess may not act on org because
+// of the org's sign-in policy, or "" if it may.
+//
+// SSO sessions satisfy the TOTP requirement: multi-factor authentication is
+// then the identity provider's job. The owner may always sign in with a
+// password so a broken IdP cannot lock the organization out.
+func policyViolation(org store.Org, isOwner bool, sess *auth.Session) string {
+ viaOrgSSO := sess.Method == auth.MethodSSO && sess.SSOOrg == org.ID
+ if org.RequireSso && !viaOrgSSO && !isOwner {
+ return "sso_required_by_org"
+ }
+ if org.RequireTotp && !viaOrgSSO && sess.Method != auth.MethodPasswordTOTP {
+ return "totp_required_by_org"
+ }
+ return ""
+}
+
+// orgAccess authenticates the request against the session's active
+// organization, enforces its sign-in policy and attaches a principal.
+func (s *Server) orgAccess() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ p, status, code, err := s.resolvePrincipal(c)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if code != "" {
+ fail(c, status, code)
+ return
+ }
+ c.Set(ctxPrincipal, p)
+ c.Next()
+ }
+}
+
+func (s *Server) resolvePrincipal(c *gin.Context) (*principal, int, string, error) {
+ if tok := bearerToken(c); tok != "" {
+ return s.tokenPrincipal(c.Request.Context(), tok)
+ }
+ sess := auth.Current(c)
+ if sess == nil {
+ return nil, http.StatusUnauthorized, "unauthenticated", nil
+ }
+ if sess.OrgID == uuid.Nil {
+ return nil, http.StatusForbidden, "forbidden", nil
+ }
+ ctx := c.Request.Context()
+ p := &principal{UserID: sess.UserID, Session: sess}
+ var member bool
+ err := s.db.Tx(ctx, tenant.Org(sess.OrgID, sess.UserID), func(q *store.Queries) error {
+ var err error
+ if p.Org, err = q.GetOrg(ctx, sess.OrgID); err != nil {
+ return err
+ }
+ p.Grants, member, err = loadGrants(ctx, q, sess.OrgID, sess.UserID)
+ return err
+ })
+ if errors.Is(err, pgx.ErrNoRows) || (err == nil && !member) {
+ return nil, http.StatusForbidden, "forbidden", nil
+ }
+ if err != nil {
+ return nil, 0, "", err
+ }
+ if code := policyViolation(p.Org, p.Grants.Owner, sess); code != "" {
+ return nil, http.StatusForbidden, code, nil
+ }
+ return p, 0, "", nil
+}
+
+// can aborts unless the principal holds perm organization-wide.
+func can(perm authz.Permission) gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if !current(c).Grants.Can(perm) {
+ fail(c, http.StatusForbidden, "forbidden")
+ return
+ }
+ c.Next()
+ }
+}
+
+// sessionOnly rejects API tokens on routes that manage credentials, so a
+// leaked token cannot mint further tokens or change who has access.
+func sessionOnly() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ if current(c).Session == nil {
+ fail(c, http.StatusForbidden, "session_required")
+ return
+ }
+ c.Next()
+ }
+}
diff --git a/internal/api/auth.go b/internal/api/auth.go
index 8f9e229..6f84eba 100644
--- a/internal/api/auth.go
+++ b/internal/api/auth.go
@@ -91,7 +91,7 @@ func (s *Server) signup(c *gin.Context) {
internalError(c, err)
return
}
- s.startSession(c, user.ID, orgID, i18n.Lang(ctx))
+ s.startSession(c, auth.NewSession{UserID: user.ID, OrgID: orgID, Locale: i18n.Lang(ctx), Method: auth.MethodPassword})
}
func (s *Server) signupAllowed(ctx context.Context) (bool, error) {
@@ -164,7 +164,7 @@ func (s *Server) login(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "totp_required"})
return
}
- s.finishLogin(c, user.ID)
+ s.finishLogin(c, user.ID, auth.MethodPassword)
}
// secondFactorRequest carries a TOTP code or a recovery code.
@@ -211,10 +211,10 @@ func (s *Server) loginTOTP(c *gin.Context) {
}
_ = s.rdb.Del(ctx, mfaKey(token)).Err()
setCookie(c, mfaCookie, "", -1)
- s.finishLogin(c, userID)
+ s.finishLogin(c, userID, auth.MethodPasswordTOTP)
}
-func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) {
+func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID, method auth.Method) {
ctx := c.Request.Context()
var (
user store.User
@@ -236,14 +236,14 @@ func (s *Server) finishLogin(c *gin.Context, userID uuid.UUID) {
if len(orgs) > 0 {
org = orgs[0].ID
}
- s.startSession(c, userID, org, deref(user.Locale))
+ s.startSession(c, auth.NewSession{UserID: userID, OrgID: org, Locale: deref(user.Locale), Method: method})
}
-func (s *Server) startSession(c *gin.Context, userID, orgID uuid.UUID, locale string) {
+func (s *Server) startSession(c *gin.Context, n auth.NewSession) {
if old := auth.Current(c); old != nil {
_ = s.sessions.Delete(c.Request.Context(), old)
}
- sess, err := s.sessions.Create(c.Request.Context(), userID, orgID, locale)
+ sess, err := s.sessions.Create(c.Request.Context(), n)
if err != nil {
internalError(c, err)
return
diff --git a/internal/api/invitations.go b/internal/api/invitations.go
new file mode 100644
index 0000000..1ff42c9
--- /dev/null
+++ b/internal/api/invitations.go
@@ -0,0 +1,339 @@
+package api
+
+import (
+ "context"
+ "errors"
+ "net/http"
+ "net/mail"
+ "strings"
+ "time"
+
+ "github.com/gin-gonic/gin"
+ "github.com/google/uuid"
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
+ "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"
+)
+
+const invitationTTL = 7 * 24 * time.Hour
+
+type inviteRequest struct {
+ Email string `json:"email" binding:"required,max=320"`
+ RoleID uuid.UUID `json:"role_id" binding:"required"`
+}
+
+func (s *Server) createInvitation(c *gin.Context) {
+ var req inviteRequest
+ if !bind(c, &req) {
+ return
+ }
+ email := normalizeEmail(req.Email)
+ if addr, err := mail.ParseAddress(email); err != nil || addr.Address != email {
+ fail(c, http.StatusUnprocessableEntity, "invalid_email")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ tok := auth.RandomToken()
+ var code string
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ role, err := q.GetRole(ctx, req.RoleID)
+ if errors.Is(err, pgx.ErrNoRows) {
+ code = "role_not_found"
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if !p.Grants.CanGrant(authz.NewSet(role.Permissions...), nil) {
+ code = "permission_escalation"
+ return nil
+ }
+ members, err := q.ListOrgMembers(ctx, p.Org.ID)
+ if err != nil {
+ return err
+ }
+ for _, m := range members {
+ if m.Email == email {
+ code = "already_member"
+ return nil
+ }
+ }
+ _, err = q.CreateInvitation(ctx, store.CreateInvitationParams{
+ OrgID: p.Org.ID, Email: email, RoleID: role.ID, TokenHash: hashToken(tok),
+ InvitedBy: &p.UserID, ExpiresAt: time.Now().Add(invitationTTL),
+ })
+ return err
+ })
+ switch {
+ case err != nil:
+ internalError(c, err)
+ case code == "role_not_found":
+ fail(c, http.StatusNotFound, code)
+ case code == "permission_escalation":
+ fail(c, http.StatusForbidden, code)
+ case code != "":
+ fail(c, http.StatusConflict, code)
+ default:
+ // There is no mailer yet; the inviter passes the link on.
+ c.JSON(http.StatusCreated, gin.H{"url": s.cfg.PublicURL + "/invite/" + tok})
+ }
+}
+
+func (s *Server) listInvitations(c *gin.Context) {
+ p := current(c)
+ ctx := c.Request.Context()
+ var rows []store.ListPendingInvitationsRow
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ rows, err = q.ListPendingInvitations(ctx)
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ type view struct {
+ ID uuid.UUID `json:"id"`
+ Email string `json:"email"`
+ RoleName string `json:"role_name"`
+ ExpiresAt time.Time `json:"expires_at"`
+ }
+ out := make([]view, len(rows))
+ for i, r := range rows {
+ out[i] = view{ID: r.ID, Email: r.Email, RoleName: r.RoleName, ExpiresAt: r.ExpiresAt}
+ }
+ c.JSON(http.StatusOK, gin.H{"invitations": out})
+}
+
+func (s *Server) deleteInvitation(c *gin.Context) {
+ id, err := uuid.Parse(c.Param("id"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var n int64
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ n, err = q.DeleteInvitation(ctx, id)
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if n == 0 {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ c.Status(http.StatusNoContent)
+}
+
+// findInvitation returns the invitation for tok, or ok=false if it does not
+// exist, was used or has expired.
+func (s *Server) findInvitation(ctx context.Context, tok string) (inv store.GetInvitationByHashRow, ok bool, err error) {
+ hash := hashToken(tok)
+ var org uuid.UUID
+ err = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
+ org, err = q.InvitationOrg(ctx, hash)
+ return err
+ })
+ if err != nil || org == uuid.Nil {
+ return inv, false, err
+ }
+ err = s.db.Tx(ctx, tenant.Org(org, uuid.Nil), func(q *store.Queries) error {
+ inv, err = q.GetInvitationByHash(ctx, hash)
+ return err
+ })
+ if err != nil {
+ return inv, false, err
+ }
+ return inv, inv.AcceptedAt == nil && inv.ExpiresAt.After(time.Now()), nil
+}
+
+// join makes userID a member with the invited role. The inviter must still
+// be allowed to grant that role; rights lost since inviting are not passed
+// on through a pending invitation.
+func (s *Server) join(ctx context.Context, inv store.GetInvitationByHashRow, userID uuid.UUID) (string, error) {
+ var code string
+ err := s.db.Tx(ctx, tenant.Org(inv.OrgID, userID), func(q *store.Queries) error {
+ if inv.InvitedBy == nil {
+ code = "invitation_invalid"
+ return nil
+ }
+ g, member, err := loadGrants(ctx, q, inv.OrgID, *inv.InvitedBy)
+ if err != nil {
+ return err
+ }
+ role, err := q.GetRole(ctx, inv.RoleID)
+ if err != nil {
+ return err
+ }
+ if !member || !g.CanGrant(authz.NewSet(role.Permissions...), nil) {
+ code = "invitation_invalid"
+ return nil
+ }
+ n, err := q.MarkInvitationAccepted(ctx, inv.ID)
+ if err != nil {
+ return err
+ }
+ if n == 0 {
+ code = "invitation_invalid"
+ return nil
+ }
+ if already, err := q.IsMember(ctx, store.IsMemberParams{OrgID: inv.OrgID, UserID: userID}); err != nil {
+ return err
+ } else if !already {
+ if err := q.AddMembership(ctx, store.AddMembershipParams{OrgID: inv.OrgID, UserID: userID}); err != nil {
+ return err
+ }
+ }
+ _, err = q.CreateAssignment(ctx, store.CreateAssignmentParams{OrgID: inv.OrgID, UserID: userID, RoleID: inv.RoleID})
+ if isUniqueViolation(err, "role_assignments_org_id_user_id_role_id_resource_type_resou_key") {
+ return nil
+ }
+ return err
+ })
+ return code, err
+}
+
+func (s *Server) acceptInvitation(c *gin.Context) {
+ ctx := c.Request.Context()
+ sess := auth.Current(c)
+ inv, ok, err := s.findInvitation(ctx, c.Param("token"))
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if !ok {
+ fail(c, http.StatusGone, "invitation_invalid")
+ return
+ }
+ me, err := s.loadMe(ctx, sess)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if me.Email != inv.Email {
+ fail(c, http.StatusForbidden, "invitation_email_mismatch")
+ return
+ }
+ code, err := s.join(ctx, inv, sess.UserID)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if code != "" {
+ fail(c, http.StatusGone, code)
+ return
+ }
+ if err := s.sessions.SwitchOrg(ctx, sess, inv.OrgID); err != nil {
+ internalError(c, err)
+ return
+ }
+ c.Status(http.StatusNoContent)
+}
+
+type inviteSignupRequest struct {
+ DisplayName string `json:"display_name" binding:"max=200"`
+ Password string `json:"password" binding:"required,max=1024"`
+}
+
+// inviteSignup creates an account for an invited address. It bypasses
+// UPTIME_SIGNUP because the organization vouched for the invitee.
+func (s *Server) inviteSignup(c *gin.Context) {
+ var req inviteSignupRequest
+ if !bind(c, &req) {
+ return
+ }
+ ctx := c.Request.Context()
+ if !s.limit(c, "signup:"+c.ClientIP(), 10, time.Hour) {
+ return
+ }
+ inv, ok, err := s.findInvitation(ctx, c.Param("token"))
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if !ok {
+ fail(c, http.StatusGone, "invitation_invalid")
+ return
+ }
+ hash, err := auth.HashPassword(req.Password)
+ if errors.Is(err, auth.ErrPasswordTooShort) {
+ fail(c, http.StatusUnprocessableEntity, "password_too_short", "Min", auth.MinPasswordLength)
+ return
+ }
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ var user store.User
+ err = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
+ user, err = q.CreateUser(ctx, store.CreateUserParams{
+ Email: inv.Email, DisplayName: strings.TrimSpace(req.DisplayName),
+ PasswordHash: &hash, Locale: ptr(i18n.Lang(ctx)),
+ })
+ return err
+ })
+ if isUniqueViolation(err, "users_email_key") {
+ fail(c, http.StatusConflict, "email_taken")
+ return
+ }
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ code, err := s.join(ctx, inv, user.ID)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if code != "" {
+ fail(c, http.StatusGone, code)
+ return
+ }
+ s.startSession(c, auth.NewSession{UserID: user.ID, OrgID: inv.OrgID, Locale: i18n.Lang(ctx), Method: auth.MethodPassword})
+}
+
+func (s *Server) invitePage(c *gin.Context) {
+ ctx := c.Request.Context()
+ tok := c.Param("token")
+ inv, ok, err := s.findInvitation(ctx, tok)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ view := web.Invitation{Token: tok, Valid: ok}
+ if ok {
+ view.OrgName, view.RoleName, view.Email = inv.OrgName, inv.RoleName, inv.Email
+ if sess := auth.Current(c); sess != nil {
+ me, err := s.loadMe(ctx, sess)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ view.SignedInAs = me.Email
+ } else {
+ err = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
+ _, err := q.GetUserByEmail(ctx, inv.Email)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil
+ }
+ view.AccountExists = err == nil
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ }
+ }
+ web.Render(c, http.StatusOK, web.InvitationPage(s.pageFor(c, "invite.title"), view))
+}
diff --git a/internal/api/me.go b/internal/api/me.go
index 4d26dbd..8b0709a 100644
--- a/internal/api/me.go
+++ b/internal/api/me.go
@@ -171,6 +171,12 @@ func (s *Server) totpEnable(c *gin.Context) {
return
}
_ = s.rdb.Del(ctx, totpSetupKey(sess.UserID)).Err()
+ if sess.Method == auth.MethodPassword || sess.Method == "" {
+ if err := s.sessions.SetMethod(ctx, sess, auth.MethodPasswordTOTP); err != nil {
+ internalError(c, err)
+ return
+ }
+ }
c.JSON(http.StatusOK, gin.H{"recovery_codes": codes})
}
diff --git a/internal/api/members.go b/internal/api/members.go
new file mode 100644
index 0000000..685cf89
--- /dev/null
+++ b/internal/api/members.go
@@ -0,0 +1,475 @@
+package api
+
+import (
+ "errors"
+ "net/http"
+ "strings"
+ "time"
+
+ "github.com/gin-gonic/gin"
+ "github.com/google/uuid"
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
+)
+
+type assignmentView struct {
+ ID uuid.UUID `json:"id"`
+ RoleID uuid.UUID `json:"role_id"`
+ RoleName string `json:"role_name"`
+ RoleKey *string `json:"role_key,omitempty"`
+ ResourceType *string `json:"resource_type,omitempty"`
+ ResourceID *uuid.UUID `json:"resource_id,omitempty"`
+}
+
+type memberView struct {
+ UserID uuid.UUID `json:"user_id"`
+ Email string `json:"email"`
+ DisplayName string `json:"display_name"`
+ IsOwner bool `json:"is_owner"`
+ JoinedAt time.Time `json:"joined_at"`
+ Assignments []assignmentView `json:"assignments"`
+}
+
+func (s *Server) loadMembers(c *gin.Context) ([]memberView, error) {
+ p := current(c)
+ ctx := c.Request.Context()
+ var out []memberView
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ members, err := q.ListOrgMembers(ctx, p.Org.ID)
+ if err != nil {
+ return err
+ }
+ assigns, err := q.ListAssignments(ctx, p.Org.ID)
+ if err != nil {
+ return err
+ }
+ byUser := map[uuid.UUID][]assignmentView{}
+ for _, a := range assigns {
+ byUser[a.UserID] = append(byUser[a.UserID], assignmentView{
+ ID: a.ID, RoleID: a.RoleID, RoleName: a.RoleName, RoleKey: a.RoleKey,
+ ResourceType: a.ResourceType, ResourceID: a.ResourceID,
+ })
+ }
+ out = make([]memberView, len(members))
+ for i, m := range members {
+ out[i] = memberView{
+ UserID: m.ID, Email: m.Email, DisplayName: m.DisplayName, IsOwner: m.IsOwner,
+ JoinedAt: m.JoinedAt, Assignments: byUser[m.ID],
+ }
+ if out[i].Assignments == nil {
+ out[i].Assignments = []assignmentView{}
+ }
+ }
+ return nil
+ })
+ return out, err
+}
+
+func (s *Server) listMembers(c *gin.Context) {
+ members, err := s.loadMembers(c)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ c.JSON(http.StatusOK, gin.H{"members": members})
+}
+
+// removeMember requires the actor to hold every permission the member holds
+// organization-wide, so a delegated admin cannot remove a stronger one.
+func (s *Server) removeMember(c *gin.Context) {
+ target, err := uuid.Parse(c.Param("user"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var code string
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ g, member, err := loadGrants(ctx, q, p.Org.ID, target)
+ switch {
+ case err != nil:
+ return err
+ case !member:
+ code = "not_found"
+ case g.Owner:
+ code = "owner_cannot_be_removed"
+ case !p.Grants.CanGrant(g.Org, nil):
+ code = "permission_escalation"
+ default:
+ _, err = q.RemoveMembership(ctx, store.RemoveMembershipParams{OrgID: p.Org.ID, UserID: target})
+ }
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ switch code {
+ case "":
+ _ = s.sessions.DeleteAllForUser(ctx, target)
+ c.Status(http.StatusNoContent)
+ case "not_found":
+ fail(c, http.StatusNotFound, code)
+ default:
+ fail(c, http.StatusForbidden, code)
+ }
+}
+
+type assignRequest struct {
+ RoleID uuid.UUID `json:"role_id" binding:"required"`
+ ResourceType string `json:"resource_type" binding:"omitempty,oneof=monitor_group status_page"`
+ ResourceID *uuid.UUID `json:"resource_id"`
+}
+
+func (r assignRequest) scope() (*authz.Resource, bool) {
+ if r.ResourceType == "" && r.ResourceID == nil {
+ return nil, true
+ }
+ if r.ResourceID == nil {
+ return nil, false
+ }
+ res := authz.Resource{Type: authz.ResourceType(r.ResourceType), ID: *r.ResourceID}
+ return &res, res.Valid()
+}
+
+func (s *Server) assignRole(c *gin.Context) {
+ target, err := uuid.Parse(c.Param("user"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ var req assignRequest
+ if !bind(c, &req) {
+ return
+ }
+ scope, ok := req.scope()
+ if !ok {
+ fail(c, http.StatusUnprocessableEntity, "invalid_input")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var (
+ code string
+ row store.RoleAssignment
+ )
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ role, err := q.GetRole(ctx, req.RoleID)
+ if errors.Is(err, pgx.ErrNoRows) {
+ code = "role_not_found"
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ m, err := q.GetMembership(ctx, store.GetMembershipParams{OrgID: p.Org.ID, UserID: target})
+ switch {
+ case errors.Is(err, pgx.ErrNoRows):
+ code = "not_found"
+ return nil
+ case err != nil:
+ return err
+ case m.IsOwner:
+ code = "owner_has_all_permissions"
+ return nil
+ case !p.Grants.CanGrant(authz.NewSet(role.Permissions...), scope):
+ code = "permission_escalation"
+ return nil
+ }
+ params := store.CreateAssignmentParams{OrgID: p.Org.ID, UserID: target, RoleID: role.ID}
+ if scope != nil {
+ rt := string(scope.Type)
+ params.ResourceType, params.ResourceID = &rt, &scope.ID
+ }
+ row, err = q.CreateAssignment(ctx, params)
+ if isUniqueViolation(err, "role_assignments_org_id_user_id_role_id_resource_type_resou_key") {
+ code = "already_assigned"
+ return nil
+ }
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ switch code {
+ case "":
+ c.JSON(http.StatusCreated, gin.H{"id": row.ID})
+ case "not_found", "role_not_found":
+ fail(c, http.StatusNotFound, code)
+ case "already_assigned", "owner_has_all_permissions":
+ fail(c, http.StatusConflict, code)
+ default:
+ fail(c, http.StatusForbidden, code)
+ }
+}
+
+func (s *Server) unassignRole(c *gin.Context) {
+ id, err := uuid.Parse(c.Param("id"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var code string
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ a, err := q.GetAssignment(ctx, id)
+ if errors.Is(err, pgx.ErrNoRows) {
+ code = "not_found"
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ role, err := q.GetRole(ctx, a.RoleID)
+ if err != nil {
+ return err
+ }
+ var scope *authz.Resource
+ if a.ResourceType != nil && a.ResourceID != nil {
+ scope = &authz.Resource{Type: authz.ResourceType(*a.ResourceType), ID: *a.ResourceID}
+ }
+ if !p.Grants.CanGrant(authz.NewSet(role.Permissions...), scope) {
+ code = "permission_escalation"
+ return nil
+ }
+ _, err = q.DeleteAssignment(ctx, id)
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ switch code {
+ case "":
+ c.Status(http.StatusNoContent)
+ case "not_found":
+ fail(c, http.StatusNotFound, code)
+ default:
+ fail(c, http.StatusForbidden, code)
+ }
+}
+
+type roleView struct {
+ ID uuid.UUID `json:"id"`
+ Key *string `json:"key,omitempty"`
+ Name string `json:"name"`
+ BuiltIn bool `json:"built_in"`
+ Permissions []string `json:"permissions"`
+}
+
+func viewRole(r store.Role) roleView {
+ return roleView{ID: r.ID, Key: r.Key, Name: r.Name, BuiltIn: r.OrgID == nil, Permissions: authz.NewSet(r.Permissions...).Strings()}
+}
+
+func (s *Server) listRoles(c *gin.Context) {
+ p := current(c)
+ ctx := c.Request.Context()
+ var rows []store.Role
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ rows, err = q.ListRoles(ctx)
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ out := make([]roleView, len(rows))
+ for i, r := range rows {
+ out[i] = viewRole(r)
+ }
+ c.JSON(http.StatusOK, gin.H{"roles": out, "permissions": authz.NewSet(authz.All...).Strings()})
+}
+
+type roleRequest struct {
+ Name string `json:"name" binding:"required,max=100"`
+ Permissions []string `json:"permissions" binding:"required,min=1,max=50,dive,max=50"`
+}
+
+func (s *Server) createRole(c *gin.Context) {
+ var req roleRequest
+ if !bind(c, &req) {
+ return
+ }
+ perms := authz.NewSet(req.Permissions...)
+ p := current(c)
+ if len(perms) == 0 || strings.TrimSpace(req.Name) == "" {
+ fail(c, http.StatusUnprocessableEntity, "invalid_permissions")
+ return
+ }
+ if !p.Grants.CanGrant(perms, nil) {
+ fail(c, http.StatusForbidden, "permission_escalation")
+ return
+ }
+ ctx := c.Request.Context()
+ var row store.Role
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ row, err = q.CreateRole(ctx, store.CreateRoleParams{OrgID: &p.Org.ID, Name: strings.TrimSpace(req.Name), Permissions: perms.Strings()})
+ return err
+ })
+ if isUniqueViolation(err, "roles_org_id_name_key") {
+ fail(c, http.StatusConflict, "role_name_taken")
+ return
+ }
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ c.JSON(http.StatusCreated, viewRole(row))
+}
+
+// updateRole requires the actor to hold both the old and the new
+// permissions: otherwise they could strip rights they cannot grant back, or
+// widen a role they are assigned to.
+func (s *Server) updateRole(c *gin.Context) {
+ id, err := uuid.Parse(c.Param("id"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ var req roleRequest
+ if !bind(c, &req) {
+ return
+ }
+ perms := authz.NewSet(req.Permissions...)
+ if len(perms) == 0 || strings.TrimSpace(req.Name) == "" {
+ fail(c, http.StatusUnprocessableEntity, "invalid_permissions")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var (
+ code string
+ row store.Role
+ )
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ old, err := q.GetRole(ctx, id)
+ switch {
+ case errors.Is(err, pgx.ErrNoRows):
+ code = "not_found"
+ return nil
+ case err != nil:
+ return err
+ case old.OrgID == nil:
+ code = "role_built_in"
+ return nil
+ case !p.Grants.CanGrant(perms.Union(authz.NewSet(old.Permissions...)), nil):
+ code = "permission_escalation"
+ return nil
+ }
+ row, err = q.UpdateRole(ctx, store.UpdateRoleParams{ID: id, Name: strings.TrimSpace(req.Name), Permissions: perms.Strings()})
+ if isUniqueViolation(err, "roles_org_id_name_key") {
+ code = "role_name_taken"
+ return nil
+ }
+ return err
+ })
+ s.roleResult(c, err, code, func() { c.JSON(http.StatusOK, viewRole(row)) })
+}
+
+func (s *Server) deleteRole(c *gin.Context) {
+ id, err := uuid.Parse(c.Param("id"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var code string
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ old, err := q.GetRole(ctx, id)
+ switch {
+ case errors.Is(err, pgx.ErrNoRows):
+ code = "not_found"
+ return nil
+ case err != nil:
+ return err
+ case old.OrgID == nil:
+ code = "role_built_in"
+ return nil
+ case !p.Grants.CanGrant(authz.NewSet(old.Permissions...), nil):
+ code = "permission_escalation"
+ return nil
+ }
+ n, err := q.CountRoleAssignments(ctx, id)
+ if err != nil {
+ return err
+ }
+ if n > 0 {
+ code = "role_in_use"
+ return nil
+ }
+ _, err = q.DeleteRole(ctx, id)
+ return err
+ })
+ s.roleResult(c, err, code, func() { c.Status(http.StatusNoContent) })
+}
+
+func (s *Server) roleResult(c *gin.Context, err error, code string, ok func()) {
+ switch {
+ case err != nil:
+ internalError(c, err)
+ case code == "":
+ ok()
+ case code == "not_found":
+ fail(c, http.StatusNotFound, code)
+ case code == "permission_escalation":
+ fail(c, http.StatusForbidden, code)
+ default:
+ fail(c, http.StatusConflict, code)
+ }
+}
+
+type policyRequest struct {
+ RequireTOTP bool `json:"require_totp"`
+ RequireSSO bool `json:"require_sso"`
+}
+
+func (s *Server) updatePolicy(c *gin.Context) {
+ var req policyRequest
+ if !bind(c, &req) {
+ return
+ }
+ p := current(c)
+ // The actor must already meet a policy before switching it on, or the
+ // change would lock them out on their next request.
+ probe := p.Org
+ probe.RequireTotp, probe.RequireSso = req.RequireTOTP, req.RequireSSO
+ if code := policyViolation(probe, p.Grants.Owner, p.Session); code != "" {
+ fail(c, http.StatusConflict, "policy_would_lock_you_out")
+ return
+ }
+ ctx := c.Request.Context()
+ var org store.Org
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ if req.RequireSSO {
+ providers, err := q.ListEnabledSSOProviders(ctx)
+ if err != nil {
+ return err
+ }
+ if len(providers) == 0 {
+ return errNoSSOProvider
+ }
+ }
+ var err error
+ org, err = q.UpdateOrgPolicy(ctx, store.UpdateOrgPolicyParams{ID: p.Org.ID, RequireTotp: req.RequireTOTP, RequireSso: req.RequireSSO})
+ return err
+ })
+ if errors.Is(err, errNoSSOProvider) {
+ fail(c, http.StatusConflict, "sso_no_provider")
+ return
+ }
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ c.JSON(http.StatusOK, gin.H{"require_totp": org.RequireTotp, "require_sso": org.RequireSso})
+}
+
+var errNoSSOProvider = errors.New("api: no enabled sso provider")
diff --git a/internal/api/pages.go b/internal/api/pages.go
index 33c8b26..291a2dc 100644
--- a/internal/api/pages.go
+++ b/internal/api/pages.go
@@ -3,12 +3,15 @@ package api
import (
"net/http"
"strings"
+ "time"
"github.com/a-h/templ"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"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"
@@ -17,9 +20,14 @@ import (
func (s *Server) registerPages(r gin.IRouter) {
r.GET("/login", s.loginPage)
r.GET("/signup", s.signupPage)
+ r.GET("/invite/:token", s.invitePage)
r.GET("/", s.page("console.monitors.title", web.Dashboard))
r.GET("/settings/security", s.securityPage)
- r.GET("/settings/sso", s.ssoSettingsPage)
+ r.GET("/settings/sso", s.orgPage("sso.settings.title", authz.OrgManage, s.ssoSettingsView))
+ r.GET("/settings/org", s.orgPage("org.title", authz.OrgManage, s.orgSettingsView))
+ r.GET("/settings/members", s.orgPage("members.title", authz.MembersRead, s.membersView))
+ r.GET("/settings/roles", s.orgPage("roles.title", authz.MembersRead, s.rolesView))
+ r.GET("/settings/tokens", s.orgPage("tokens.title", "", s.tokensView))
}
// flashErrors lists the codes a redirect may ask a page to display. Anything
@@ -28,6 +36,7 @@ var flashErrors = map[ssoError]bool{
"sso_unavailable": true, "sso_provider_error": true, "sso_expired": true,
"sso_denied": true, "sso_not_member": true, "sso_not_provisioned": true,
"sso_link_required": true, "sso_identity_taken": true, "invalid_credentials": true,
+ "totp_required_by_org": true, "sso_required_by_org": true,
}
func (s *Server) pageFor(c *gin.Context, titleID string) web.Page {
@@ -44,9 +53,19 @@ func (s *Server) pageFor(c *gin.Context, titleID string) web.Page {
return p
}
+// localPath returns next if it is a path on this site, so login redirects
+// cannot send users to another origin.
+func localPath(next string) string {
+ if strings.HasPrefix(next, "/") && !strings.HasPrefix(next, "//") && !strings.Contains(next, `\`) {
+ return next
+ }
+ return "/"
+}
+
func (s *Server) loginPage(c *gin.Context) {
+ next := localPath(c.Query("next"))
if auth.Current(c) != nil {
- c.Redirect(http.StatusSeeOther, "/")
+ c.Redirect(http.StatusSeeOther, next)
return
}
allowed, err := s.signupAllowed(c.Request.Context())
@@ -54,7 +73,7 @@ func (s *Server) loginPage(c *gin.Context) {
internalError(c, err)
return
}
- web.Render(c, http.StatusOK, web.Login(s.pageFor(c, "auth.login.title"), allowed))
+ web.Render(c, http.StatusOK, web.Login(s.pageFor(c, "auth.login.title"), allowed, next))
}
func (s *Server) signupPage(c *gin.Context) {
@@ -70,30 +89,100 @@ func (s *Server) signupPage(c *gin.Context) {
web.Render(c, http.StatusOK, web.Signup(s.pageFor(c, "auth.signup.title")))
}
+// consoleMe loads the signed-in user and, if an organization is active,
+// their permissions and policy state there. The principal is nil when the
+// user has no active organization or is no longer a member.
+func (s *Server) consoleMe(c *gin.Context, sess *auth.Session) (web.Me, *principal, error) {
+ ctx := c.Request.Context()
+ m, err := s.loadMe(ctx, sess)
+ if err != nil {
+ return web.Me{}, nil, err
+ }
+ me := toWebMe(m)
+ me.Can = map[string]bool{}
+ if sess.OrgID == uuid.Nil {
+ return me, nil, nil
+ }
+ p := &principal{UserID: sess.UserID, Session: sess}
+ var member bool
+ err = s.db.Tx(ctx, tenant.Org(sess.OrgID, sess.UserID), func(q *store.Queries) error {
+ var err error
+ if p.Org, err = q.GetOrg(ctx, sess.OrgID); err != nil {
+ return err
+ }
+ p.Grants, member, err = loadGrants(ctx, q, sess.OrgID, sess.UserID)
+ return err
+ })
+ if err != nil || !member {
+ return me, nil, err
+ }
+ for _, perm := range authz.All {
+ me.Can[string(perm)] = p.Grants.Can(perm)
+ }
+ me.Policy = policyViolation(p.Org, p.Grants.Owner, sess)
+ return me, p, nil
+}
+
func (s *Server) page(titleID string, view func(web.Page, web.Me) templ.Component) gin.HandlerFunc {
return func(c *gin.Context) {
sess := auth.Current(c)
if sess == nil {
- c.Redirect(http.StatusSeeOther, "/login")
+ c.Redirect(http.StatusSeeOther, "/login?next="+c.Request.URL.Path)
return
}
- me, err := s.loadMe(c.Request.Context(), sess)
+ me, _, err := s.consoleMe(c, sess)
if err != nil {
internalError(c, err)
return
}
- web.Render(c, http.StatusOK, view(s.pageFor(c, titleID), toWebMe(me)))
+ web.Render(c, http.StatusOK, view(s.pageFor(c, titleID), me))
+ }
+}
+
+type orgPageView func(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error)
+
+// orgPage renders an organization settings page. perm may be empty for
+// pages every member can open.
+func (s *Server) orgPage(titleID string, perm authz.Permission, view orgPageView) gin.HandlerFunc {
+ return func(c *gin.Context) {
+ sess := auth.Current(c)
+ if sess == nil {
+ c.Redirect(http.StatusSeeOther, "/login?next="+c.Request.URL.Path)
+ return
+ }
+ me, p, err := s.consoleMe(c, sess)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ switch {
+ case p == nil:
+ c.Redirect(http.StatusSeeOther, "/")
+ return
+ case me.Policy != "":
+ c.Redirect(http.StatusSeeOther, "/settings/security?sso_error="+me.Policy)
+ return
+ case perm != "" && !p.Grants.Can(perm):
+ c.Redirect(http.StatusSeeOther, "/")
+ return
+ }
+ comp, err := view(c, p, s.pageFor(c, titleID), me)
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ web.Render(c, http.StatusOK, comp)
}
}
func (s *Server) securityPage(c *gin.Context) {
sess := auth.Current(c)
if sess == nil {
- c.Redirect(http.StatusSeeOther, "/login")
+ c.Redirect(http.StatusSeeOther, "/login?next=/settings/security")
return
}
ctx := c.Request.Context()
- me, err := s.loadMe(ctx, sess)
+ me, _, err := s.consoleMe(c, sess)
if err != nil {
internalError(c, err)
return
@@ -120,47 +209,161 @@ func (s *Server) securityPage(c *gin.Context) {
return
}
}
- web.Render(c, http.StatusOK, web.Security(s.pageFor(c, "security.title"), toWebMe(me), identities, canLink))
+ web.Render(c, http.StatusOK, web.Security(s.pageFor(c, "security.title"), me, identities, canLink))
}
-func (s *Server) ssoSettingsPage(c *gin.Context) {
- sess := auth.Current(c)
- if sess == nil {
- c.Redirect(http.StatusSeeOther, "/login")
- return
+func toWebRoles(rows []store.Role) []web.Role {
+ out := make([]web.Role, len(rows))
+ for i, r := range rows {
+ out[i] = web.Role{ID: r.ID.String(), Name: r.Name, BuiltIn: r.OrgID == nil, Permissions: authz.NewSet(r.Permissions...).Strings()}
}
+ return out
+}
+
+// grantable lists the permissions p may hand out organization-wide.
+func grantable(p *principal) []string {
+ var out []string
+ for _, perm := range authz.All {
+ if p.Grants.CanGrant(authz.NewSet(perm), nil) {
+ out = append(out, string(perm))
+ }
+ }
+ return out
+}
+
+func (s *Server) ssoSettingsView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
ctx := c.Request.Context()
- me, err := s.loadMe(ctx, sess)
- if err != nil {
- internalError(c, err)
- return
- }
- wm := toWebMe(me)
- if !wm.IsOwner {
- c.Redirect(http.StatusSeeOther, "/")
- return
- }
- var rows []store.SsoProvider
- err = s.db.Tx(ctx, tenant.Org(sess.OrgID, sess.UserID), func(q *store.Queries) error {
- rows, err = q.ListSSOProviders(ctx)
+ var (
+ rows []store.SsoProvider
+ roles []store.Role
+ )
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ if rows, err = q.ListSSOProviders(ctx); err != nil {
+ return err
+ }
+ roles, err = q.ListRoles(ctx)
return err
})
if err != nil {
- internalError(c, err)
- return
+ return nil, err
}
view := web.SSOSettings{
RedirectURL: s.sso.RedirectURL(),
- LoginURL: s.cfg.PublicURL + "/sso/" + wm.ActiveSlug,
+ LoginURL: s.cfg.PublicURL + "/sso/" + p.Org.Slug,
+ Roles: toWebRoles(roles),
}
for _, r := range rows {
- view.Providers = append(view.Providers, web.SSOProvider{
+ pr := web.SSOProvider{
ID: r.ID.String(), Name: r.Name, Issuer: r.Issuer, ClientID: r.ClientID,
HasSecret: r.ClientSecret != nil, AllowedDomains: strings.Join(r.AllowedDomains, ", "),
AutoProvision: r.AutoProvision, Enabled: r.Enabled,
- })
+ }
+ if r.DefaultRoleID != nil {
+ pr.DefaultRoleID = r.DefaultRoleID.String()
+ }
+ view.Providers = append(view.Providers, pr)
}
- web.Render(c, http.StatusOK, web.SSOSettingsPage(s.pageFor(c, "sso.settings.title"), wm, view))
+ return web.SSOSettingsPage(page, me, view), nil
+}
+
+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
+}
+
+func (s *Server) membersView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
+ c.Set(ctxPrincipal, p)
+ members, err := s.loadMembers(c)
+ if err != nil {
+ return nil, err
+ }
+ ctx := c.Request.Context()
+ var (
+ roles []store.Role
+ pending []store.ListPendingInvitationsRow
+ )
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ if roles, err = q.ListRoles(ctx); err != nil {
+ return err
+ }
+ pending, err = q.ListPendingInvitations(ctx)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ v := web.MembersView{CanManage: p.Grants.Can(authz.MembersManage)}
+ for _, r := range toWebRoles(roles) {
+ if p.Grants.CanGrant(authz.NewSet(r.Permissions...), nil) {
+ v.Roles = append(v.Roles, r)
+ }
+ }
+ for _, m := range members {
+ wm := web.Member{UserID: m.UserID.String(), Email: m.Email, DisplayName: m.DisplayName, IsOwner: m.IsOwner}
+ for _, a := range m.Assignments {
+ wa := web.Assignment{ID: a.ID.String(), RoleName: a.RoleName}
+ if a.ResourceType != nil {
+ wa.Scope = i18n.T(ctx, "scope."+*a.ResourceType)
+ }
+ wm.Assignments = append(wm.Assignments, wa)
+ }
+ v.Members = append(v.Members, wm)
+ }
+ for _, inv := range pending {
+ v.Invitations = append(v.Invitations, web.PendingInvite{ID: inv.ID.String(), Email: inv.Email, RoleName: inv.RoleName})
+ }
+ return web.MembersPage(page, me, v), nil
+}
+
+func (s *Server) rolesView(c *gin.Context, p *principal, page web.Page, me web.Me) (templ.Component, error) {
+ ctx := c.Request.Context()
+ var roles []store.Role
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ roles, err = q.ListRoles(ctx)
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ return web.RolesPage(page, me, web.RolesView{
+ Roles: toWebRoles(roles),
+ Permissions: authz.NewSet(authz.All...).Strings(),
+ Grantable: grantable(p),
+ CanManage: p.Grants.Can(authz.RolesManage),
+ }), nil
+}
+
+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)
+ var filter *uuid.UUID
+ if !showAll {
+ filter = &p.UserID
+ }
+ var rows []store.ListAPITokensRow
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ rows, err = q.ListAPITokens(ctx, store.ListAPITokensParams{OrgID: p.Org.ID, UserID: filter})
+ return err
+ })
+ if err != nil {
+ return nil, err
+ }
+ v := web.TokensView{Grantable: grantable(p), ShowOwner: showAll}
+ 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: "–"}
+ if r.ExpiresAt != nil {
+ t.ExpiresAt = r.ExpiresAt.Format(time.DateOnly)
+ }
+ if r.LastUsedAt != nil {
+ t.LastUsedAt = r.LastUsedAt.Format(time.DateTime)
+ }
+ v.Tokens = append(v.Tokens, t)
+ }
+ return web.TokensPage(page, me, v), nil
}
func toWebMe(m meView) web.Me {
@@ -169,7 +372,6 @@ func toWebMe(m meView) web.Me {
DisplayName: m.DisplayName,
TOTP: m.TOTP,
ActiveOrg: m.ActiveOrg.String(),
- TOTPMissing: m.TOTPEnrollmentRequired,
RecoveryCodesLeft: m.RecoveryCodesLeft,
}
for _, o := range m.Orgs {
diff --git a/internal/api/permissions_test.go b/internal/api/permissions_test.go
new file mode 100644
index 0000000..1ab8964
--- /dev/null
+++ b/internal/api/permissions_test.go
@@ -0,0 +1,211 @@
+package api_test
+
+import (
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/pquerna/otp/totp"
+)
+
+const password = "correct horse battery"
+
+// invite creates an invitation from b and returns its token.
+func (b *browser) invite(email, roleID string) string {
+ b.t.Helper()
+ st, body := b.do("POST", "/api/v1/org/invitations", map[string]any{"email": email, "role_id": roleID})
+ if st != http.StatusCreated {
+ b.t.Fatalf("invite(%s) = %d %v, want 201", email, st, body)
+ }
+ u := body["url"].(string)
+ return u[strings.LastIndex(u, "/")+1:]
+}
+
+// joinVia signs up a new account through an invitation.
+func (e *env) joinVia(t *testing.T, tok string) *browser {
+ t.Helper()
+ b := e.browser(t)
+ st, body := b.do("POST", "/api/v1/invitations/"+tok+"/signup", map[string]any{"password": password})
+ if st != http.StatusOK {
+ t.Fatalf("invite signup = %d %v, want 200", st, body)
+ }
+ return b
+}
+
+func (b *browser) roleID(key string) string {
+ b.t.Helper()
+ _, body := b.do("GET", "/api/v1/org/roles", nil)
+ for _, r := range body["roles"].([]any) {
+ r := r.(map[string]any)
+ if r["key"] == key || r["name"] == key {
+ return r["id"].(string)
+ }
+ }
+ b.t.Fatalf("role %q not found in %v", key, body)
+ return ""
+}
+
+func (b *browser) userID(email string) string {
+ b.t.Helper()
+ _, body := b.do("GET", "/api/v1/org/members", nil)
+ for _, m := range body["members"].([]any) {
+ m := m.(map[string]any)
+ if m["email"] == email {
+ return m["user_id"].(string)
+ }
+ }
+ b.t.Fatalf("member %q not found", email)
+ return ""
+}
+
+func expect(t *testing.T, what string, st int, body map[string]any, wantStatus int, wantCode string) {
+ t.Helper()
+ if st != wantStatus || (wantCode != "" && body["error"] != wantCode) {
+ t.Errorf("%s = %d %v, want %d %s", what, st, body["error"], wantStatus, wantCode)
+ }
+}
+
+func TestPermissions(t *testing.T) {
+ e := newEnv(t)
+ domain := uniq("p") + ".test"
+ owner := e.browser(t)
+ owner.signup("owner@"+domain, uniq("perm-"))
+
+ editorTok := owner.invite("editor@"+domain, owner.roleID("editor"))
+ editor := e.joinVia(t, editorTok)
+
+ t.Run("invitation works once", func(t *testing.T) {
+ st, body := e.browser(t).do("POST", "/api/v1/invitations/"+editorTok+"/signup", map[string]any{"password": password})
+ expect(t, "second use", st, body, http.StatusGone, "invitation_invalid")
+ })
+
+ t.Run("editor permissions", func(t *testing.T) {
+ st, body := editor.do("GET", "/api/v1/org/members", nil)
+ expect(t, "editor GET members", st, body, http.StatusOK, "")
+ st, body = editor.do("GET", "/api/v1/org/sso", nil)
+ expect(t, "editor GET sso", st, body, http.StatusForbidden, "forbidden")
+ st, body = editor.do("POST", "/api/v1/org/invitations", map[string]any{"email": "x@" + domain, "role_id": owner.roleID("viewer")})
+ expect(t, "editor invite", st, body, http.StatusForbidden, "forbidden")
+ })
+
+ // A delegated people manager may only hand out what they hold.
+ st, body := owner.do("POST", "/api/v1/org/roles", map[string]any{"name": "People", "permissions": []string{"members.manage"}})
+ expect(t, "create role", st, body, http.StatusCreated, "")
+ st, body = owner.do("POST", "/api/v1/org/roles", map[string]any{"name": "Readers", "permissions": []string{"members.read"}})
+ expect(t, "create role", st, body, http.StatusCreated, "")
+ manager := e.joinVia(t, owner.invite("manager@"+domain, owner.roleID("People")))
+
+ t.Run("no escalation through delegation", func(t *testing.T) {
+ editorID := owner.userID("editor@" + domain)
+ st, body := manager.do("POST", "/api/v1/org/members/"+editorID+"/roles", map[string]any{"role_id": owner.roleID("admin")})
+ expect(t, "manager assigns admin", st, body, http.StatusForbidden, "permission_escalation")
+ st, body = manager.do("POST", "/api/v1/org/members/"+editorID+"/roles", map[string]any{"role_id": owner.roleID("Readers")})
+ expect(t, "manager assigns readers", st, body, http.StatusCreated, "")
+ st, body = manager.do("DELETE", "/api/v1/org/members/"+editorID, nil)
+ expect(t, "manager removes stronger editor", st, body, http.StatusForbidden, "permission_escalation")
+ st, body = manager.do("DELETE", "/api/v1/org/members/"+owner.userID("owner@"+domain), nil)
+ expect(t, "manager removes owner", st, body, http.StatusForbidden, "owner_cannot_be_removed")
+ st, body = manager.do("POST", "/api/v1/org/invitations", map[string]any{"email": "y@" + domain, "role_id": owner.roleID("editor")})
+ expect(t, "manager invites editor", st, body, http.StatusForbidden, "permission_escalation")
+ st, body = manager.do("POST", "/api/v1/org/roles", map[string]any{"name": "Sneaky", "permissions": []string{"org.manage"}})
+ expect(t, "manager creates role", st, body, http.StatusForbidden, "forbidden")
+ })
+
+ t.Run("settings pages", func(t *testing.T) {
+ pages := []string{"/settings/members", "/settings/roles", "/settings/tokens", "/settings/org", "/settings/sso", "/settings/security", "/"}
+ for _, path := range pages {
+ if got := owner.visit(path); got.Path != path {
+ t.Errorf("owner GET %s ended at %s", path, got.Path)
+ }
+ }
+ for path, want := range map[string]string{"/settings/sso": "/", "/settings/org": "/", "/settings/members": "/settings/members", "/settings/tokens": "/settings/tokens"} {
+ if got := editor.visit(path); got.Path != want {
+ t.Errorf("editor GET %s ended at %s, want %s", path, got.Path, want)
+ }
+ }
+ })
+
+ t.Run("built-in roles are read-only", func(t *testing.T) {
+ st, body := owner.do("PUT", "/api/v1/org/roles/"+owner.roleID("viewer"), map[string]any{"name": "Viewer", "permissions": []string{"org.manage"}})
+ expect(t, "update built-in", st, body, http.StatusConflict, "role_built_in")
+ st, body = owner.do("DELETE", "/api/v1/org/roles/"+owner.roleID("People"), nil)
+ expect(t, "delete role in use", st, body, http.StatusConflict, "role_in_use")
+ })
+
+ t.Run("api tokens follow their owner", func(t *testing.T) {
+ st, body := editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "too much", "permissions": []string{"org.manage"}})
+ expect(t, "token beyond own rights", st, body, http.StatusForbidden, "permission_escalation")
+ st, body = editor.do("POST", "/api/v1/org/tokens", map[string]any{"name": "ci", "permissions": []string{"members.read", "monitors.write"}, "expires_in_days": 30})
+ expect(t, "create token", st, body, http.StatusCreated, "")
+ api := &browser{t: t, base: editor.base, hc: e.srv.Client(), bearer: body["token"].(string)}
+
+ st, body = api.do("GET", "/api/v1/org/members", nil)
+ expect(t, "token GET members", st, body, http.StatusOK, "")
+ st, body = api.do("GET", "/api/v1/org/sso", nil)
+ expect(t, "token GET sso", st, body, http.StatusForbidden, "forbidden")
+ st, body = api.do("POST", "/api/v1/org/tokens", map[string]any{"name": "child", "permissions": []string{"members.read"}})
+ expect(t, "token mints token", st, body, http.StatusForbidden, "session_required")
+
+ // Losing the role that granted members.read removes it from the token.
+ editorID := owner.userID("editor@" + domain)
+ _, members := owner.do("GET", "/api/v1/org/members", nil)
+ for _, m := range members["members"].([]any) {
+ m := m.(map[string]any)
+ if m["user_id"] != editorID {
+ continue
+ }
+ for _, a := range m["assignments"].([]any) {
+ owner.do("DELETE", "/api/v1/org/assignments/"+a.(map[string]any)["id"].(string), nil)
+ }
+ }
+ st, body = api.do("GET", "/api/v1/org/members", nil)
+ expect(t, "token after role removal", st, body, http.StatusForbidden, "forbidden")
+
+ st, body = owner.do("DELETE", "/api/v1/org/members/"+editorID, nil)
+ expect(t, "owner removes editor", st, body, http.StatusNoContent, "")
+ st, body = api.do("GET", "/api/v1/org/members", nil)
+ expect(t, "token after removal", st, body, http.StatusUnauthorized, "unauthenticated")
+ st, _ = editor.do("GET", "/api/v1/me", nil)
+ if st != http.StatusUnauthorized {
+ t.Errorf("removed member's session GET /me = %d, want 401", st)
+ }
+ })
+
+ t.Run("org policies", func(t *testing.T) {
+ st, body := owner.do("PUT", "/api/v1/org/policy", map[string]any{"require_sso": true})
+ expect(t, "require sso without provider", st, body, http.StatusConflict, "sso_no_provider")
+ st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"require_totp": true})
+ expect(t, "require totp without own totp", st, body, http.StatusConflict, "policy_would_lock_you_out")
+
+ owner.enableTOTP()
+ st, body = owner.do("PUT", "/api/v1/org/policy", map[string]any{"require_totp": true})
+ expect(t, "require totp", st, body, http.StatusOK, "")
+ st, body = manager.do("GET", "/api/v1/org/members", nil)
+ expect(t, "password-only member", st, body, http.StatusForbidden, "totp_required_by_org")
+
+ // The manager enables TOTP in the current session and is let in.
+ _, setup := manager.do("POST", "/api/v1/me/totp/setup", nil)
+ code, _ := totp.GenerateCode(setup["secret"].(string), time.Now())
+ manager.do("POST", "/api/v1/me/totp/enable", map[string]any{"code": code})
+ st, body = manager.do("GET", "/api/v1/org/members", nil)
+ expect(t, "member after enabling totp", st, body, http.StatusOK, "")
+ })
+
+ t.Run("invitation for another address", func(t *testing.T) {
+ tok := owner.invite("someone@"+domain, owner.roleID("viewer"))
+ st, body := manager.do("POST", "/api/v1/invitations/"+tok+"/accept", nil)
+ expect(t, "accept as other user", st, body, http.StatusForbidden, "invitation_email_mismatch")
+ })
+
+ t.Run("custom roles stay in their org", func(t *testing.T) {
+ other := e.browser(t)
+ other.signup("x@"+uniq("o")+".test", uniq("other-"))
+ _, body := other.do("GET", "/api/v1/org/roles", nil)
+ for _, r := range body["roles"].([]any) {
+ if name := r.(map[string]any)["name"]; name == "People" || name == "Readers" {
+ t.Errorf("other org sees custom role %v", name)
+ }
+ }
+ })
+}
diff --git a/internal/api/server.go b/internal/api/server.go
index 2687d31..47cbd75 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -12,6 +12,7 @@ import (
"github.com/redis/go-redis/v9"
"git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
"git.zb-server.de/ZB-Server/uptimesebi/internal/config"
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
"git.zb-server.de/ZB-Server/uptimesebi/internal/requestid"
@@ -85,11 +86,36 @@ func (s *Server) Mount(r gin.IRouter) {
me.POST("/totp/disable", s.totpDisable)
me.POST("/totp/recovery-codes", s.regenerateRecoveryCodes)
- org := v1.Group("/org", auth.Require(), s.requireOwner())
- org.GET("/sso", s.listSSOProviders)
- org.POST("/sso", s.createSSOProvider)
- org.PUT("/sso/:id", s.updateSSOProvider)
- org.DELETE("/sso/:id", s.deleteSSOProvider)
+ v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation)
+ v1.POST("/invitations/:token/signup", s.inviteSignup)
+
+ org := v1.Group("/org", s.orgAccess())
+ org.PUT("/policy", sessionOnly(), can(authz.OrgManage), s.updatePolicy)
+
+ org.GET("/sso", can(authz.OrgManage), s.listSSOProviders)
+ org.POST("/sso", sessionOnly(), can(authz.OrgManage), s.createSSOProvider)
+ org.PUT("/sso/:id", sessionOnly(), can(authz.OrgManage), s.updateSSOProvider)
+ org.DELETE("/sso/:id", sessionOnly(), can(authz.OrgManage), s.deleteSSOProvider)
+
+ org.GET("/members", can(authz.MembersRead), s.listMembers)
+ org.DELETE("/members/:user", sessionOnly(), can(authz.MembersManage), s.removeMember)
+ org.POST("/members/:user/roles", sessionOnly(), can(authz.MembersManage), s.assignRole)
+ org.DELETE("/assignments/:id", sessionOnly(), can(authz.MembersManage), s.unassignRole)
+
+ org.GET("/invitations", can(authz.MembersRead), s.listInvitations)
+ org.POST("/invitations", sessionOnly(), can(authz.MembersManage), s.createInvitation)
+ org.DELETE("/invitations/:id", sessionOnly(), can(authz.MembersManage), s.deleteInvitation)
+
+ org.GET("/roles", can(authz.MembersRead), s.listRoles)
+ org.POST("/roles", sessionOnly(), can(authz.RolesManage), s.createRole)
+ org.PUT("/roles/:id", sessionOnly(), can(authz.RolesManage), s.updateRole)
+ org.DELETE("/roles/:id", sessionOnly(), can(authz.RolesManage), s.deleteRole)
+
+ // Every member may hold personal tokens; their rights are capped by the
+ // member's own.
+ org.GET("/tokens", s.listTokens)
+ org.POST("/tokens", sessionOnly(), s.createToken)
+ org.DELETE("/tokens/:id", s.deleteToken)
g.GET("/sso", s.ssoLookup)
g.GET("/sso/callback", s.ssoCallback)
diff --git a/internal/api/sso.go b/internal/api/sso.go
index 252e9b5..7dbb1ce 100644
--- a/internal/api/sso.go
+++ b/internal/api/sso.go
@@ -23,6 +23,9 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/web"
)
+// viewerRoleID is the built-in Viewer role seeded by migration 00009.
+var viewerRoleID = uuid.MustParse("00000000-0000-0000-0000-00000000a003")
+
const (
ssoCookie = "__Host-sso"
ssoFlowTTL = 10 * time.Minute
@@ -262,7 +265,9 @@ func (s *Server) ssoCallback(c *gin.Context) {
if locale == "" {
locale = i18n.Lang(ctx)
}
- sess, err := s.sessions.Create(ctx, userID, row.OrgID, locale)
+ sess, err := s.sessions.Create(ctx, auth.NewSession{
+ UserID: userID, OrgID: row.OrgID, Locale: locale, Method: auth.MethodSSO, SSOOrg: row.OrgID,
+ })
if err != nil {
internalError(c, err)
return
@@ -322,6 +327,13 @@ func (s *Server) ssoResolveUser(ctx context.Context, row store.SsoProvider, cl s
if err := q.AddMembership(ctx, store.AddMembershipParams{OrgID: row.OrgID, UserID: u.ID}); err != nil {
return err
}
+ role := viewerRoleID
+ if row.DefaultRoleID != nil {
+ role = *row.DefaultRoleID
+ }
+ if _, err := q.CreateAssignment(ctx, store.CreateAssignmentParams{OrgID: row.OrgID, UserID: u.ID, RoleID: role}); err != nil {
+ return err
+ }
userID = u.ID
return q.CreateIdentity(ctx, store.CreateIdentityParams{ProviderID: row.ID, Subject: cl.Subject, OrgID: row.OrgID, UserID: u.ID, Email: nonEmpty(email)})
})
diff --git a/internal/api/sso_admin.go b/internal/api/sso_admin.go
index 5d72986..98146a8 100644
--- a/internal/api/sso_admin.go
+++ b/internal/api/sso_admin.go
@@ -11,62 +11,29 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
- "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
"git.zb-server.de/ZB-Server/uptimesebi/internal/sso"
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
- "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
)
-const ctxOrgKey = "api.org"
-
-// requireOwner admits only the owner of the session's active org. It is a
-// stand-in until role-based permissions exist (#6).
-func (s *Server) requireOwner() gin.HandlerFunc {
- return func(c *gin.Context) {
- sess := auth.Current(c)
- if sess == nil || sess.OrgID == uuid.Nil {
- fail(c, http.StatusForbidden, "forbidden")
- return
- }
- ctx := c.Request.Context()
- var m store.Membership
- err := s.db.Tx(ctx, tenant.Org(sess.OrgID, sess.UserID), func(q *store.Queries) error {
- var err error
- m, err = q.GetMembership(ctx, store.GetMembershipParams{OrgID: sess.OrgID, UserID: sess.UserID})
- return err
- })
- if errors.Is(err, pgx.ErrNoRows) || (err == nil && !m.IsOwner) {
- fail(c, http.StatusForbidden, "forbidden")
- return
- }
- if err != nil {
- internalError(c, err)
- return
- }
- c.Set(ctxOrgKey, sess.OrgID)
- c.Next()
- }
-}
-
-func orgOf(c *gin.Context) uuid.UUID { return c.MustGet(ctxOrgKey).(uuid.UUID) }
-
type ssoProviderView struct {
- ID uuid.UUID `json:"id"`
- Name string `json:"name"`
- Issuer string `json:"issuer"`
- ClientID string `json:"client_id"`
- HasClientSecret bool `json:"has_client_secret"`
- Scopes []string `json:"scopes"`
- AllowedDomains []string `json:"allowed_domains"`
- AutoProvision bool `json:"auto_provision"`
- Enabled bool `json:"enabled"`
+ ID uuid.UUID `json:"id"`
+ Name string `json:"name"`
+ Issuer string `json:"issuer"`
+ ClientID string `json:"client_id"`
+ HasClientSecret bool `json:"has_client_secret"`
+ Scopes []string `json:"scopes"`
+ AllowedDomains []string `json:"allowed_domains"`
+ AutoProvision bool `json:"auto_provision"`
+ DefaultRoleID *uuid.UUID `json:"default_role_id"`
+ Enabled bool `json:"enabled"`
}
func viewSSOProvider(p store.SsoProvider) ssoProviderView {
return ssoProviderView{
ID: p.ID, Name: p.Name, Issuer: p.Issuer, ClientID: p.ClientID,
HasClientSecret: p.ClientSecret != nil, Scopes: p.Scopes,
- AllowedDomains: p.AllowedDomains, AutoProvision: p.AutoProvision, Enabled: p.Enabled,
+ AllowedDomains: p.AllowedDomains, AutoProvision: p.AutoProvision, DefaultRoleID: p.DefaultRoleID, Enabled: p.Enabled,
}
}
@@ -79,7 +46,9 @@ type ssoProviderRequest struct {
Scopes []string `json:"scopes" binding:"max=20,dive,max=100"`
AllowedDomains []string `json:"allowed_domains" binding:"max=50,dive,max=253"`
AutoProvision bool `json:"auto_provision"`
- Enabled *bool `json:"enabled"`
+ // DefaultRoleID is assigned to auto-provisioned users; nil means Viewer.
+ DefaultRoleID *uuid.UUID `json:"default_role_id"`
+ Enabled *bool `json:"enabled"`
}
var domainRE = regexp.MustCompile(`^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$`)
@@ -122,7 +91,7 @@ func (r *ssoProviderRequest) normalize() string {
func (s *Server) listSSOProviders(c *gin.Context) {
ctx := c.Request.Context()
var rows []store.SsoProvider
- err := s.db.Tx(ctx, tenant.Org(orgOf(c), auth.Current(c).UserID), func(q *store.Queries) error {
+ err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
rows, err = q.ListSSOProviders(ctx)
return err
@@ -143,6 +112,28 @@ func (s *Server) validateSSORequest(c *gin.Context, req *ssoProviderRequest) boo
fail(c, http.StatusUnprocessableEntity, code)
return false
}
+ if req.DefaultRoleID != nil {
+ ctx := c.Request.Context()
+ var role store.Role
+ err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
+ var err error
+ role, err = q.GetRole(ctx, *req.DefaultRoleID)
+ return err
+ })
+ if errors.Is(err, pgx.ErrNoRows) {
+ fail(c, http.StatusUnprocessableEntity, "role_not_found")
+ return false
+ }
+ if err != nil {
+ internalError(c, err)
+ return false
+ }
+ // Auto-provisioning hands this role to anyone the IdP vouches for.
+ if !current(c).Grants.CanGrant(authz.NewSet(role.Permissions...), nil) {
+ fail(c, http.StatusForbidden, "permission_escalation")
+ return false
+ }
+ }
if err := s.sso.ValidateIssuer(c.Request.Context(), req.Issuer); err != nil {
code := "sso_discovery_failed"
switch {
@@ -169,12 +160,12 @@ func (s *Server) createSSOProvider(c *gin.Context) {
secret = s.keys.Seal([]byte(req.ClientSecret), id[:])
}
var row store.SsoProvider
- err := s.db.Tx(ctx, tenant.Org(orgOf(c), auth.Current(c).UserID), func(q *store.Queries) error {
+ err := s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
row, err = q.CreateSSOProvider(ctx, store.CreateSSOProviderParams{
- ID: id, OrgID: orgOf(c), Name: req.Name, Issuer: req.Issuer, ClientID: req.ClientID,
+ ID: id, OrgID: current(c).Org.ID, Name: req.Name, Issuer: req.Issuer, ClientID: req.ClientID,
ClientSecret: secret, Scopes: req.Scopes, AllowedDomains: req.AllowedDomains,
- AutoProvision: req.AutoProvision, Enabled: req.Enabled == nil || *req.Enabled,
+ AutoProvision: req.AutoProvision, DefaultRoleID: req.DefaultRoleID, Enabled: req.Enabled == nil || *req.Enabled,
})
return err
})
@@ -201,12 +192,12 @@ func (s *Server) updateSSOProvider(c *gin.Context) {
secret = s.keys.Seal([]byte(req.ClientSecret), id[:])
}
var row store.SsoProvider
- err = s.db.Tx(ctx, tenant.Org(orgOf(c), auth.Current(c).UserID), func(q *store.Queries) error {
+ err = s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
row, err = q.UpdateSSOProvider(ctx, store.UpdateSSOProviderParams{
ID: id, Name: req.Name, Issuer: req.Issuer, ClientID: req.ClientID, ClientSecret: secret,
Scopes: req.Scopes, AllowedDomains: req.AllowedDomains, AutoProvision: req.AutoProvision,
- Enabled: req.Enabled == nil || *req.Enabled,
+ DefaultRoleID: req.DefaultRoleID, Enabled: req.Enabled == nil || *req.Enabled,
})
return err
})
@@ -229,7 +220,7 @@ func (s *Server) deleteSSOProvider(c *gin.Context) {
}
ctx := c.Request.Context()
var n int64
- err = s.db.Tx(ctx, tenant.Org(orgOf(c), auth.Current(c).UserID), func(q *store.Queries) error {
+ err = s.db.Tx(ctx, current(c).scope(), func(q *store.Queries) error {
var err error
n, err = q.DeleteSSOProvider(ctx, id)
return err
diff --git a/internal/api/sso_test.go b/internal/api/sso_test.go
index 0c3ace2..1803ad3 100644
--- a/internal/api/sso_test.go
+++ b/internal/api/sso_test.go
@@ -99,6 +99,8 @@ type browser struct {
base string
hc *http.Client
csrf string
+ // bearer, if set, is sent as an API token instead of relying on cookies.
+ bearer string
}
func (e *env) browser(t *testing.T) *browser {
@@ -121,6 +123,9 @@ func (b *browser) do(method, path string, body any) (int, map[string]any) {
if b.csrf != "" {
req.Header.Set("X-CSRF-Token", b.csrf)
}
+ if b.bearer != "" {
+ req.Header.Set("Authorization", "Bearer "+b.bearer)
+ }
resp, err := b.hc.Do(req)
if err != nil {
b.t.Fatalf("%s %s failed: %v", method, path, err)
@@ -142,6 +147,9 @@ func (b *browser) visit(path string) *url.URL {
b.t.Fatalf("GET %s failed: %v", path, err)
}
_ = resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ b.t.Errorf("GET %s ended with status %d at %s", path, resp.StatusCode, resp.Request.URL)
+ }
return resp.Request.URL
}
diff --git a/internal/api/tokens.go b/internal/api/tokens.go
new file mode 100644
index 0000000..d4bc51b
--- /dev/null
+++ b/internal/api/tokens.go
@@ -0,0 +1,206 @@
+package api
+
+import (
+ "context"
+ "crypto/sha256"
+ "errors"
+ "net/http"
+ "strings"
+ "time"
+
+ "github.com/gin-gonic/gin"
+ "github.com/google/uuid"
+ "github.com/jackc/pgx/v5"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/store"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant"
+)
+
+// tokenPrefix makes tokens recognizable to secret scanners and to humans.
+const tokenPrefix = "ust_"
+
+func hashToken(tok string) []byte {
+ sum := sha256.Sum256([]byte(tok))
+ return sum[:]
+}
+
+func bearerToken(c *gin.Context) string {
+ h := c.GetHeader("Authorization")
+ if len(h) < 7 || !strings.EqualFold(h[:7], "bearer ") {
+ return ""
+ }
+ return strings.TrimSpace(h[7:])
+}
+
+func (s *Server) tokenPrincipal(ctx context.Context, tok string) (*principal, int, string, error) {
+ if !strings.HasPrefix(tok, tokenPrefix) {
+ return nil, http.StatusUnauthorized, "unauthenticated", nil
+ }
+ hash := hashToken(tok)
+ var org uuid.UUID
+ err := s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error {
+ var err error
+ org, err = q.APITokenOrg(ctx, hash)
+ return err
+ })
+ if err != nil {
+ return nil, 0, "", err
+ }
+ if org == uuid.Nil {
+ return nil, http.StatusUnauthorized, "unauthenticated", nil
+ }
+ p := &principal{}
+ var (
+ row store.ApiToken
+ member bool
+ )
+ err = s.db.Tx(ctx, tenant.Org(org, uuid.Nil), func(q *store.Queries) error {
+ var err error
+ if row, err = q.GetAPITokenByHash(ctx, hash); err != nil {
+ return err
+ }
+ if row.ExpiresAt != nil && !row.ExpiresAt.After(time.Now()) {
+ return nil
+ }
+ if p.Org, err = q.GetOrg(ctx, org); err != nil {
+ return err
+ }
+ if p.Grants, member, err = loadGrants(ctx, q, org, row.UserID); err != nil || !member {
+ return err
+ }
+ return q.TouchAPIToken(ctx, row.ID)
+ })
+ if errors.Is(err, pgx.ErrNoRows) || (err == nil && !member) {
+ return nil, http.StatusUnauthorized, "unauthenticated", nil
+ }
+ if err != nil {
+ return nil, 0, "", err
+ }
+ p.UserID, p.TokenID = row.UserID, row.ID
+ p.Grants = p.Grants.Restrict(authz.NewSet(row.Permissions...))
+ return p, 0, "", nil
+}
+
+type tokenView struct {
+ ID uuid.UUID `json:"id"`
+ Name string `json:"name"`
+ Prefix string `json:"prefix"`
+ UserID uuid.UUID `json:"user_id"`
+ UserEmail string `json:"user_email"`
+ Permissions []string `json:"permissions"`
+ ExpiresAt *time.Time `json:"expires_at"`
+ LastUsedAt *time.Time `json:"last_used_at"`
+ CreatedAt time.Time `json:"created_at"`
+}
+
+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.
+ var filter *uuid.UUID
+ if !p.Grants.Can(authz.MembersManage) {
+ filter = &p.UserID
+ }
+ var rows []store.ListAPITokensRow
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ rows, err = q.ListAPITokens(ctx, store.ListAPITokensParams{OrgID: p.Org.ID, UserID: filter})
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ out := make([]tokenView, len(rows))
+ for i, r := range rows {
+ out[i] = tokenView{
+ ID: r.ID, Name: r.Name, Prefix: r.Prefix, UserID: r.UserID, UserEmail: r.UserEmail,
+ Permissions: r.Permissions, ExpiresAt: r.ExpiresAt, LastUsedAt: r.LastUsedAt, CreatedAt: r.CreatedAt,
+ }
+ }
+ c.JSON(http.StatusOK, gin.H{"tokens": out})
+}
+
+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 int `json:"expires_in_days" binding:"min=0,max=3650"`
+}
+
+func (s *Server) createToken(c *gin.Context) {
+ var req createTokenRequest
+ if !bind(c, &req) {
+ return
+ }
+ p := current(c)
+ perms := authz.NewSet(req.Permissions...)
+ if len(perms) == 0 {
+ fail(c, http.StatusUnprocessableEntity, "invalid_permissions")
+ return
+ }
+ if !p.Grants.CanGrant(perms, nil) {
+ fail(c, http.StatusForbidden, "permission_escalation")
+ return
+ }
+ var expires *time.Time
+ if req.ExpiresInDays > 0 {
+ t := time.Now().AddDate(0, 0, req.ExpiresInDays)
+ expires = &t
+ }
+ tok := tokenPrefix + auth.RandomToken()
+ ctx := c.Request.Context()
+ var row store.ApiToken
+ err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ var err error
+ row, err = q.CreateAPIToken(ctx, store.CreateAPITokenParams{
+ OrgID: p.Org.ID, UserID: p.UserID, Name: strings.TrimSpace(req.Name),
+ TokenHash: hashToken(tok), Prefix: tok[:len(tokenPrefix)+6],
+ Permissions: perms.Strings(), ExpiresAt: expires,
+ })
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ c.JSON(http.StatusCreated, gin.H{"id": row.ID, "token": tok, "prefix": row.Prefix, "permissions": row.Permissions})
+}
+
+func (s *Server) deleteToken(c *gin.Context) {
+ id, err := uuid.Parse(c.Param("id"))
+ if err != nil {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ p := current(c)
+ ctx := c.Request.Context()
+ var found bool
+ err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
+ row, err := q.GetAPIToken(ctx, id)
+ if errors.Is(err, pgx.ErrNoRows) {
+ return nil
+ }
+ if err != nil {
+ return err
+ }
+ if row.UserID != p.UserID && !p.Grants.Can(authz.MembersManage) {
+ return nil
+ }
+ found = true
+ _, err = q.DeleteAPIToken(ctx, id)
+ return err
+ })
+ if err != nil {
+ internalError(c, err)
+ return
+ }
+ if !found {
+ fail(c, http.StatusNotFound, "not_found")
+ return
+ }
+ c.Status(http.StatusNoContent)
+}
diff --git a/internal/i18n/i18n_test.go b/internal/i18n/i18n_test.go
index c59d879..419cb84 100644
--- a/internal/i18n/i18n_test.go
+++ b/internal/i18n/i18n_test.go
@@ -10,6 +10,8 @@ import (
"sort"
"strings"
"testing"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
)
func catalogKeys(t *testing.T) map[string]map[string]bool {
@@ -57,13 +59,19 @@ func TestCatalogsHaveSameKeys(t *testing.T) {
var usagePatterns = []struct {
re *regexp.Regexp
prefix string
+ // dir limits the pattern to files below this directory.
+ dir string
}{
- {regexp.MustCompile(`i18n\.T\(ctx, "([a-z0-9_.]+)"[,)]`), ""},
- {regexp.MustCompile(`\bfail\(c, [^,]+, "([a-z_]+)"`), "error."},
- {regexp.MustCompile(`\b(?:pageFor\(c|s\.page\()(?:, )?"([a-z0-9_.]+)"`), ""},
- {regexp.MustCompile(`[^(]"(sso_[a-z_]+)"`), "error."},
- {regexp.MustCompile(`return "(invalid_[a-z_]+)"`), "error."},
- {regexp.MustCompile(`NoticeID = "([a-z0-9_.]+)"`), ""},
+ {re: regexp.MustCompile(`i18n\.T\(ctx, "([a-z0-9_.]+)"[,)]`)},
+ {re: regexp.MustCompile(`\bfail\(c, [^,]+, "([a-z_]+)"`), prefix: "error."},
+ {re: regexp.MustCompile(`\b(?:pageFor\(c|s\.page\(|s\.orgPage\()(?:, )?"([a-z0-9_.]+)"`)},
+ {re: regexp.MustCompile(`[^(]"(sso_[a-z_]+)"`), prefix: "error.", dir: "api"},
+ {re: regexp.MustCompile(`return "(invalid_[a-z_]+)"`), prefix: "error."},
+ {re: regexp.MustCompile(`code = "([a-z_]+)"`), prefix: "error."},
+ {re: regexp.MustCompile(`NoticeID = "([a-z0-9_.]+)"`)},
+ {re: regexp.MustCompile(`@(?:settingsHeading|sectionHeading)\("([a-z0-9_.]+)"`)},
+ {re: regexp.MustCompile(`@settingsHeading\("[a-z0-9_.]+", "([a-z0-9_.]+)"`)},
+ {re: regexp.MustCompile(`@policyBanner\("([a-z0-9_.]+)", "([a-z0-9_.]+)"`)},
}
// TestUsedKeysExist scans the source tree for literal message IDs so a typo
@@ -86,9 +94,14 @@ func TestUsedKeysExist(t *testing.T) {
return err
}
for _, u := range usagePatterns {
+ if u.dir != "" && !strings.Contains(filepath.ToSlash(p), "/"+u.dir+"/") {
+ continue
+ }
for _, m := range u.re.FindAllStringSubmatch(string(src), -1) {
- if id := u.prefix + m[1]; !en[id] {
- missing = append(missing, p+": "+id)
+ for _, id := range m[1:] {
+ if id := u.prefix + id; !en[id] {
+ missing = append(missing, p+": "+id)
+ }
}
}
}
@@ -103,6 +116,22 @@ func TestUsedKeysExist(t *testing.T) {
}
}
+// Permission and scope labels are looked up as "perm." and
+// "scope.".
+func TestEveryPermissionHasALabel(t *testing.T) {
+ en := catalogKeys(t)["en"]
+ for _, p := range authz.All {
+ if !en["perm."+string(p)] {
+ t.Errorf("en.json is missing %q", "perm."+string(p))
+ }
+ }
+ for _, rt := range []authz.ResourceType{authz.MonitorGroup, authz.StatusPage} {
+ if !en["scope."+string(rt)] {
+ t.Errorf("en.json is missing %q", "scope."+string(rt))
+ }
+ }
+}
+
// The language switcher builds "lang." dynamically.
func TestEveryLanguageHasAName(t *testing.T) {
c, err := Load()
diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json
index e0648c5..16c5876 100644
--- a/internal/i18n/locales/de.json
+++ b/internal/i18n/locales/de.json
@@ -24,24 +24,43 @@
"console.monitors.empty": "Noch keine Monitore angelegt.",
"console.monitors.title": "Monitore",
"console.nav.logout": "Abmelden",
+ "console.nav.members": "Mitglieder",
+ "console.nav.org": "Organisation",
+ "console.nav.roles": "Rollen",
"console.nav.security": "Sicherheit",
"console.nav.sso": "SSO",
- "console.totp_missing": "Deine Organisation verlangt Zwei-Faktor-Anmeldung.",
+ "console.nav.tokens": "API-Tokens",
+ "console.sso_required_action": "Mit SSO anmelden",
"console.totp_missing_action": "Jetzt einrichten",
+ "error.already_assigned": "Das Mitglied hat diese Rolle bereits.",
+ "error.already_member": "Diese Person ist bereits Mitglied.",
"error.email_taken": "Diese E-Mail-Adresse ist bereits registriert.",
"error.forbidden": "Dafür fehlt dir die Berechtigung.",
"error.internal": "Interner Fehler.",
"error.invalid_code": "Code ungültig.",
"error.invalid_credentials": "E-Mail oder Passwort falsch.",
"error.invalid_domain": "Eine der Domains ist ungültig.",
+ "error.invalid_email": "Bitte eine gültige E-Mail-Adresse eingeben.",
"error.invalid_input": "Eingaben prüfen.",
+ "error.invalid_permissions": "Mindestens eine Berechtigung auswählen.",
"error.invalid_slug": "Kurzname: 2–63 Zeichen, a–z, 0–9 und Bindestrich.",
+ "error.invitation_email_mismatch": "Diese Einladung ging an eine andere E-Mail-Adresse als die, mit der du angemeldet bist.",
+ "error.invitation_invalid": "Diese Einladung ist ungültig, abgelaufen oder wurde bereits verwendet.",
"error.mfa_expired": "Anmeldung abgelaufen, bitte erneut anmelden.",
"error.no_password": "Konto ohne Passwort.",
"error.not_found": "Nicht gefunden.",
"error.org_not_found": "Organisation nicht gefunden.",
+ "error.owner_cannot_be_removed": "Der Owner kann nicht entfernt werden.",
+ "error.owner_has_all_permissions": "Der Owner hat bereits alle Berechtigungen.",
"error.password_too_short": "Das Passwort braucht mindestens {{.Min}} Zeichen.",
+ "error.permission_escalation": "Du kannst keine Berechtigungen vergeben, die du selbst nicht hast.",
+ "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.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.",
+ "error.role_not_found": "Rolle nicht gefunden.",
+ "error.session_required": "Diese Aktion ist für API-Tokens nicht verfügbar.",
"error.signup_closed": "Registrierung ist deaktiviert.",
"error.slug_taken": "Dieser Kurzname ist bereits vergeben.",
"error.sso_denied": "Die Anmeldung wurde beim Identity Provider abgebrochen.",
@@ -51,16 +70,64 @@
"error.sso_identity_taken": "Diese SSO-Anmeldung ist bereits mit einem anderen Konto verknüpft.",
"error.sso_invalid_issuer": "Der Issuer muss eine https-URL ohne Query und Zugangsdaten sein.",
"error.sso_link_required": "Es gibt bereits ein Konto mit dieser E-Mail. Melde dich mit Passwort an und verknüpfe SSO unter Sicherheit.",
+ "error.sso_no_provider": "Lege zuerst einen SSO-Provider an und aktiviere ihn.",
"error.sso_not_member": "Dein Konto ist kein Mitglied dieser Organisation.",
"error.sso_not_provisioned": "Für diese Anmeldung gibt es kein Konto. Bitte lass dich von einem Admin einladen.",
"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.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.",
+ "error.unauthenticated": "Anmeldung erforderlich.",
"error.unsupported_locale": "Sprache wird nicht unterstützt.",
+ "invite.accept": "Einladung annehmen",
+ "invite.create_account": "Konto anlegen und beitreten",
+ "invite.sign_in": "Zum Annehmen anmelden",
+ "invite.summary": "Du bist eingeladen, {{.Org}} als {{.Role}} beizutreten.",
+ "invite.title": "Einladung",
"lang.de": "Deutsch",
"lang.en": "English",
+ "members.assign": "Rolle hinzufügen",
+ "members.intro": "Rollen bestimmen, was ein Mitglied darf. Niemand kann Berechtigungen vergeben, die er selbst nicht hat.",
+ "members.invite": "Einladen",
+ "members.invite_link": "Schicke diesen Link an die eingeladene Person. Er gilt 7 Tage und funktioniert einmal.",
+ "members.invite_submit": "Einladung erstellen",
+ "members.owner": "Owner",
+ "members.pending": "Offene Einladungen",
+ "members.remove": "Aus der Organisation entfernen",
+ "members.remove_confirm": "Dieses Mitglied entfernen? Seine Sessions und API-Tokens enden sofort.",
+ "members.revoke": "Widerrufen",
+ "members.role": "Rolle",
+ "members.roles": "Rollen",
+ "members.title": "Mitglieder",
+ "members.unassign": "Rolle entfernen",
+ "org.policy": "Anmelderichtlinie",
+ "org.require_sso": "SSO verlangen",
+ "org.require_sso_hint": "Mitglieder müssen sich über den Identity Provider dieser Organisation anmelden. Der Owner kann weiterhin ein Passwort nutzen, damit ein defekter IdP euch nicht aussperrt.",
+ "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",
+ "perm.incidents.read": "Incidents sehen",
+ "perm.incidents.write": "Incidents verwalten",
+ "perm.members.manage": "Mitglieder einladen und verwalten",
+ "perm.members.read": "Mitglieder und Rollen sehen",
+ "perm.monitors.read": "Monitore sehen",
+ "perm.monitors.write": "Monitore bearbeiten",
+ "perm.notifications.read": "Benachrichtigungskanäle sehen",
+ "perm.notifications.write": "Benachrichtigungskanäle bearbeiten",
+ "perm.org.manage": "Organisation und SSO verwalten",
+ "perm.roles.manage": "Eigene Rollen verwalten",
+ "perm.statuspages.read": "Statuspages sehen",
+ "perm.statuspages.write": "Statuspages bearbeiten",
+ "roles.built_in": "eingebaut",
+ "roles.create": "Rolle anlegen",
+ "roles.delete": "Rolle löschen",
+ "roles.delete_confirm": "Diese Rolle löschen?",
+ "roles.intro": "Eingebaute Rollen decken die üblichen Fälle ab. Eigene Rollen kombinieren einzelne Berechtigungen.",
+ "roles.title": "Rollen",
+ "scope.monitor_group": "Monitor-Gruppe",
+ "scope.status_page": "Statuspage",
"security.recovery.left": {
"one": "{{.Count}} Wiederherstellungscode übrig",
"other": "{{.Count}} Wiederherstellungscodes übrig"
@@ -92,6 +159,8 @@
"sso.field.client_id": "Client-ID",
"sso.field.client_secret": "Client-Secret",
"sso.field.client_secret_keep": "unverändert",
+ "sso.field.default_role": "Rolle für neue Konten",
+ "sso.field.default_role_viewer": "Viewer (Standard)",
"sso.field.enabled": "Aktiv",
"sso.field.issuer": "Issuer-URL",
"sso.field.name": "Name",
@@ -99,5 +168,18 @@
"sso.settings.intro": "Mitglieder dieser Organisation können sich über euren eigenen OpenID-Connect-Identity-Provider anmelden. Tragt die Redirect-URL unten bei eurem Provider als erlaubten Callback ein.",
"sso.settings.login_url": "Anmelde-URL",
"sso.settings.redirect_url": "Redirect-URL",
- "sso.settings.title": "Single Sign-on"
+ "sso.settings.title": "Single Sign-on",
+ "tokens.copy_now": "Kopiere den Token jetzt. Er wird nicht erneut angezeigt.",
+ "tokens.create": "Token erstellen",
+ "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.last_used": "Zuletzt genutzt",
+ "tokens.never": "nie",
+ "tokens.owner": "Inhaber",
+ "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 9ca4d53..3c38f82 100644
--- a/internal/i18n/locales/en.json
+++ b/internal/i18n/locales/en.json
@@ -24,24 +24,43 @@
"console.monitors.empty": "No monitors yet.",
"console.monitors.title": "Monitors",
"console.nav.logout": "Sign out",
+ "console.nav.members": "Members",
+ "console.nav.org": "Organization",
+ "console.nav.roles": "Roles",
"console.nav.security": "Security",
"console.nav.sso": "SSO",
- "console.totp_missing": "Your organization requires two-factor sign-in.",
+ "console.nav.tokens": "API tokens",
+ "console.sso_required_action": "Sign in with SSO",
"console.totp_missing_action": "Set up now",
+ "error.already_assigned": "The member already has this role.",
+ "error.already_member": "This person is already a member.",
"error.email_taken": "This email address is already registered.",
"error.forbidden": "You are not allowed to do this.",
"error.internal": "Internal error.",
"error.invalid_code": "Invalid code.",
"error.invalid_credentials": "Wrong email or password.",
"error.invalid_domain": "One of the domains is not valid.",
+ "error.invalid_email": "Please enter a valid email address.",
"error.invalid_input": "Please check your input.",
+ "error.invalid_permissions": "Choose at least one permission.",
"error.invalid_slug": "Short name: 2–63 characters, a–z, 0–9 and hyphen.",
+ "error.invitation_email_mismatch": "This invitation was sent to a different email address than the one you are signed in with.",
+ "error.invitation_invalid": "This invitation is invalid, expired or was already used.",
"error.mfa_expired": "Sign-in expired, please start again.",
"error.no_password": "This account has no password.",
"error.not_found": "Not found.",
"error.org_not_found": "Organization not found.",
+ "error.owner_cannot_be_removed": "The owner cannot be removed.",
+ "error.owner_has_all_permissions": "The owner already has every permission.",
"error.password_too_short": "The password needs at least {{.Min}} characters.",
+ "error.permission_escalation": "You cannot grant permissions you do not hold yourself.",
+ "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.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.",
+ "error.role_not_found": "Role not found.",
+ "error.session_required": "This action is not available to API tokens.",
"error.signup_closed": "Sign-up is disabled.",
"error.slug_taken": "This short name is already taken.",
"error.sso_denied": "Sign-in was cancelled at the identity provider.",
@@ -51,16 +70,64 @@
"error.sso_identity_taken": "This SSO sign-in is already linked to another account.",
"error.sso_invalid_issuer": "The issuer must be an https URL without query or credentials.",
"error.sso_link_required": "An account with this email already exists. Sign in with your password and link SSO under Security.",
+ "error.sso_no_provider": "Add and enable an SSO provider first.",
"error.sso_not_member": "Your account is not a member of this organization.",
"error.sso_not_provisioned": "No account exists for this sign-in. Ask an administrator to invite you.",
"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.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.",
+ "error.unauthenticated": "Authentication required.",
"error.unsupported_locale": "Unsupported language.",
+ "invite.accept": "Accept invitation",
+ "invite.create_account": "Create account and join",
+ "invite.sign_in": "Sign in to accept",
+ "invite.summary": "You are invited to join {{.Org}} as {{.Role}}.",
+ "invite.title": "Invitation",
"lang.de": "Deutsch",
"lang.en": "English",
+ "members.assign": "Add role",
+ "members.intro": "Roles decide what each member may do. Nobody can grant permissions they do not hold themselves.",
+ "members.invite": "Invite",
+ "members.invite_link": "Send this link to the invitee. It is valid for 7 days and works once.",
+ "members.invite_submit": "Create invitation",
+ "members.owner": "Owner",
+ "members.pending": "Pending invitations",
+ "members.remove": "Remove from organization",
+ "members.remove_confirm": "Remove this member? Their sessions and API tokens end immediately.",
+ "members.revoke": "Revoke",
+ "members.role": "Role",
+ "members.roles": "Roles",
+ "members.title": "Members",
+ "members.unassign": "Remove role",
+ "org.policy": "Sign-in policy",
+ "org.require_sso": "Require SSO",
+ "org.require_sso_hint": "Members must sign in through this organization's identity provider. The owner can still use a password so a broken IdP cannot lock you out.",
+ "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",
+ "perm.incidents.read": "View incidents",
+ "perm.incidents.write": "Manage incidents",
+ "perm.members.manage": "Invite and manage members",
+ "perm.members.read": "View members and roles",
+ "perm.monitors.read": "View monitors",
+ "perm.monitors.write": "Edit monitors",
+ "perm.notifications.read": "View notification channels",
+ "perm.notifications.write": "Edit notification channels",
+ "perm.org.manage": "Manage organization and SSO",
+ "perm.roles.manage": "Manage custom roles",
+ "perm.statuspages.read": "View status pages",
+ "perm.statuspages.write": "Edit status pages",
+ "roles.built_in": "built-in",
+ "roles.create": "Create role",
+ "roles.delete": "Delete role",
+ "roles.delete_confirm": "Delete this role?",
+ "roles.intro": "Built-in roles cover common cases. Custom roles combine individual permissions.",
+ "roles.title": "Roles",
+ "scope.monitor_group": "monitor group",
+ "scope.status_page": "status page",
"security.recovery.left": {
"one": "{{.Count}} recovery code left",
"other": "{{.Count}} recovery codes left"
@@ -92,6 +159,8 @@
"sso.field.client_id": "Client ID",
"sso.field.client_secret": "Client secret",
"sso.field.client_secret_keep": "unchanged",
+ "sso.field.default_role": "Role for new accounts",
+ "sso.field.default_role_viewer": "Viewer (default)",
"sso.field.enabled": "Enabled",
"sso.field.issuer": "Issuer URL",
"sso.field.name": "Name",
@@ -99,5 +168,18 @@
"sso.settings.intro": "Members of this organization can sign in through your own OpenID Connect identity provider. Register the redirect URL below as an allowed callback at your provider.",
"sso.settings.login_url": "Sign-in URL",
"sso.settings.redirect_url": "Redirect URL",
- "sso.settings.title": "Single sign-on"
+ "sso.settings.title": "Single sign-on",
+ "tokens.copy_now": "Copy the token now. It will not be shown again.",
+ "tokens.create": "Create token",
+ "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.last_used": "Last used",
+ "tokens.never": "never",
+ "tokens.owner": "Owner",
+ "tokens.revoke_confirm": "Revoke this token? Requests using it fail immediately.",
+ "tokens.title": "API tokens"
}
diff --git a/internal/web/assets/app.js b/internal/web/assets/app.js
index a95524c..fc5e927 100644
--- a/internal/web/assets/app.js
+++ b/internal/web/assets/app.js
@@ -17,13 +17,22 @@
el.classList.toggle("hidden", !text);
};
- // Inputs inside a hidden [data-step] are skipped, checkboxes become
- // booleans and [data-list] inputs become comma-separated arrays.
+ // Inputs inside a hidden [data-step] are skipped. Checkboxes become
+ // booleans, or arrays of values with [data-multi]; [data-list] inputs are
+ // split on commas, [data-number] parsed and empty [data-nullable] sent as null.
const serialize = (form) => {
const out = {};
for (const el of form.elements) {
- if (!el.name || el.disabled || el.closest("[data-step]")?.hidden) continue;
+ if (!el.name || el.closest("[data-step]")?.hidden) continue;
+ if (el.dataset.multi !== undefined) {
+ out[el.name] ??= [];
+ if (el.checked && !el.disabled) out[el.name].push(el.value);
+ continue;
+ }
+ if (el.disabled) continue;
if (el.type === "checkbox") out[el.name] = el.checked;
+ else if (el.dataset.number !== undefined) out[el.name] = Number(el.value);
+ else if (el.dataset.nullable !== undefined) out[el.name] = el.value || null;
else if (el.dataset.list !== undefined)
out[el.name] = el.value.split(",").map((v) => v.trim()).filter(Boolean);
else out[el.name] = el.value;
@@ -54,6 +63,14 @@
out.hidden = false;
return;
}
+ if (form.dataset.showLink !== undefined && (res.data?.url || res.data?.token)) {
+ const out = form.querySelector("[data-link-output]");
+ const input = out.querySelector("[data-link]");
+ input.value = res.data.url || res.data.token;
+ out.hidden = false;
+ input.select();
+ return;
+ }
if (res.data?.status === "totp_required" && totpStep) {
form.querySelector('[data-step="password"]').hidden = true;
totpStep.hidden = false;
diff --git a/internal/web/auth.templ b/internal/web/auth.templ
index 14d9f59..fbf5b84 100644
--- a/internal/web/auth.templ
+++ b/internal/web/auth.templ
@@ -5,9 +5,9 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
-templ Login(p Page, signupAllowed bool) {
+templ Login(p Page, signupAllowed bool, next string) {
@authShell(p) {
-
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
- templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var12), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var14), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -349,7 +397,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Var16 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_Var18 := 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 {
@@ -361,51 +409,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "")
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, "security.title"))
+ var templ_7745c5c3_Var19 string
+ templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 82, Col: 72}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 92, Col: 72}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
+ _, 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, 27, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, " ")
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, "security.totp.heading"))
+ var templ_7745c5c3_Var20 string
+ templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.heading"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 84, Col: 114}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 94, Col: 114}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
+ _, 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, 28, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if me.TOTP {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "● ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "
● ")
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, "security.totp.active"))
+ var templ_7745c5c3_Var21 string
+ templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.active"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 86, Col: 98}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 96, Col: 98}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
+ _, 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, 30, "
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -413,25 +461,25 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
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, 31, "= 3)}
- templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var20...)
+ var templ_7745c5c3_Var22 = []any{"mb-6 text-sm", templ.KV("text-down", me.RecoveryCodesLeft < 3), templ.KV("text-muted", me.RecoveryCodesLeft >= 3)}
+ templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var22...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var21 string
- templ_7745c5c3_Var21, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var20).String()).Resolve(ctx)
+ var templ_7745c5c3_Var23 string
+ templ_7745c5c3_Var23, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var22).String()).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 1, Col: 0}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var23)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "\"")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -445,33 +493,33 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
}
templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, ">")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, ">")
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, "security.recovery.left", "Count", me.RecoveryCodesLeft))
+ var templ_7745c5c3_Var24 string
+ templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.left", "Count", me.RecoveryCodesLeft))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 88, Col: 75}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 98, Col: 75}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
+ _, 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, 34, "
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var23 string
- templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate"))
+ var templ_7745c5c3_Var25 string
+ templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 91, Col: 116}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 101, Col: 116}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
+ _, 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, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -495,20 +543,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var24 string
- templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable"))
+ var templ_7745c5c3_Var26 string
+ templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.disable"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 101, Col: 109}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 111, Col: 109}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
+ _, 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, 37, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -528,51 +576,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "● ")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var25 string
- templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive"))
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 110, Col: 105}
- }
- _, 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, 40, "
")
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var26 string
- templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.start"))
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 112, Col: 141}
- }
- _, 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, 41, " ● ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var27 string
- templ_7745c5c3_Var27, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "security.totp.qr_alt")).Resolve(ctx)
+ templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 114, Col: 65}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 120, Col: 105}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var27)
+ _, 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, 42, "\" class=\"mb-3 h-48 w-48 border border-rule bg-white p-2\">
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var28 string
+ templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.start"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 122, Col: 141}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
+ 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
}
@@ -592,127 +640,127 @@ func Security(p Page, me Me, identities []Identity, canLink bool) templ.Componen
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var28 string
- templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading"))
+ var templ_7745c5c3_Var30 string
+ templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 127, Col: 113}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 137, Col: 113}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
+ _, 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, 45, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(identities) == 0 {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var29 string
- templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none"))
+ var templ_7745c5c3_Var31 string
+ templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 129, Col: 73}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 139, Col: 73}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, id := range identities {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var30 string
- templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(id.Provider)
+ var templ_7745c5c3_Var32 string
+ templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(id.Provider)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 133, Col: 69}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 143, Col: 69}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var31 string
- templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(id.Email)
+ var templ_7745c5c3_Var33 string
+ templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(id.Email)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 133, Col: 131}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 143, Col: 131}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, " ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if canLink {
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "\" class=\"inline-block border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var33 string
- templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link"))
+ var templ_7745c5c3_Var35 string
+ templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.link"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 138, Col: 190}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 148, Col: 190}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
- templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var16), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var18), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -739,33 +787,97 @@ func recoveryOutput() templ.Component {
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "
")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var35 string
- templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.save_now"))
+ var templ_7745c5c3_Var37 string
+ templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.save_now"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 148, Col: 69}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 158, Col: 69}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "
")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, " ")
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, "security.recovery.saved"))
+ var templ_7745c5c3_Var38 string
+ templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.saved"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 150, Col: 116}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 160, Col: 116}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+func policyBanner(msgID, actionID, href string) 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, 63, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var40 string
+ templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 167, Col: 23}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var42 string
+ templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, actionID))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 168, Col: 95}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42))
+ 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
}
diff --git a/internal/web/org.templ b/internal/web/org.templ
new file mode 100644
index 0000000..83de210
--- /dev/null
+++ b/internal/web/org.templ
@@ -0,0 +1,396 @@
+package web
+
+import (
+ "slices"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
+)
+
+// Role is a built-in or custom role.
+type Role struct {
+ ID string
+ Name string
+ BuiltIn bool
+ Permissions []string
+}
+
+// Assignment is one role a member holds.
+type Assignment struct {
+ ID string
+ RoleName string
+ // Scope is empty for organization-wide assignments.
+ Scope string
+}
+
+// Member is a row on the members page.
+type Member struct {
+ UserID string
+ Email string
+ DisplayName string
+ IsOwner bool
+ Assignments []Assignment
+}
+
+// PendingInvite is an invitation that was not accepted yet.
+type PendingInvite struct {
+ ID string
+ Email string
+ RoleName string
+}
+
+// MembersView is the data of the members page.
+type MembersView struct {
+ Members []Member
+ Roles []Role
+ Invitations []PendingInvite
+ CanManage bool
+}
+
+templ settingsHeading(titleID, introID string) {
+ { i18n.T(ctx, titleID) }
+ if introID != "" {
+ { i18n.T(ctx, introID) }
+ }
+}
+
+templ sectionHeading(id string) {
+ { i18n.T(ctx, id) }
+}
+
+templ roleSelect(roles []Role, name string) {
+
+ for _, r := range roles {
+ { r.Name }
+ }
+
+}
+
+templ MembersPage(p Page, me Me, v MembersView) {
+ @consoleShell(p, me) {
+ @settingsHeading("members.title", "members.intro")
+
+
+
+ { i18n.T(ctx, "auth.field.email") }
+ { i18n.T(ctx, "members.roles") }
+
+
+
+
+ for _, m := range v.Members {
+
+
+ { m.Email }
+ if m.DisplayName != "" {
+ { m.DisplayName }
+ }
+
+
+ if m.IsOwner {
+ { i18n.T(ctx, "members.owner") }
+ }
+
+ for _, a := range m.Assignments {
+
+ { a.RoleName }
+ if a.Scope != "" {
+ · { a.Scope }
+ }
+ if v.CanManage {
+ ×
+ }
+
+ }
+
+
+
+ if v.CanManage && !m.IsOwner {
+
+ { i18n.T(ctx, "sso.action.edit") }
+
+
+ @formError()
+ @roleSelect(v.Roles, "role_id")
+ @submit(i18n.T(ctx, "members.assign"))
+
+ { i18n.T(ctx, "members.remove") }
+
+
+ }
+
+
+ }
+
+
+ if v.CanManage {
+
+
+ @sectionHeading("members.invite")
+
+ @formError()
+ @field(i18n.T(ctx, "auth.field.email"), "email", "email", "off", true)
+
+ { i18n.T(ctx, "members.role") }
+ @roleSelect(v.Roles, "role_id")
+
+ @submit(i18n.T(ctx, "members.invite_submit"))
+
+
{ i18n.T(ctx, "members.invite_link") }
+
+
+
+
+ if len(v.Invitations) > 0 {
+
+ @sectionHeading("members.pending")
+
+ for _, inv := range v.Invitations {
+
+ { inv.Email } · { inv.RoleName }
+ { i18n.T(ctx, "members.revoke") }
+
+ }
+
+
+ }
+
+ }
+ }
+}
+
+// RolesView is the data of the roles page.
+type RolesView struct {
+ Roles []Role
+ Permissions []string
+ // Grantable lists the permissions the viewer may put into a role.
+ Grantable []string
+ CanManage bool
+}
+
+templ permissionChecks(all, grantable, checked []string) {
+
+ for _, perm := range all {
+
+
+ { i18n.T(ctx, "perm."+perm) }
+
+ }
+
+}
+
+templ RolesPage(p Page, me Me, v RolesView) {
+ @consoleShell(p, me) {
+ @settingsHeading("roles.title", "roles.intro")
+
+ for _, r := range v.Roles {
+
+
+
+ { r.Name }
+ if r.BuiltIn {
+ { i18n.T(ctx, "roles.built_in") }
+ }
+
+ if v.CanManage && !r.BuiltIn {
+ { i18n.T(ctx, "roles.delete") }
+ }
+
+ if v.CanManage && !r.BuiltIn {
+
+ @formError()
+ @valueField(i18n.T(ctx, "sso.field.name"), "name", r.Name, "", true)
+ @permissionChecks(v.Permissions, v.Grantable, r.Permissions)
+ @submit(i18n.T(ctx, "common.save"))
+
+ } else {
+
+ for _, perm := range r.Permissions {
+ { i18n.T(ctx, "perm."+perm) }
+ }
+
+ }
+
+ }
+
+ if v.CanManage {
+
+ @sectionHeading("roles.create")
+
+ @formError()
+ @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true)
+ @permissionChecks(v.Permissions, v.Grantable, nil)
+ @submit(i18n.T(ctx, "roles.create"))
+
+
+ }
+ }
+}
+
+// Token is a row on the tokens page.
+type Token struct {
+ ID string
+ Name string
+ Prefix string
+ UserEmail string
+ Permissions []string
+ ExpiresAt string
+ LastUsedAt string
+}
+
+// TokensView is the data of the tokens page.
+type TokensView struct {
+ Tokens []Token
+ Grantable []string
+ ShowOwner bool
+}
+
+templ TokensPage(p Page, me Me, v TokensView) {
+ @consoleShell(p, me) {
+ @settingsHeading("tokens.title", "tokens.intro")
+ if len(v.Tokens) > 0 {
+
+
+
+ { i18n.T(ctx, "sso.field.name") }
+ if v.ShowOwner {
+ { i18n.T(ctx, "tokens.owner") }
+ }
+ { i18n.T(ctx, "tokens.expires") }
+ { i18n.T(ctx, "tokens.last_used") }
+
+
+
+
+ for _, t := range v.Tokens {
+
+ { t.Name } { t.Prefix }…
+ if v.ShowOwner {
+ { t.UserEmail }
+ }
+ { t.ExpiresAt }
+ { t.LastUsedAt }
+
+ { i18n.T(ctx, "members.revoke") }
+
+
+ }
+
+
+ }
+
+ @sectionHeading("tokens.create")
+
+ @formError()
+ @valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true)
+ @permissionChecks(v.Grantable, v.Grantable, nil)
+
+ { i18n.T(ctx, "tokens.expires") }
+
+ { i18n.T(ctx, "tokens.days", "Count", 30) }
+ { i18n.T(ctx, "tokens.days", "Count", 90) }
+ { i18n.T(ctx, "tokens.days", "Count", 365) }
+ { i18n.T(ctx, "tokens.never") }
+
+
+ @submit(i18n.T(ctx, "tokens.create"))
+
+
{ i18n.T(ctx, "tokens.copy_now") }
+
+
+
+
+ }
+}
+
+// OrgSettings is the data of the organization settings page.
+type OrgSettings struct {
+ RequireTOTP bool
+ RequireSSO bool
+}
+
+templ OrgSettingsPage(p Page, me Me, v OrgSettings) {
+ @consoleShell(p, me) {
+ @settingsHeading("org.title", "")
+
+ @sectionHeading("org.policy")
+
+ @formError()
+ @checkbox(i18n.T(ctx, "org.require_totp"), "require_totp", v.RequireTOTP)
+ { i18n.T(ctx, "org.require_totp_hint") }
+ @checkbox(i18n.T(ctx, "org.require_sso"), "require_sso", v.RequireSSO)
+ { i18n.T(ctx, "org.require_sso_hint") }
+ @submit(i18n.T(ctx, "common.save"))
+
+
+ }
+}
+
+// Invitation is the data of the invitation landing page.
+type Invitation struct {
+ Token string
+ Valid bool
+ OrgName string
+ RoleName string
+ Email string
+ SignedInAs string
+ AccountExists bool
+}
+
+templ InvitationPage(p Page, v Invitation) {
+ @authShell(p) {
+ if !v.Valid {
+ { i18n.T(ctx, "error.invitation_invalid") }
+ } else {
+ { i18n.T(ctx, "invite.summary", "Org", v.OrgName, "Role", v.RoleName) }
+ { v.Email }
+ switch {
+ case v.SignedInAs == v.Email:
+
+ @formError()
+ @submit(i18n.T(ctx, "invite.accept"))
+
+ case v.SignedInAs != "":
+ { i18n.T(ctx, "error.invitation_email_mismatch") }
+ { i18n.T(ctx, "console.nav.logout") }
+ case v.AccountExists:
+ { i18n.T(ctx, "invite.sign_in") }
+ default:
+
+ @formError()
+ @field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false)
+ @field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true)
+ @submit(i18n.T(ctx, "invite.create_account"))
+
+ }
+ }
+ }
+}
diff --git a/internal/web/org_templ.go b/internal/web/org_templ.go
new file mode 100644
index 0000000..3e4585c
--- /dev/null
+++ b/internal/web/org_templ.go
@@ -0,0 +1,1770 @@
+// 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 (
+ "slices"
+
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/auth"
+ "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
+)
+
+// Role is a built-in or custom role.
+type Role struct {
+ ID string
+ Name string
+ BuiltIn bool
+ Permissions []string
+}
+
+// Assignment is one role a member holds.
+type Assignment struct {
+ ID string
+ RoleName string
+ // Scope is empty for organization-wide assignments.
+ Scope string
+}
+
+// Member is a row on the members page.
+type Member struct {
+ UserID string
+ Email string
+ DisplayName string
+ IsOwner bool
+ Assignments []Assignment
+}
+
+// PendingInvite is an invitation that was not accepted yet.
+type PendingInvite struct {
+ ID string
+ Email string
+ RoleName string
+}
+
+// MembersView is the data of the members page.
+type MembersView struct {
+ Members []Member
+ Roles []Role
+ Invitations []PendingInvite
+ CanManage bool
+}
+
+func settingsHeading(titleID, introID string) 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
+ }
+ var templ_7745c5c3_Var2 string
+ templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, titleID))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 51, Col: 62}
+ }
+ _, 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, 2, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if introID != "" {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "")
+ 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, introID))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 53, Col: 69}
+ }
+ _, 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, 4, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ return nil
+ })
+}
+
+func sectionHeading(id string) 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, 5, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var5 string
+ templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, id))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 58, Col: 91}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
+ 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
+ }
+ return nil
+ })
+}
+
+func roleSelect(roles []Role, name string) 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, 7, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, r := range roles {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var9 string
+ templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 64, Col: 34}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+func MembersPage(p Page, me Me, v MembersView) 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_Var11 := 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 {
+ 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)
+ templ_7745c5c3_Err = settingsHeading("members.title", "members.intro").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "")
+ 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, "auth.field.email"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 75, Col: 72}
+ }
+ _, 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, 14, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var13 string
+ templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.roles"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 76, Col: 69}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, m := range v.Members {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var14 string
+ templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(m.Email)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 84, Col: 16}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
+ 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 m.DisplayName != "" {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var15 string
+ templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(m.DisplayName)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 86, Col: 62}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if m.IsOwner {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var16 string
+ templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.owner"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 91, Col: 64}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, " ")
+ 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
+ }
+ for _, a := range m.Assignments {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var17 string
+ templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(a.RoleName)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 96, Col: 22}
+ }
+ _, 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, 25, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if a.Scope != "" {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "· ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var18 string
+ templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(a.Scope)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 98, Col: 48}
+ }
+ _, 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, 27, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ if v.CanManage {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "× ")
+ 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
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.CanManage && !m.IsOwner {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "")
+ 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, "sso.action.edit"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 115, Col: 99}
+ }
+ _, 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, 34, "
")
+ 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 = roleSelect(v.Roles, "role_id").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "members.assign")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var25 string
+ templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.remove"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 127, Col: 42}
+ }
+ _, 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, 39, " ")
+ 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
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.CanManage {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("members.invite").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "")
+ 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 = field(i18n.T(ctx, "auth.field.email"), "email", "email", "off", true).Render(ctx, templ_7745c5c3_Buffer)
+ 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
+ }
+ var templ_7745c5c3_Var26 string
+ templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.role"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 144, Col: 117}
+ }
+ _, 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, 45, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = roleSelect(v.Roles, "role_id").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "members.invite_submit")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if len(v.Invitations) > 0 {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("members.pending").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, inv := range v.Invitations {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var28 string
+ templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(inv.Email)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 160, Col: 26}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, " · ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var29 string
+ templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(inv.RoleName)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 160, Col: 71}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var31 string
+ templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.revoke"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 161, Col: 142}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ return nil
+ })
+ templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+// RolesView is the data of the roles page.
+type RolesView struct {
+ Roles []Role
+ Permissions []string
+ // Grantable lists the permissions the viewer may put into a role.
+ Grantable []string
+ CanManage bool
+}
+
+func permissionChecks(all, grantable, checked []string) 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, 58, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, perm := range all {
+ {
+ 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, 59, " ")
+ 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, "perm."+perm))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 194, Col: 31}
+ }
+ _, 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, 66, " ")
+ 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
+ }
+ return nil
+ })
+}
+
+func RolesPage(p Page, me Me, v RolesView) 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_Var38 := 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 {
+ 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)
+ templ_7745c5c3_Err = settingsHeading("roles.title", "roles.intro").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, r := range v.Roles {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var39 string
+ templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 208, Col: 15}
+ }
+ _, 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, 70, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if r.BuiltIn {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var40 string
+ templ_7745c5c3_Var40, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "roles.built_in"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 210, Col: 77}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var40))
+ 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 = templruntime.WriteString(templ_7745c5c3_Buffer, 73, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.CanManage && !r.BuiltIn {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var43 string
+ templ_7745c5c3_Var43, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "roles.delete"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 219, Col: 37}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var43))
+ 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
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.CanManage && !r.BuiltIn {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 79, "")
+ 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 = valueField(i18n.T(ctx, "sso.field.name"), "name", r.Name, "", true).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = permissionChecks(v.Permissions, v.Grantable, r.Permissions).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "common.save")).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
+ }
+ } else {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, perm := range r.Permissions {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var45 string
+ templ_7745c5c3_Var45, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "perm."+perm))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 232, Col: 80}
+ }
+ _, 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, 84, " ")
+ 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
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 87, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.CanManage {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 88, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("roles.create").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 89, "")
+ 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 = valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = permissionChecks(v.Permissions, v.Grantable, nil).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "roles.create")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ return nil
+ })
+ templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var38), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+// Token is a row on the tokens page.
+type Token struct {
+ ID string
+ Name string
+ Prefix string
+ UserEmail string
+ Permissions []string
+ ExpiresAt string
+ LastUsedAt string
+}
+
+// TokensView is the data of the tokens page.
+type TokensView struct {
+ Tokens []Token
+ Grantable []string
+ ShowOwner bool
+}
+
+func TokensPage(p Page, me Me, v TokensView) 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_Var47 := 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 {
+ 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)
+ templ_7745c5c3_Err = settingsHeading("tokens.title", "tokens.intro").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if len(v.Tokens) > 0 {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "")
+ 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, "sso.field.name"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 278, Col: 71}
+ }
+ _, 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, 92, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.ShowOwner {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 93, "")
+ 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, "tokens.owner"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 280, Col: 70}
+ }
+ _, 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, 94, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "")
+ 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, "tokens.expires"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 282, Col: 71}
+ }
+ _, 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, 96, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var51 string
+ templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.last_used"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 283, Col: 73}
+ }
+ _, 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, 97, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, t := range v.Tokens {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 98, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var52 string
+ templ_7745c5c3_Var52, templ_7745c5c3_Err = templ.JoinStringErrs(t.Name)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 290, Col: 39}
+ }
+ _, 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, 99, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var53 string
+ templ_7745c5c3_Var53, templ_7745c5c3_Err = templ.JoinStringErrs(t.Prefix)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 290, Col: 101}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var53))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 100, "… ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if v.ShowOwner {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 101, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var54 string
+ templ_7745c5c3_Var54, templ_7745c5c3_Err = templ.JoinStringErrs(t.UserEmail)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 292, Col: 45}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var54))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 102, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 103, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var55 string
+ templ_7745c5c3_Var55, templ_7745c5c3_Err = templ.JoinStringErrs(t.ExpiresAt)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 294, Col: 62}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var55))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var56 string
+ templ_7745c5c3_Var56, templ_7745c5c3_Err = templ.JoinStringErrs(t.LastUsedAt)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 295, Col: 63}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var56))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 105, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var59 string
+ templ_7745c5c3_Var59, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "members.revoke"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 302, Col: 40}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var59))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 108, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("tokens.create").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 111, "")
+ 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 = valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = permissionChecks(v.Grantable, v.Grantable, nil).Render(ctx, templ_7745c5c3_Buffer)
+ 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
+ }
+ var templ_7745c5c3_Var60 string
+ templ_7745c5c3_Var60, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.expires"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 316, Col: 117}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var60))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 113, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var61 string
+ templ_7745c5c3_Var61, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.days", "Count", 30))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 318, Col: 66}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var61))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 114, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var62 string
+ templ_7745c5c3_Var62, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.days", "Count", 90))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 319, Col: 75}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var62))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 115, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var63 string
+ templ_7745c5c3_Var63, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.days", "Count", 365))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 320, Col: 68}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var63))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 116, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var64 string
+ templ_7745c5c3_Var64, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "tokens.never"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 321, Col: 53}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var64))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "tokens.create")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 118, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+ templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var47), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+// OrgSettings is the data of the organization settings page.
+type OrgSettings struct {
+ RequireTOTP bool
+ RequireSSO bool
+}
+
+func OrgSettingsPage(p Page, me Me, v OrgSettings) 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_Var67 := 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 {
+ 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)
+ templ_7745c5c3_Err = settingsHeading("org.title", "").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 120, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = sectionHeading("org.policy").Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, "")
+ 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 = checkbox(i18n.T(ctx, "org.require_totp"), "require_totp", v.RequireTOTP).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 122, "")
+ 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"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 348, Col: 82}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = checkbox(i18n.T(ctx, "org.require_sso"), "require_sso", v.RequireSSO).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 124, "")
+ 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"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 350, Col: 81}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 125, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "common.save")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 126, " ")
+ 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)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+// Invitation is the data of the invitation landing page.
+type Invitation struct {
+ Token string
+ Valid bool
+ OrgName string
+ RoleName string
+ Email string
+ SignedInAs string
+ AccountExists bool
+}
+
+func InvitationPage(p Page, v Invitation) 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_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 {
+ 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)
+ if !v.Valid {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "")
+ 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"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 371, Col: 63}
+ }
+ _, 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, 128, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ } else {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 129, "")
+ 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))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 373, Col: 96}
+ }
+ _, 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, 130, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var74 string
+ templ_7745c5c3_Var74, 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}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var74))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ switch {
+ case v.SignedInAs == v.Email:
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "")
+ 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 = submit(i18n.T(ctx, "invite.accept")).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 134, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ case v.SignedInAs != "":
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, "")
+ 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"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 382, Col: 82}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 136, "
")
+ 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, "console.nav.logout"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 383, Col: 110}
+ }
+ _, 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, 137, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ case v.AccountExists:
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 138, "")
+ 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"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/org.templ`, Line: 385, Col: 153}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var79))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ default:
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, "")
+ 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 = field(i18n.T(ctx, "auth.field.name"), "display_name", "text", "name", false).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = field(i18n.T(ctx, "auth.field.new_password", "Min", auth.MinPasswordLength), "password", "password", "new-password", true).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = submit(i18n.T(ctx, "invite.create_account")).Render(ctx, templ_7745c5c3_Buffer)
+ 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
+ }
+ }
+ }
+ return nil
+ })
+ templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var71), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return nil
+ })
+}
+
+var _ = templruntime.GeneratedTemplate
diff --git a/internal/web/sso.templ b/internal/web/sso.templ
index 2651a50..ffbbce5 100644
--- a/internal/web/sso.templ
+++ b/internal/web/sso.templ
@@ -28,6 +28,7 @@ type SSOProvider struct {
HasSecret bool
AllowedDomains string
AutoProvision bool
+ DefaultRoleID string
Enabled bool
}
@@ -36,6 +37,7 @@ type SSOSettings struct {
Providers []SSOProvider
RedirectURL string
LoginURL string
+ Roles []Role
}
templ SSOSettingsPage(p Page, me Me, s SSOSettings) {
@@ -70,7 +72,7 @@ templ SSOSettingsPage(p Page, me Me, s SSOSettings) {
{ i18n.T(ctx, "sso.action.edit") }
- @ssoForm(pr, "put", "/org/sso/"+pr.ID)
+ @ssoForm(pr, s.Roles, "put", "/org/sso/"+pr.ID)
{ i18n.T(ctx, "sso.settings.add") }
- @ssoForm(SSOProvider{Enabled: true}, "post", "/org/sso")
+ @ssoForm(SSOProvider{Enabled: true}, s.Roles, "post", "/org/sso")
}
}
@@ -100,7 +102,7 @@ templ yesNo(v bool) {
}
}
-templ ssoForm(pr SSOProvider, method, action string) {
+templ ssoForm(pr SSOProvider, roles []Role, method, action string) {
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", pr.Name, "", true)
@@ -130,6 +132,15 @@ templ ssoForm(pr SSOProvider, method, action string) {
{ i18n.T(ctx, "sso.field.allowed_domains_hint") }
@checkbox(i18n.T(ctx, "sso.field.auto_provision"), "auto_provision", pr.AutoProvision)
+
+ { i18n.T(ctx, "sso.field.default_role") }
+
+ { i18n.T(ctx, "sso.field.default_role_viewer") }
+ for _, r := range roles {
+ { r.Name }
+ }
+
+
@checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", pr.Enabled)
@submit(i18n.T(ctx, "common.save"))
diff --git a/internal/web/sso_templ.go b/internal/web/sso_templ.go
index 5703f68..6526218 100644
--- a/internal/web/sso_templ.go
+++ b/internal/web/sso_templ.go
@@ -118,6 +118,7 @@ type SSOProvider struct {
HasSecret bool
AllowedDomains string
AutoProvision bool
+ DefaultRoleID string
Enabled bool
}
@@ -126,6 +127,7 @@ type SSOSettings struct {
Providers []SSOProvider
RedirectURL string
LoginURL string
+ Roles []Role
}
func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
@@ -164,7 +166,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.settings.title"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 43, Col: 76}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 45, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
@@ -177,7 +179,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.settings.intro"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 44, Col: 82}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 46, Col: 82}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -190,7 +192,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.settings.redirect_url"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 46, Col: 68}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 48, Col: 68}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
@@ -203,7 +205,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(s.RedirectURL)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 47, Col: 68}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 49, Col: 68}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
@@ -216,7 +218,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.settings.login_url"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 48, Col: 65}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 50, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
@@ -229,7 +231,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(s.LoginURL)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 49, Col: 65}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 51, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
@@ -247,7 +249,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.name"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 55, Col: 71}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 57, Col: 71}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
@@ -260,7 +262,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.issuer"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 56, Col: 73}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 58, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
@@ -273,7 +275,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.auto_provision"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 57, Col: 81}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 59, Col: 81}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
@@ -286,7 +288,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.enabled"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 58, Col: 74}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 60, Col: 74}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
@@ -304,7 +306,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var18 string
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(pr.Name)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 65, Col: 40}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 67, Col: 40}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
if templ_7745c5c3_Err != nil {
@@ -317,7 +319,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var19 string
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(pr.Issuer)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 66, Col: 70}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 68, Col: 70}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
if templ_7745c5c3_Err != nil {
@@ -346,7 +348,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var20 string
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.action.edit"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 71, Col: 99}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 73, Col: 99}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil {
@@ -356,7 +358,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = ssoForm(pr, "put", "/org/sso/"+pr.ID).Render(ctx, templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = ssoForm(pr, s.Roles, "put", "/org/sso/"+pr.ID).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -367,7 +369,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var21 string
templ_7745c5c3_Var21, templ_7745c5c3_Err = templruntime.NewAttributeExpression("/org/sso/" + pr.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 76, Col: 44}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 78, Col: 44}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var21)
if templ_7745c5c3_Err != nil {
@@ -380,7 +382,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var22 string
templ_7745c5c3_Var22, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "sso.action.delete_confirm")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 77, Col: 66}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 79, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var22)
if templ_7745c5c3_Err != nil {
@@ -393,7 +395,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var23 string
templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.action.delete"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 79, Col: 45}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 81, Col: 45}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23))
if templ_7745c5c3_Err != nil {
@@ -416,7 +418,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
var templ_7745c5c3_Var24 string
templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.settings.add"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 89, Col: 109}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 91, Col: 109}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24))
if templ_7745c5c3_Err != nil {
@@ -426,7 +428,7 @@ func SSOSettingsPage(p Page, me Me, s SSOSettings) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = ssoForm(SSOProvider{Enabled: true}, "post", "/org/sso").Render(ctx, templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = ssoForm(SSOProvider{Enabled: true}, s.Roles, "post", "/org/sso").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -469,7 +471,7 @@ func yesNo(v bool) templ.Component {
var templ_7745c5c3_Var26 string
templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.yes"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 97, Col: 62}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 99, Col: 62}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26))
if templ_7745c5c3_Err != nil {
@@ -483,7 +485,7 @@ func yesNo(v bool) templ.Component {
var templ_7745c5c3_Var27 string
templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "common.no"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 99, Col: 66}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 101, Col: 66}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27))
if templ_7745c5c3_Err != nil {
@@ -494,7 +496,7 @@ func yesNo(v bool) templ.Component {
})
}
-func ssoForm(pr SSOProvider, method, action string) templ.Component {
+func ssoForm(pr SSOProvider, roles []Role, method, action string) 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 {
@@ -518,7 +520,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var29 string
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(action).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 104, Col: 24}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 106, Col: 24}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
if templ_7745c5c3_Err != nil {
@@ -531,7 +533,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var30 string
templ_7745c5c3_Var30, templ_7745c5c3_Err = templruntime.NewAttributeExpression(method).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 104, Col: 47}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 106, Col: 47}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var30)
if templ_7745c5c3_Err != nil {
@@ -564,7 +566,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var31 string
templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.client_secret"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 110, Col: 124}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 112, Col: 124}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var31))
if templ_7745c5c3_Err != nil {
@@ -582,7 +584,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var32 string
templ_7745c5c3_Var32, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "sso.field.client_secret_keep")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 117, Col: 62}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 119, Col: 62}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var32)
if templ_7745c5c3_Err != nil {
@@ -600,7 +602,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var33 string
templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.allowed_domains"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 122, Col: 126}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 124, Col: 126}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33))
if templ_7745c5c3_Err != nil {
@@ -613,7 +615,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var34 string
templ_7745c5c3_Var34, templ_7745c5c3_Err = templruntime.NewAttributeExpression(pr.AllowedDomains).Resolve(ctx)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 127, Col: 29}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 129, Col: 29}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var34)
if templ_7745c5c3_Err != nil {
@@ -626,7 +628,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
var templ_7745c5c3_Var35 string
templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.allowed_domains_hint"))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 130, Col: 94}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 132, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35))
if templ_7745c5c3_Err != nil {
@@ -640,6 +642,82 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "")
+ 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, "sso.field.default_role"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 136, Col: 123}
+ }
+ _, 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, 47, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var37 string
+ templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "sso.field.default_role_viewer"))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 138, Col: 67}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, r := range roles {
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var39 string
+ templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 140, Col: 75}
+ }
+ _, 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, 53, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, " ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
templ_7745c5c3_Err = checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", pr.Enabled).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
@@ -648,7 +726,7 @@ func ssoForm(pr SSOProvider, method, action string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -673,69 +751,69 @@ func valueField(label, name, value, placeholder string, required bool) templ.Com
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var37 string
- templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(label)
+ var templ_7745c5c3_Var41 string
+ templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(label)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 140, Col: 90}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 151, Col: 90}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37))
+ _, 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, 48, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -760,43 +838,43 @@ func checkbox(label, name string, checked bool) templ.Component {
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, " class=\"accent-ink\"> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var43 string
- templ_7745c5c3_Var43, templ_7745c5c3_Err = templ.JoinStringErrs(label)
+ var templ_7745c5c3_Var47 string
+ templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(label)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 154, Col: 9}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 165, Col: 9}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var43))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var47))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, " ")
+ templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}