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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:49:35 +01:00
1 parent 30409697f7
commit d7d4821e3e
24 files changed
+4677 -439

No files matched your search

+153
View File
@@ -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()
}
}
+7 -7
View File
@@ -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
+339
View File
@@ -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))
}
+6
View File
@@ -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})
}
+475
View File
@@ -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")
+236 -34
View File
@@ -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 {
+211
View File
@@ -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)
}
}
})
}
+31 -5
View File
@@ -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)
+13 -1
View File
@@ -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)})
})
+44 -53
View File
@@ -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
+8
View File
@@ -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
}
+206
View File
@@ -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)
}
+37 -8
View File
@@ -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.<name>" and
// "scope.<type>".
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.<code>" dynamically.
func TestEveryLanguageHasAName(t *testing.T) {
c, err := Load()
+84 -2
View File
@@ -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"
}
+84 -2
View File
@@ -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"
}
+20 -3
View File
@@ -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;
+2 -2
View File
@@ -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) {
<form data-api="/auth/login" data-next="/">
<form data-api="/auth/login" data-next={ next }>
@formError()
<div data-step="password">
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "username", true)
+72 -59
View File
@@ -14,7 +14,7 @@ import (
"git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
)
func Login(p Page, signupAllowed bool) templ.Component {
func Login(p Page, signupAllowed bool, next 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 {
@@ -43,7 +43,20 @@ func Login(p Page, signupAllowed bool) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<form data-api=\"/auth/login\" data-next=\"/\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<form data-api=\"/auth/login\" data-next=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(next).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 10, Col: 47}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
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
}
@@ -51,7 +64,7 @@ func Login(p Page, signupAllowed bool) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<div data-step=\"password\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<div data-step=\"password\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -63,20 +76,20 @@ func Login(p Page, signupAllowed bool) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</div><div data-step=\"totp\" hidden><p class=\"mb-4 text-sm text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</div><div data-step=\"totp\" hidden><p class=\"mb-4 text-sm text-muted\">")
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, "auth.login.totp_hint"))
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.totp_hint"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 17, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -84,7 +97,7 @@ func Login(p Page, signupAllowed bool) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -92,90 +105,90 @@ func Login(p Page, signupAllowed bool) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</form><form action=\"/sso\" method=\"get\" class=\"mt-10 border-t border-rule pt-6\"><p class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.heading"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 23, Col: 108}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</p><div class=\"flex gap-2\"><input class=\"min-w-0 flex-1 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink\" name=\"org\" placeholder=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</form><form action=\"/sso\" method=\"get\" class=\"mt-10 border-t border-rule pt-6\"><p class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "auth.sso.org_placeholder")).Resolve(ctx)
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.heading"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 28, Col: 58}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 23, Col: 108}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
_, 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, 8, "\" aria-label=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</p><div class=\"flex gap-2\"><input class=\"min-w-0 flex-1 border border-rule bg-transparent px-2.5 py-1.5 font-mono text-sm outline-none focus:border-ink\" name=\"org\" placeholder=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "auth.sso.org_placeholder")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 29, Col: 57}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 28, Col: 58}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" autocomplete=\"organization\" required> <button type=\"submit\" class=\"border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" aria-label=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.submit"))
templ_7745c5c3_Var7, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "auth.sso.org_placeholder")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 33, Col: 134}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 29, Col: 57}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</button></div></form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\" autocomplete=\"organization\" required> <button type=\"submit\" class=\"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_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.sso.submit"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 33, Col: 134}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</button></div></form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if signupAllowed {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<p class=\"mt-8 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.no_account"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 38, Col: 42}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, " <a class=\"text-ink underline underline-offset-2\" href=\"/signup\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<p class=\"mt-8 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.to_signup"))
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.no_account"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 39, Col: 105}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 38, Col: 42}
}
_, 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, 13, "</a></p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " <a class=\"text-ink underline underline-offset-2\" href=\"/signup\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.login.to_signup"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 39, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</a></p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -207,7 +220,7 @@ func Signup(p Page) templ.Component {
}
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_Var12 := 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 {
@@ -219,7 +232,7 @@ func Signup(p Page) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<form data-api=\"/auth/signup\" data-next=\"/\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<form data-api=\"/auth/signup\" data-next=\"/\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -239,7 +252,7 @@ func Signup(p Page) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<hr class=\"my-6 border-rule\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "<hr class=\"my-6 border-rule\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -255,26 +268,26 @@ func Signup(p Page) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</form><p class=\"mt-8 text-sm text-muted\"><a class=\"text-ink underline underline-offset-2\" href=\"/login\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</form><p class=\"mt-8 text-sm text-muted\"><a class=\"text-ink underline underline-offset-2\" href=\"/login\">")
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.signup.to_login"))
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "auth.signup.to_login"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 57, Col: 137}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
_, 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, 17, "</a></p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</a></p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
templ_7745c5c3_Err = authShell(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var12), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+28 -9
View File
@@ -12,7 +12,11 @@ type Me struct {
TOTP bool
ActiveOrg string
Orgs []Org
TOTPMissing bool
// Can holds the permissions in the active organization.
Can map[string]bool
// Policy is the error code of an unmet sign-in policy of the active
// organization, or empty.
Policy string
// RecoveryCodesLeft counts unused TOTP recovery codes.
RecoveryCodesLeft int
}
@@ -40,7 +44,15 @@ templ consoleShell(p Page, me Me) {
<span class="text-muted">{ me.Orgs[0].Name }</span>
}
<nav class="ml-auto flex items-center gap-5">
if me.IsOwner {
if me.Can["members.read"] {
<a href="/settings/members" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.members") }</a>
<a href="/settings/roles" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.roles") }</a>
}
if len(me.Orgs) > 0 {
<a href="/settings/tokens" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.tokens") }</a>
}
if me.Can["org.manage"] {
<a href="/settings/org" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.org") }</a>
<a href="/settings/sso" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.sso") }</a>
}
<a href="/settings/security" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.security") }</a>
@@ -49,13 +61,11 @@ templ consoleShell(p Page, me Me) {
</nav>
</div>
</header>
if me.TOTPMissing {
<div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
{ i18n.T(ctx, "console.totp_missing") }
<a href="/settings/security" class="underline underline-offset-2">{ i18n.T(ctx, "console.totp_missing_action") }</a>
</p>
</div>
switch me.Policy {
case "totp_required_by_org":
@policyBanner("error.totp_required_by_org", "console.totp_missing_action", "/settings/security")
case "sso_required_by_org":
@policyBanner("error.sso_required_by_org", "console.sso_required_action", "/sso/"+me.ActiveSlug)
}
<main class="mx-auto max-w-5xl px-6 py-10">
@flash(p)
@@ -150,3 +160,12 @@ templ recoveryOutput() {
<a href="/settings/security" class="text-sm underline underline-offset-2">{ i18n.T(ctx, "security.recovery.saved") }</a>
</div>
}
templ policyBanner(msgID, actionID, href string) {
<div class="border-b border-degraded/40 bg-degraded/10">
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
{ i18n.T(ctx, msgID) }
<a href={ templ.SafeURL(href) } class="underline underline-offset-2">{ i18n.T(ctx, actionID) }</a>
</p>
</div>
}
+297 -185
View File
@@ -21,7 +21,11 @@ type Me struct {
TOTP bool
ActiveOrg string
Orgs []Org
TOTPMissing bool
// Can holds the permissions in the active organization.
Can map[string]bool
// Policy is the error code of an unmet sign-in policy of the active
// organization, or empty.
Policy string
// RecoveryCodesLeft counts unused TOTP recovery codes.
RecoveryCodesLeft int
}
@@ -81,7 +85,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(o.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 36, Col: 27}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 40, Col: 27}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
if templ_7745c5c3_Err != nil {
@@ -104,7 +108,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(o.Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 36, Col: 73}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 40, Col: 73}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
@@ -127,7 +131,7 @@ func consoleShell(p Page, me Me) templ.Component {
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(me.Orgs[0].Name)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 40, Col: 47}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 44, Col: 47}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -142,52 +146,116 @@ func consoleShell(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if me.IsOwner {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<a href=\"/settings/sso\" class=\"text-muted hover:text-ink\">")
if me.Can["members.read"] {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<a href=\"/settings/members\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.sso"))
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.members"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 44, Col: 96}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 48, Col: 104}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</a> ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</a> <a href=\"/settings/roles\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.roles"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 49, Col: 100}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</a> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "<a href=\"/settings/security\" class=\"text-muted hover:text-ink\">")
if len(me.Orgs) > 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<a href=\"/settings/tokens\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.tokens"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 52, Col: 102}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</a> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if me.Can["org.manage"] {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "<a href=\"/settings/org\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.org"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 55, Col: 96}
}
_, 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, 18, "</a> <a href=\"/settings/sso\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.sso"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 56, Col: 96}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "</a> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "<a href=\"/settings/security\" class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.security"))
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.security"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 46, Col: 105}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 58, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</a> <button data-logout class=\"text-muted hover:text-ink\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</a> <button data-logout class=\"text-muted hover:text-ink\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.nav.logout"))
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, 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/console.templ`, Line: 47, Col: 94}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 59, Col: 94}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
_, 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, 16, "</button>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</button>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -195,43 +263,23 @@ func consoleShell(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "</nav></div></header>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "</nav></div></header>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if me.TOTPMissing {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<div class=\"border-b border-degraded/40 bg-degraded/10\"><p class=\"mx-auto max-w-5xl px-6 py-2 text-sm\">")
switch me.Policy {
case "totp_required_by_org":
templ_7745c5c3_Err = policyBanner("error.totp_required_by_org", "console.totp_missing_action", "/settings/security").Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.totp_missing"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 55, Col: 42}
}
_, 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, 19, " <a href=\"/settings/security\" class=\"underline underline-offset-2\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.totp_missing_action"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 56, Col: 115}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "</a></p></div>")
case "sso_required_by_org":
templ_7745c5c3_Err = policyBanner("error.sso_required_by_org", "console.sso_required_action", "/sso/"+me.ActiveSlug).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, " <main class=\"mx-auto max-w-5xl px-6 py-10\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, " <main class=\"mx-auto max-w-5xl px-6 py-10\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -243,7 +291,7 @@ func consoleShell(p Page, me Me) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</main>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "</main>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -274,7 +322,7 @@ func Dashboard(p Page, me Me) templ.Component {
}
ctx = templ.InitializeContext(ctx)
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var12 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Var14 := 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 {
@@ -286,39 +334,39 @@ func Dashboard(p Page, me Me) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<h1 class=\"text-lg font-semibold\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "<h1 class=\"text-lg font-semibold\">")
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, "console.monitors.title"))
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.title"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 69, Col: 75}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 79, Col: 75}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
_, 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, 24, "</h1><p class=\"mt-2 text-sm text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</h1><p class=\"mt-2 text-sm text-muted\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.empty"))
var templ_7745c5c3_Var16 string
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.monitors.empty"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 70, Col: 76}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 80, Col: 76}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
_, 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, 25, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "</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, "<h1 class=\"mb-8 text-lg font-semibold\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<h1 class=\"mb-8 text-lg font-semibold\">")
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, "</h1><section class=\"max-w-md\"><h2 class=\"mb-1 text-xs font-medium uppercase tracking-wider text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "</h1><section class=\"max-w-md\"><h2 class=\"mb-1 text-xs font-medium uppercase tracking-wider text-muted\">")
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, "</h2>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</h2>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if me.TOTP {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<p class=\"mb-1 text-sm\"><span class=\"text-up\">●</span> ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "<p class=\"mb-1 text-sm\"><span class=\"text-up\">●</span> ")
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, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "</p>")
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, "<p class=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "<p class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var20 = []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_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, "</p><details class=\"mb-6\"><summary class=\"cursor-pointer text-sm text-muted hover:text-ink\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "</p><details class=\"mb-6\"><summary class=\"cursor-pointer text-sm text-muted hover:text-ink\">")
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, "</summary><form data-api=\"/me/totp/recovery-codes\" data-show-codes class=\"mt-4\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</summary><form data-api=\"/me/totp/recovery-codes\" data-show-codes class=\"mt-4\">")
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, "</form></details> <details><summary class=\"cursor-pointer text-sm text-muted hover:text-ink\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</form></details> <details><summary class=\"cursor-pointer text-sm text-muted hover:text-ink\">")
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, "</summary><form data-api=\"/me/totp/disable\" data-next=\"/settings/security\" class=\"mt-4\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "</summary><form data-api=\"/me/totp/disable\" data-next=\"/settings/security\" class=\"mt-4\">")
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, "</form></details>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "</form></details>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "<p class=\"mb-6 text-sm\"><span class=\"text-unknown\">●</span> ")
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, "</p><div data-totp-setup><button data-totp-start class=\"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_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, "</button><div data-totp-panel hidden><img data-totp-qr alt=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "<p class=\"mb-6 text-sm\"><span class=\"text-unknown\">●</span> ")
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\"><p class=\"mb-6 break-all font-mono text-xs text-muted\" data-totp-secret></p><form data-api=\"/me/totp/enable\" data-show-codes>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</p><div data-totp-setup><button data-totp-start class=\"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_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, "</button><div data-totp-panel hidden><img data-totp-qr alt=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var29 string
templ_7745c5c3_Var29, templ_7745c5c3_Err = templruntime.NewAttributeExpression(i18n.T(ctx, "security.totp.qr_alt")).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 124, Col: 65}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var29)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "\" class=\"mb-3 h-48 w-48 border border-rule bg-white p-2\"><p class=\"mb-6 break-all font-mono text-xs text-muted\" data-totp-secret></p><form data-api=\"/me/totp/enable\" data-show-codes>")
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, "</form></div></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "</form></div></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</section><section class=\"mt-12 max-w-md\"><h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "</section><section class=\"mt-12 max-w-md\"><h2 class=\"mb-3 text-xs font-medium uppercase tracking-wider text-muted\">")
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, "</h2>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "</h2>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(identities) == 0 {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "<p class=\"mb-4 text-sm text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<p class=\"mb-4 text-sm text-muted\">")
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, "</p>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "</p>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "<ul class=\"mb-4 divide-y divide-rule border-y border-rule text-sm\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "<ul class=\"mb-4 divide-y divide-rule border-y border-rule text-sm\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, id := range identities {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<li class=\"flex justify-between gap-4 py-2\"><span>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "<li class=\"flex justify-between gap-4 py-2\"><span>")
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, "</span><span class=\"font-mono text-xs text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "</span><span class=\"font-mono text-xs text-muted\">")
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, "</span></li>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "</span></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "</ul>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
if canLink {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "<a href=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<a href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var32 string
templ_7745c5c3_Var32, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL("/sso/" + me.ActiveSlug + "?link=1")).ResolveURL(ctx)
var templ_7745c5c3_Var34 string
templ_7745c5c3_Var34, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL("/sso/" + me.ActiveSlug + "?link=1")).ResolveURL(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 138, Col: 64}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 148, Col: 64}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var32)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var34)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "\" class=\"inline-block border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper\">")
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, "</a>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "</a>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "</section>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "</section>")
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, "<div data-recovery-output hidden class=\"mt-6 border border-ink p-4\"><p class=\"mb-3 text-sm\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "<div data-recovery-output hidden class=\"mt-6 border border-ink p-4\"><p class=\"mb-3 text-sm\">")
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, "</p><ol data-recovery-list class=\"mb-4 grid grid-cols-2 gap-x-6 gap-y-1 font-mono text-sm\"></ol><a href=\"/settings/security\" class=\"text-sm underline underline-offset-2\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, "</p><ol data-recovery-list class=\"mb-4 grid grid-cols-2 gap-x-6 gap-y-1 font-mono text-sm\"></ol><a href=\"/settings/security\" class=\"text-sm underline underline-offset-2\">")
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, "</a></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "</a></div>")
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, "<div class=\"border-b border-degraded/40 bg-degraded/10\"><p class=\"mx-auto max-w-5xl px-6 py-2 text-sm\">")
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, " <a href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var41 string
templ_7745c5c3_Var41, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(href)).ResolveURL(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 168, Col: 32}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var41)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "\" class=\"underline underline-offset-2\">")
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, "</a></p></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+396
View File
@@ -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) {
<h1 class="mb-2 text-lg font-semibold">{ i18n.T(ctx, titleID) }</h1>
if introID != "" {
<p class="mb-8 max-w-2xl text-sm text-muted">{ i18n.T(ctx, introID) }</p>
}
}
templ sectionHeading(id string) {
<h2 class="mb-4 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, id) }</h2>
}
templ roleSelect(roles []Role, name string) {
<select name={ name } class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm" required>
for _, r := range roles {
<option value={ r.ID }>{ r.Name }</option>
}
</select>
}
templ MembersPage(p Page, me Me, v MembersView) {
@consoleShell(p, me) {
@settingsHeading("members.title", "members.intro")
<table class="mb-12 w-full text-left text-sm">
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
<tr>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "auth.field.email") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "members.roles") }</th>
<th class="py-2"></th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
for _, m := range v.Members {
<tr class="align-top">
<td class="py-2.5 pr-4">
{ m.Email }
if m.DisplayName != "" {
<span class="block text-xs text-muted">{ m.DisplayName }</span>
}
</td>
<td class="py-2.5 pr-4">
if m.IsOwner {
<span class="font-medium">{ i18n.T(ctx, "members.owner") }</span>
}
<ul class="flex flex-wrap gap-1.5">
for _, a := range m.Assignments {
<li class="inline-flex items-center gap-1.5 border border-rule px-1.5 py-0.5 text-xs">
{ a.RoleName }
if a.Scope != "" {
<span class="text-muted">· { a.Scope }</span>
}
if v.CanManage {
<button
type="button"
data-delete={ "/org/assignments/" + a.ID }
class="text-muted hover:text-down"
aria-label={ i18n.T(ctx, "members.unassign") }
>×</button>
}
</li>
}
</ul>
</td>
<td class="py-2.5 text-right">
if v.CanManage && !m.IsOwner {
<details class="inline-block text-left">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "sso.action.edit") }</summary>
<div class="mt-3 w-64">
<form data-api={ "/org/members/" + m.UserID + "/roles" } data-next="/settings/members">
@formError()
@roleSelect(v.Roles, "role_id")
@submit(i18n.T(ctx, "members.assign"))
</form>
<button
type="button"
data-delete={ "/org/members/" + m.UserID }
data-confirm={ i18n.T(ctx, "members.remove_confirm") }
class="mt-4 text-sm text-down hover:underline"
>{ i18n.T(ctx, "members.remove") }</button>
</div>
</details>
}
</td>
</tr>
}
</tbody>
</table>
if v.CanManage {
<div class="grid gap-12 md:grid-cols-2">
<section>
@sectionHeading("members.invite")
<form data-api="/org/invitations" data-show-link>
@formError()
@field(i18n.T(ctx, "auth.field.email"), "email", "email", "off", true)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "members.role") }</span>
@roleSelect(v.Roles, "role_id")
</label>
@submit(i18n.T(ctx, "members.invite_submit"))
<div data-link-output hidden class="mt-6 border border-ink p-4">
<p class="mb-2 text-sm">{ i18n.T(ctx, "members.invite_link") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
</div>
</form>
</section>
if len(v.Invitations) > 0 {
<section>
@sectionHeading("members.pending")
<ul class="divide-y divide-rule border-y border-rule text-sm">
for _, inv := range v.Invitations {
<li class="flex items-center justify-between gap-4 py-2">
<span>{ inv.Email } <span class="text-muted">· { inv.RoleName }</span></span>
<button type="button" data-delete={ "/org/invitations/" + inv.ID } class="text-muted hover:text-down">{ i18n.T(ctx, "members.revoke") }</button>
</li>
}
</ul>
</section>
}
</div>
}
}
}
// 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) {
<fieldset class="mb-4 grid grid-cols-1 gap-1 sm:grid-cols-2">
for _, perm := range all {
<label class={ "flex items-center gap-2 text-sm", templ.KV("text-muted", !slices.Contains(grantable, perm)) }>
<input
type="checkbox"
name="permissions"
value={ perm }
data-multi
checked?={ slices.Contains(checked, perm) }
disabled?={ !slices.Contains(grantable, perm) }
class="accent-ink"
/>
{ i18n.T(ctx, "perm."+perm) }
</label>
}
</fieldset>
}
templ RolesPage(p Page, me Me, v RolesView) {
@consoleShell(p, me) {
@settingsHeading("roles.title", "roles.intro")
<div class="mb-12 space-y-6">
for _, r := range v.Roles {
<section class="border-t border-rule pt-4">
<div class="mb-2 flex items-baseline justify-between gap-4">
<h2 class="font-medium">
{ r.Name }
if r.BuiltIn {
<span class="ml-2 text-xs text-muted">{ i18n.T(ctx, "roles.built_in") }</span>
}
</h2>
if v.CanManage && !r.BuiltIn {
<button
type="button"
data-delete={ "/org/roles/" + r.ID }
data-confirm={ i18n.T(ctx, "roles.delete_confirm") }
class="text-sm text-down hover:underline"
>{ i18n.T(ctx, "roles.delete") }</button>
}
</div>
if v.CanManage && !r.BuiltIn {
<form data-api={ "/org/roles/" + r.ID } data-method="put" data-next="/settings/roles" class="max-w-xl">
@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"))
</form>
} else {
<ul class="flex flex-wrap gap-1.5 text-xs">
for _, perm := range r.Permissions {
<li class="border border-rule px-1.5 py-0.5">{ i18n.T(ctx, "perm."+perm) }</li>
}
</ul>
}
</section>
}
</div>
if v.CanManage {
<section class="max-w-xl">
@sectionHeading("roles.create")
<form data-api="/org/roles" data-next="/settings/roles">
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true)
@permissionChecks(v.Permissions, v.Grantable, nil)
@submit(i18n.T(ctx, "roles.create"))
</form>
</section>
}
}
}
// 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 {
<table class="mb-12 w-full text-left text-sm">
<thead class="border-b border-rule text-xs uppercase tracking-wider text-muted">
<tr>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "sso.field.name") }</th>
if v.ShowOwner {
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.owner") }</th>
}
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.expires") }</th>
<th class="py-2 pr-4 font-medium">{ i18n.T(ctx, "tokens.last_used") }</th>
<th class="py-2"></th>
</tr>
</thead>
<tbody class="divide-y divide-rule">
for _, t := range v.Tokens {
<tr>
<td class="py-2.5 pr-4">{ t.Name } <span class="block font-mono text-xs text-muted">{ t.Prefix }…</span></td>
if v.ShowOwner {
<td class="py-2.5 pr-4">{ t.UserEmail }</td>
}
<td class="py-2.5 pr-4 font-mono text-xs">{ t.ExpiresAt }</td>
<td class="py-2.5 pr-4 font-mono text-xs">{ t.LastUsedAt }</td>
<td class="py-2.5 text-right">
<button
type="button"
data-delete={ "/org/tokens/" + t.ID }
data-confirm={ i18n.T(ctx, "tokens.revoke_confirm") }
class="text-muted hover:text-down"
>{ i18n.T(ctx, "members.revoke") }</button>
</td>
</tr>
}
</tbody>
</table>
}
<section class="max-w-xl">
@sectionHeading("tokens.create")
<form data-api="/org/tokens" data-show-link>
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", "", "", true)
@permissionChecks(v.Grantable, v.Grantable, nil)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "tokens.expires") }</span>
<select name="expires_in_days" data-number class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="30">{ i18n.T(ctx, "tokens.days", "Count", 30) }</option>
<option value="90" selected>{ i18n.T(ctx, "tokens.days", "Count", 90) }</option>
<option value="365">{ i18n.T(ctx, "tokens.days", "Count", 365) }</option>
<option value="0">{ i18n.T(ctx, "tokens.never") }</option>
</select>
</label>
@submit(i18n.T(ctx, "tokens.create"))
<div data-link-output hidden class="mt-6 border border-ink p-4">
<p class="mb-2 text-sm">{ i18n.T(ctx, "tokens.copy_now") }</p>
<input data-link readonly class="w-full border border-rule bg-transparent px-2 py-1.5 font-mono text-xs"/>
</div>
</form>
</section>
}
}
// 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", "")
<section class="max-w-xl">
@sectionHeading("org.policy")
<form data-api="/org/policy" data-method="put" data-next="/settings/org">
@formError()
@checkbox(i18n.T(ctx, "org.require_totp"), "require_totp", v.RequireTOTP)
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "org.require_totp_hint") }</p>
@checkbox(i18n.T(ctx, "org.require_sso"), "require_sso", v.RequireSSO)
<p class="mb-4 ml-6 text-xs text-muted">{ i18n.T(ctx, "org.require_sso_hint") }</p>
@submit(i18n.T(ctx, "common.save"))
</form>
</section>
}
}
// 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 {
<p class="text-sm">{ i18n.T(ctx, "error.invitation_invalid") }</p>
} else {
<p class="mb-6 text-sm">{ i18n.T(ctx, "invite.summary", "Org", v.OrgName, "Role", v.RoleName) }</p>
<p class="mb-6 font-mono text-sm">{ v.Email }</p>
switch {
case v.SignedInAs == v.Email:
<form data-api={ "/invitations/" + v.Token + "/accept" } data-next="/">
@formError()
@submit(i18n.T(ctx, "invite.accept"))
</form>
case v.SignedInAs != "":
<p class="text-sm text-down">{ i18n.T(ctx, "error.invitation_email_mismatch") }</p>
<button data-logout class="mt-4 text-sm underline underline-offset-2">{ i18n.T(ctx, "console.nav.logout") }</button>
case v.AccountExists:
<a href={ templ.SafeURL("/login?next=/invite/" + v.Token) } class="inline-block bg-ink px-3 py-2 text-sm text-paper">{ i18n.T(ctx, "invite.sign_in") }</a>
default:
<form data-api={ "/invitations/" + v.Token + "/signup" } data-next="/">
@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"))
</form>
}
}
}
}
File diff suppressed because it is too large. Load diff
+14 -3
View File
@@ -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) {
<details class="inline-block text-left">
<summary class="cursor-pointer text-muted hover:text-ink">{ i18n.T(ctx, "sso.action.edit") }</summary>
<div class="mt-4 w-80">
@ssoForm(pr, "put", "/org/sso/"+pr.ID)
@ssoForm(pr, s.Roles, "put", "/org/sso/"+pr.ID)
<button
type="button"
data-delete={ "/org/sso/" + pr.ID }
@@ -87,7 +89,7 @@ templ SSOSettingsPage(p Page, me Me, s SSOSettings) {
}
<section class="max-w-md">
<h2 class="mb-4 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.settings.add") }</h2>
@ssoForm(SSOProvider{Enabled: true}, "post", "/org/sso")
@ssoForm(SSOProvider{Enabled: true}, s.Roles, "post", "/org/sso")
</section>
}
}
@@ -100,7 +102,7 @@ templ yesNo(v bool) {
}
}
templ ssoForm(pr SSOProvider, method, action string) {
templ ssoForm(pr SSOProvider, roles []Role, method, action string) {
<form data-api={ action } data-method={ method } data-next="/settings/sso">
@formError()
@valueField(i18n.T(ctx, "sso.field.name"), "name", pr.Name, "", true)
@@ -130,6 +132,15 @@ templ ssoForm(pr SSOProvider, method, action string) {
<span class="mt-1 block text-xs text-muted">{ i18n.T(ctx, "sso.field.allowed_domains_hint") }</span>
</label>
@checkbox(i18n.T(ctx, "sso.field.auto_provision"), "auto_provision", pr.AutoProvision)
<label class="mb-4 block">
<span class="mb-1 block text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "sso.field.default_role") }</span>
<select name="default_role_id" data-nullable class="w-full border border-rule bg-transparent px-2 py-1.5 text-sm">
<option value="">{ i18n.T(ctx, "sso.field.default_role_viewer") }</option>
for _, r := range roles {
<option value={ r.ID } selected?={ r.ID == pr.DefaultRoleID }>{ r.Name }</option>
}
</select>
</label>
@checkbox(i18n.T(ctx, "sso.field.enabled"), "enabled", pr.Enabled)
@submit(i18n.T(ctx, "common.save"))
</form>
+144 -66
View File
@@ -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, "<label class=\"mb-4 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
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, "</span> <select name=\"default_role_id\" data-nullable class=\"w-full border border-rule bg-transparent px-2 py-1.5 text-sm\"><option value=\"\">")
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, "</option> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, r := range roles {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var38 string
templ_7745c5c3_Var38, templ_7745c5c3_Err = templruntime.NewAttributeExpression(r.ID).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 140, Col: 25}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
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
}
if r.ID == pr.DefaultRoleID {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, " selected")
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_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, "</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "</select></label>")
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, "</form>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, "</form>")
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, "<label class=\"mb-4 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "<label class=\"mb-4 block\"><span class=\"mb-1 block text-xs font-medium uppercase tracking-wider text-muted\">")
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, "</span> <input class=\"w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink\" name=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "</span> <input class=\"w-full border border-rule bg-transparent px-2.5 py-1.5 outline-none focus:border-ink\" name=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var38 string
templ_7745c5c3_Var38, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
var templ_7745c5c3_Var42 string
templ_7745c5c3_Var42, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 143, Col: 14}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 154, Col: 14}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var38)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var42)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "\" value=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var39 string
templ_7745c5c3_Var39, templ_7745c5c3_Err = templruntime.NewAttributeExpression(value).Resolve(ctx)
var templ_7745c5c3_Var43 string
templ_7745c5c3_Var43, templ_7745c5c3_Err = templruntime.NewAttributeExpression(value).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 144, Col: 16}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 155, Col: 16}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var39)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var43)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "\" placeholder=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, "\" placeholder=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var40 string
templ_7745c5c3_Var40, templ_7745c5c3_Err = templruntime.NewAttributeExpression(placeholder).Resolve(ctx)
var templ_7745c5c3_Var44 string
templ_7745c5c3_Var44, templ_7745c5c3_Err = templruntime.NewAttributeExpression(placeholder).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 145, Col: 28}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 156, Col: 28}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var40)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var44)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if required {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, " required")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, " required")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 53, "></label>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "></label>")
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, "<label class=\"mb-3 flex items-center gap-2 text-sm\"><input type=\"checkbox\" name=\"")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "<label class=\"mb-3 flex items-center gap-2 text-sm\"><input type=\"checkbox\" name=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var42 string
templ_7745c5c3_Var42, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
var templ_7745c5c3_Var46 string
templ_7745c5c3_Var46, templ_7745c5c3_Err = templruntime.NewAttributeExpression(name).Resolve(ctx)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 153, Col: 36}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/sso.templ`, Line: 164, Col: 36}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var42)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var46)
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, 64, "\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if checked {
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, " checked")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, " checked")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, " class=\"accent-ink\"> ")
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, "</label>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "</label>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}