diff --git a/internal/api/apidocs.go b/internal/api/apidocs.go index 2e28e23..7a87ad9 100644 --- a/internal/api/apidocs.go +++ b/internal/api/apidocs.go @@ -65,6 +65,17 @@ var endpoints = []endpoint{ {method: "POST", path: "/api/v1/consent", tag: "Account", summary: "Accept the platform's privacy policy and terms", sessionOnly: true, description: "`versions` are the versions shown, e.g. `privacy:12,terms:14`; `409 consent_outdated` when a document changed meanwhile. Until an account accepted the current versions, other requests of its sessions get `403 consent_required`.", req: consentRequest{}, resp: obj{"redirect": ""}}, + {method: "GET", path: "/api/v1/support/tickets", tag: "Support", summary: "The account's support tickets", sessionOnly: true, + description: "Newest activity first. Open to suspended accounts and to those that have not accepted the terms.", resp: obj{"tickets": []supportTicketView{}}}, + {method: "POST", path: "/api/v1/support/tickets", tag: "Support", summary: "Ask the platform's admins for help", sessionOnly: true, + description: "`message` is Markdown; the admins are mailed. `attach_org` names the active organization; `monitor_id`, `channel_id`, `alert_group_id`, `status_page_id` and `incident_id` point at things in it the account can read, and name it too. `409 too_many_tickets` beyond the platform's limit of open tickets per account, `409 suspended_ticket_limit` for a second ticket of a suspended account; `403 support_disabled` while the admins switched support off.", + req: supportTicketRequest{}, resp: supportTicketView{}, status: http.StatusCreated}, + {method: "GET", path: "/api/v1/support/tickets/:id", tag: "Support", summary: "A support ticket with its messages", sessionOnly: true, + resp: supportTicketView{}}, + {method: "POST", path: "/api/v1/support/tickets/:id/messages", tag: "Support", summary: "Reply to a support ticket", sessionOnly: true, + description: "Moves the ticket to `open`, also out of `closed`.", req: supportMessageRequest{}, resp: obj{"status": ""}, status: http.StatusCreated}, + {method: "PUT", path: "/api/v1/support/tickets/:id/status", tag: "Support", summary: "Close or reopen a support ticket", sessionOnly: true, + description: "`status` is `closed` or `open`.", req: supportStatusRequest{}, status: http.StatusNoContent}, {method: "POST", path: "/api/v1/markdown/preview", tag: "Account", summary: "Render Markdown as pages will show it", req: previewRequest{}, resp: obj{"html": ""}}, {method: "POST", path: "/api/v1/invitations/:token/accept", tag: "Account", summary: "Accept an invitation with the signed-in account", sessionOnly: true, @@ -273,6 +284,18 @@ var endpoints = []endpoint{ // Platform {method: "GET", path: "/api/v1/admin/audit", tag: "Platform", summary: "Platform audit log", perm: "platform admin", description: "Paged, newest first.", resp: paged(obj{"events": []auditEventView{}})}, + {method: "GET", path: "/api/v1/admin/support/settings", tag: "Platform", summary: "How the platform runs support tickets", perm: "platform admin", + resp: supportSettings{}}, + {method: "PUT", path: "/api/v1/admin/support/settings", tag: "Platform", summary: "Switch support tickets on or off and limit open tickets per account", perm: "platform admin", + description: "`max_open_tickets` of 0 means unlimited.", req: supportSettings{}, status: http.StatusNoContent}, + {method: "GET", path: "/api/v1/admin/support/tickets", tag: "Platform", summary: "Support tickets of every account", perm: "platform admin", + description: "`?status=open` (default), `answered`, `closed` or `all`; the latest 200, those waiting for the admins first.", resp: obj{"tickets": []supportTicketView{}}}, + {method: "GET", path: "/api/v1/admin/support/tickets/:id", tag: "Platform", summary: "A support ticket with its messages", perm: "platform admin", + resp: supportTicketView{}}, + {method: "POST", path: "/api/v1/admin/support/tickets/:id/messages", tag: "Platform", summary: "Answer a support ticket", perm: "platform admin", + description: "Moves the ticket to `answered` and mails the account.", req: supportMessageRequest{}, resp: obj{"status": ""}, status: http.StatusCreated}, + {method: "PUT", path: "/api/v1/admin/support/tickets/:id/status", tag: "Platform", summary: "Set a support ticket's status", perm: "platform admin", + req: supportStatusRequest{}, status: http.StatusNoContent}, {method: "GET", path: "/api/v1/admin/legal", tag: "Platform", summary: "Platform legal notice and privacy policy", perm: "platform admin", resp: obj{"documents": []legalView{}}}, {method: "PUT", path: "/api/v1/admin/legal/:kind", tag: "Platform", summary: "Set a platform legal document", perm: "platform admin", diff --git a/internal/api/audit.go b/internal/api/audit.go index 5d48df2..2191ac2 100644 --- a/internal/api/audit.go +++ b/internal/api/audit.go @@ -38,6 +38,12 @@ var auditActions = map[string]string{ "POST /api/v1/auth/login/totp": "auth.login", "POST /api/v1/auth/logout": "auth.logout", "POST /api/v1/consent": "account.consent", + "POST /api/v1/support/tickets": "support.create", + "POST /api/v1/support/tickets/:id/messages": "support.reply", + "PUT /api/v1/support/tickets/:id/status": "support.status", + "POST /api/v1/admin/support/tickets/:id/messages": "support.answer", + "PUT /api/v1/admin/support/tickets/:id/status": "support.status", + "PUT /api/v1/admin/support/settings": "support.settings", "PUT /api/v1/org/members/:user/owner": "member.owner", "PATCH /api/v1/org/incidents/:id": "incident.title", "POST /api/v1/org/incidents/:id/updates": "incident.update", diff --git a/internal/api/consent.go b/internal/api/consent.go index fdf5d1f..989a526 100644 --- a/internal/api/consent.go +++ b/internal/api/consent.go @@ -132,11 +132,13 @@ func (s *Server) accessOf(ctx context.Context, user uuid.UUID) (access, error) { } // restrictedPaths stay open to accounts that are suspended or have yet to -// accept the documents. Admins keep editing the documents, which they may -// be publishing one after the other; the handlers still check they are. +// accept the documents, support included: a suspended account may want to +// ask why. Admins keep editing the documents, which they may be publishing +// one after the other; the handlers still check they are. var restrictedPaths = []string{ "/consent", "/account/suspended", "/legal/", "/api/v1/auth/", "/api/v1/consent", "/api/v1/me/export", "/api/v1/me/delete", "/api/v1/locale", + "/support", "/support/", "/api/v1/support/", "/admin/legal", "/api/v1/admin/legal/", } @@ -249,6 +251,7 @@ func (s *Server) restrictedMe(c *gin.Context, sess *auth.Session) (web.Me, error return web.Me{}, err } me := toWebMe(m) + me.Support = s.supportSettings(c.Request.Context()).Enabled me.DeletesOrgs, err = s.lastOwnedOrgs(c.Request.Context(), sess.UserID) return me, err } diff --git a/internal/api/gdpr.go b/internal/api/gdpr.go index 8c6f2e3..f812b82 100644 --- a/internal/api/gdpr.go +++ b/internal/api/gdpr.go @@ -32,9 +32,24 @@ type accountExport struct { Identities []exportIdentity `json:"sso_identities"` Tokens []exportToken `json:"api_tokens"` Consents []exportConsent `json:"consents"` + Support []exportTicket `json:"support_tickets"` Activity []exportActivity `json:"activity"` } +type exportTicket struct { + Subject string `json:"subject"` + Status string `json:"status"` + CreatedAt time.Time `json:"created_at"` + Messages []exportTicketMessage `json:"messages"` +} + +// exportTicketMessage leaves out which admin answered: that is about them. +type exportTicketMessage struct { + Time time.Time `json:"time"` + FromStaff bool `json:"from_staff"` + Body string `json:"body"` +} + // exportConsent is an accepted version of the privacy policy or terms. type exportConsent struct { Kind string `json:"kind"` @@ -156,6 +171,22 @@ func (s *Server) buildAccountExport(ctx context.Context, userID uuid.UUID) (acco ExpiresAt: t.ExpiresAt, LastUsedAt: t.LastUsedAt, CreatedAt: t.CreatedAt, }) } + tickets, err := q.ListUserSupportTickets(ctx, userID) + if err != nil { + return err + } + x.Support = []exportTicket{} + for _, t := range tickets { + msgs, err := q.SupportMessages(ctx, t.ID) + if err != nil { + return err + } + et := exportTicket{Subject: t.Subject, Status: t.Status, CreatedAt: t.CreatedAt, Messages: []exportTicketMessage{}} + for _, m := range msgs { + et.Messages = append(et.Messages, exportTicketMessage{Time: m.CreatedAt, FromStaff: m.FromStaff, Body: m.Body}) + } + x.Support = append(x.Support, et) + } events, err := q.UserAuditEvents(ctx, &userID) if err != nil { return err diff --git a/internal/api/pages.go b/internal/api/pages.go index 8fbe92b..329c2d6 100644 --- a/internal/api/pages.go +++ b/internal/api/pages.go @@ -46,6 +46,10 @@ func (s *Server) registerPages(r gin.IRouter) { r.GET("/admin/status-pages", s.adminStatusPagesPage) r.GET("/admin/orgs", s.adminOrgsPage) r.GET("/admin/legal", s.adminLegalPage) + r.GET("/admin/support", s.adminSupportPage) + r.GET("/admin/support/:id", s.adminSupportTicketPage) + r.GET("/support", s.supportPage) + r.GET("/support/:id", s.supportTicketPage) r.GET("/settings/legal", s.orgPage("legal.org_title", authz.OrgManage, s.orgLegalView)) r.GET("/incidents/:id", s.orgPage("incidents.title", authz.IncidentsRead, s.incidentDetailView)) r.GET("/settings/incident-statuses", s.orgPage("incident_statuses.title", authz.IncidentsRead, s.incidentStatusesView)) @@ -176,6 +180,7 @@ func (s *Server) consoleMe(c *gin.Context, sess *auth.Session) (web.Me, *princip } me := toWebMe(m) me.Can = map[string]bool{} + me.Support = s.supportSettings(ctx).Enabled if sess.OrgID == uuid.Nil { return me, nil, nil } diff --git a/internal/api/server.go b/internal/api/server.go index 05c0f7a..d608b0b 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -53,6 +53,8 @@ type Server struct { checkerNet *versioned[bool] // limits caches the platform's default limits. limits *versioned[Limits] + // support caches how the platform runs support tickets. + support *versioned[supportSettings] } // Deps are the external resources a Server needs. @@ -88,6 +90,7 @@ func New(cfg config.API, d Deps) *Server { checkTypes: newVersioned[map[string]bool]("check-types"), checkerNet: newVersioned[bool]("checker-network"), limits: newVersioned[Limits]("limits"), + support: newVersioned[supportSettings]("support"), } } @@ -132,6 +135,13 @@ func (s *Server) Mount(r gin.IRouter) { me.GET("/export", s.exportAccount) me.POST("/delete", s.deleteAccount) + support := v1.Group("/support", auth.Require(), s.requireSupport()) + support.GET("/tickets", s.listMyTickets) + support.POST("/tickets", s.createTicket) + support.GET("/tickets/:id", s.getMyTicket) + support.POST("/tickets/:id/messages", s.replyMyTicket) + support.PUT("/tickets/:id/status", s.setMyTicketStatus) + v1.POST("/invitations/:token/accept", auth.Require(), s.acceptInvitation) v1.POST("/invitations/:token/signup", s.inviteSignup) @@ -203,6 +213,12 @@ func (s *Server) Mount(r gin.IRouter) { admin.GET("/regions", s.adminListRegions) admin.POST("/regions", s.adminCreateRegion) admin.DELETE("/regions/:id", s.adminDeleteRegion) + admin.GET("/support/settings", s.adminGetSupportSettings) + admin.PUT("/support/settings", s.adminSetSupportSettings) + admin.GET("/support/tickets", s.adminListTickets) + admin.GET("/support/tickets/:id", s.adminGetTicket) + admin.POST("/support/tickets/:id/messages", s.adminReplyTicket) + admin.PUT("/support/tickets/:id/status", s.adminSetTicketStatus) admin.GET("/agents", s.adminListAgents) admin.POST("/agents", s.adminCreateAgent) admin.DELETE("/agents/:id", s.adminDeleteAgent) diff --git a/internal/api/support.go b/internal/api/support.go new file mode 100644 index 0000000..3e1c18d --- /dev/null +++ b/internal/api/support.go @@ -0,0 +1,860 @@ +package api + +import ( + "context" + "errors" + "log/slog" + "net/http" + "slices" + "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/notify" + "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" +) + +// Support tickets: an account asks the platform's admins for help, also +// while it is suspended or has yet to accept the terms. A ticket is open +// while it waits for the admins and answered while it waits for the +// account; a reply from either side moves it accordingly, also out of +// closed. + +const ( + ticketOpen = "open" + ticketAnswered = "answered" + ticketClosed = "closed" +) + +type supportTicketRequest struct { + Subject string `json:"subject" binding:"required,max=200"` + Message string `json:"message" binding:"required,max=10000"` + // AttachOrg names the active organization in the ticket. Anything else + // attached comes from it and names it too. + AttachOrg bool `json:"attach_org"` + Monitor string `json:"monitor_id" binding:"max=36"` + Channel string `json:"channel_id" binding:"max=36"` + AlertGroup string `json:"alert_group_id" binding:"max=36"` + StatusPage string `json:"status_page_id" binding:"max=36"` + Incident string `json:"incident_id" binding:"max=36"` +} + +// supportReference is something a ticket points at, by kind: org, +// monitor, channel, alert_group, status_page or incident. +type supportReference struct { + Kind string `json:"kind"` + Name string `json:"name"` +} + +type supportMessageRequest struct { + Message string `json:"message" binding:"required,max=10000"` +} + +type supportStatusRequest struct { + Status string `json:"status" binding:"required,oneof=open answered closed"` +} + +type supportMessageView struct { + ID uuid.UUID `json:"id"` + FromStaff bool `json:"from_staff"` + // Author is the admin who answered, shown to admins only. + Author string `json:"author,omitempty"` + Body string `json:"body"` + CreatedAt time.Time `json:"created_at"` +} + +type supportTicketView struct { + ID uuid.UUID `json:"id"` + Subject string `json:"subject"` + Status string `json:"status"` + // Org is the organization the account was in when it opened the ticket. + Org *string `json:"org,omitempty"` + // User is the account's email, shown to admins only. + User string `json:"user,omitempty"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + References []supportReference `json:"references,omitempty"` + Messages []supportMessageView `json:"messages,omitempty"` +} + +// cleanSupportText trims text and reports whether anything is left. +func cleanSupportText(c *gin.Context, texts ...*string) bool { + for _, t := range texts { + *t = strings.TrimSpace(*t) + if *t == "" { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return false + } + } + return true +} + +// loadTicket reads a ticket with its messages in scope, which decides +// whose tickets are visible. +func (s *Server) loadTicket(ctx context.Context, scope tenant.Scope, id uuid.UUID, staff bool) (supportTicketView, error) { + var v supportTicketView + err := s.db.Tx(ctx, scope, func(q *store.Queries) error { + t, err := q.GetSupportTicket(ctx, id) + if err != nil { + return err + } + v = supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, Org: t.OrgName, CreatedAt: t.CreatedAt, UpdatedAt: t.UpdatedAt} + if staff { + v.User = t.UserEmail + } + msgs, err := q.SupportMessages(ctx, id) + for _, m := range msgs { + mv := supportMessageView{ID: m.ID, FromStaff: m.FromStaff, Body: m.Body, CreatedAt: m.CreatedAt} + if staff && m.FromStaff { + mv.Author = m.AuthorEmail + } + v.Messages = append(v.Messages, mv) + } + return err + }) + if err != nil { + return v, err + } + v.References, err = s.ticketReferences(ctx, id) + return v, err +} + +// ticketReferences names what a ticket points at. The account may no +// longer see those things, so this reads past row-level security, after +// the caller saw the ticket itself. +func (s *Server) ticketReferences(ctx context.Context, id uuid.UUID) ([]supportReference, error) { + var out []supportReference + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + r, err := q.SupportTicketReferences(ctx, id) + if err != nil { + return err + } + add := func(kind string, name *string, extra ...*string) { + if name == nil { + return + } + n := *name + for _, e := range extra { + if e != nil && *e != "" { + n += " (" + *e + ")" + } + } + out = append(out, supportReference{Kind: kind, Name: n}) + } + add("org", r.OrgName, r.OrgSlug) + add("monitor", r.MonitorName, r.MonitorType) + add("channel", r.ChannelName, r.ChannelType) + add("alert_group", r.AlertGroupName) + add("status_page", r.StatusPageTitle, r.StatusPageSlug) + if r.IncidentStartedAt != nil { + name := deref(r.IncidentMonitor) + if t := deref(r.IncidentTitle); t != "" { + name = t + " · " + name + } + name += " · " + r.IncidentStartedAt.UTC().Format(timeLayout) + add("incident", &name) + } + return nil + }) + return out, err +} + +func ticketID(c *gin.Context) (uuid.UUID, bool) { + id, err := uuid.Parse(c.Param("id")) + if err != nil { + fail(c, http.StatusNotFound, "not_found") + } + return id, err == nil +} + +func (s *Server) listMyTickets(c *gin.Context) { + sess := auth.Current(c) + ctx := c.Request.Context() + var rows []store.SupportTicket + if err := s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error { + var err error + rows, err = q.ListUserSupportTickets(ctx, sess.UserID) + return err + }); err != nil { + internalError(c, err) + return + } + out := make([]supportTicketView, len(rows)) + for i, t := range rows { + out[i] = supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, CreatedAt: t.CreatedAt, UpdatedAt: t.UpdatedAt} + } + c.JSON(http.StatusOK, gin.H{"tickets": out}) +} + +// optionalID parses a form's optional reference; empty is none. +func optionalID(v string) (*uuid.UUID, bool) { + if v = strings.TrimSpace(v); v == "" { + return nil, true + } + id, err := uuid.Parse(v) + return &id, err == nil +} + +// ticketRefs resolves what a new ticket points at. Everything comes from +// the active organization, which the account has to be able to read. +func (s *Server) ticketRefs(c *gin.Context, req supportTicketRequest) (store.CreateSupportTicketParams, bool) { + var p store.CreateSupportTicketParams + ids := []struct { + raw string + dst **uuid.UUID + perm authz.Permission + }{ + {req.Monitor, &p.MonitorID, authz.MonitorsRead}, + {req.Channel, &p.ChannelID, authz.NotificationsRead}, + {req.AlertGroup, &p.AlertGroupID, authz.NotificationsRead}, + {req.StatusPage, &p.StatusPageID, authz.StatusPagesRead}, + {req.Incident, &p.IncidentID, authz.IncidentsRead}, + } + any := req.AttachOrg + for _, r := range ids { + id, ok := optionalID(r.raw) + if !ok { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return p, false + } + *r.dst = id + any = any || id != nil + } + if !any { + return p, true + } + sess := auth.Current(c) + _, principal, err := s.consoleMe(c, sess) + if err != nil { + internalError(c, err) + return p, false + } + if principal == nil { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return p, false + } + for _, r := range ids { + if *r.dst != nil && !principal.Grants.Can(r.perm) { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return p, false + } + } + ctx := c.Request.Context() + var exists *bool + if err := s.db.Tx(ctx, principal.scope(), func(q *store.Queries) error { + var err error + exists, err = q.SupportReferencesExist(ctx, store.SupportReferencesExistParams{ + OrgID: principal.Org.ID, MonitorID: p.MonitorID, ChannelID: p.ChannelID, + AlertGroupID: p.AlertGroupID, StatusPageID: p.StatusPageID, IncidentID: p.IncidentID, + }) + return err + }); err != nil { + internalError(c, err) + return p, false + } + if exists == nil || !*exists { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return p, false + } + p.OrgID = &principal.Org.ID + return p, true +} + +// errTicketLimit and errSuspendedTicket refuse tickets beyond what the +// platform allows; the error code says which. +var ( + errTicketLimit = errors.New("api: too many open tickets") + errSuspendedTicket = errors.New("api: suspended accounts open one ticket") +) + +// checkTicketLimits refuses another open ticket for user: more than the +// platform allows at the same time, or a second since a suspension. +func checkTicketLimits(ctx context.Context, q *store.Queries, user uuid.UUID, maxOpen int, newTicket bool) error { + if newTicket { + u, err := q.GetUser(ctx, user) + if err != nil { + return err + } + if u.DisabledAt != nil { + n, err := q.CountSupportTicketsSince(ctx, store.CountSupportTicketsSinceParams{UserID: user, CreatedAt: *u.DisabledAt}) + if err != nil { + return err + } + if n > 0 { + return errSuspendedTicket + } + } + } + if maxOpen <= 0 { + return nil + } + n, err := q.CountOpenSupportTickets(ctx, user) + if err != nil { + return err + } + if n >= int64(maxOpen) { + return errTicketLimit + } + return nil +} + +// failTicketLimit answers err if it is one of the ticket limits. +func failTicketLimit(c *gin.Context, err error, maxOpen int) bool { + switch { + case errors.Is(err, errSuspendedTicket): + fail(c, http.StatusConflict, "suspended_ticket_limit") + case errors.Is(err, errTicketLimit): + fail(c, http.StatusConflict, "too_many_tickets", "Count", maxOpen) + default: + return false + } + return true +} + +func (s *Server) createTicket(c *gin.Context) { + var req supportTicketRequest + if !bind(c, &req) || !cleanSupportText(c, &req.Subject, &req.Message) { + return + } + sess := auth.Current(c) + if !s.limit(c, "support:user:"+sess.UserID.String(), 10, time.Hour) { + return + } + params, ok := s.ticketRefs(c, req) + if !ok { + return + } + params.UserID, params.Subject = sess.UserID, req.Subject + ctx := c.Request.Context() + maxOpen := s.supportSettings(ctx).MaxOpen + var t store.SupportTicket + err := s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error { + if err := checkTicketLimits(ctx, q, sess.UserID, maxOpen, true); err != nil { + return err + } + var err error + if t, err = q.CreateSupportTicket(ctx, params); err != nil { + return err + } + _, err = q.AddSupportMessage(ctx, store.AddSupportMessageParams{TicketID: t.ID, AuthorID: &sess.UserID, Body: req.Message}) + return err + }) + if failTicketLimit(c, err, maxOpen) { + return + } + if err != nil { + internalError(c, err) + return + } + auditDetail(c, "ticket", t.ID.String()) + s.mailAdmins(ctx, t.ID, t.Subject) + c.JSON(http.StatusCreated, supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, CreatedAt: t.CreatedAt, UpdatedAt: t.UpdatedAt}) +} + +func (s *Server) getMyTicket(c *gin.Context) { + id, ok := ticketID(c) + if !ok { + return + } + v, err := s.loadTicket(c.Request.Context(), tenant.User(auth.Current(c).UserID), id, false) + s.respondTicket(c, v, err) +} + +func (s *Server) respondTicket(c *gin.Context, v supportTicketView, err error) { + switch { + case errors.Is(err, pgx.ErrNoRows): + fail(c, http.StatusNotFound, "not_found") + case err != nil: + internalError(c, err) + default: + c.JSON(http.StatusOK, v) + } +} + +// replyTicket adds a message and moves the ticket to the side that has to +// answer next. +func (s *Server) replyTicket(c *gin.Context, scope tenant.Scope, author uuid.UUID, staff bool) (store.GetSupportTicketRow, bool) { + maxOpen := 0 + if !staff { + maxOpen = s.supportSettings(c.Request.Context()).MaxOpen + } + id, ok := ticketID(c) + if !ok { + return store.GetSupportTicketRow{}, false + } + var req supportMessageRequest + if !bind(c, &req) || !cleanSupportText(c, &req.Message) { + return store.GetSupportTicketRow{}, false + } + status := ticketOpen + if staff { + status = ticketAnswered + } + ctx := c.Request.Context() + var t store.GetSupportTicketRow + err := s.db.Tx(ctx, scope, func(q *store.Queries) error { + var err error + if t, err = q.GetSupportTicket(ctx, id); err != nil { + return err + } + if !staff && t.Status == ticketClosed { + if err := checkTicketLimits(ctx, q, t.UserID, maxOpen, false); err != nil { + return err + } + } + if _, err = q.AddSupportMessage(ctx, store.AddSupportMessageParams{TicketID: id, AuthorID: &author, FromStaff: staff, Body: req.Message}); err != nil { + return err + } + _, err = q.SetSupportTicketStatus(ctx, store.SetSupportTicketStatusParams{ID: id, Status: status}) + return err + }) + switch { + case errors.Is(err, pgx.ErrNoRows): + fail(c, http.StatusNotFound, "not_found") + return t, false + case failTicketLimit(c, err, maxOpen): + return t, false + case err != nil: + internalError(c, err) + return t, false + } + auditDetail(c, "ticket", id.String()) + c.JSON(http.StatusCreated, gin.H{"status": status}) + return t, true +} + +func (s *Server) replyMyTicket(c *gin.Context) { + sess := auth.Current(c) + if !s.limit(c, "support:reply:"+sess.UserID.String(), 60, time.Hour) { + return + } + if t, ok := s.replyTicket(c, tenant.User(sess.UserID), sess.UserID, false); ok { + s.mailAdmins(c.Request.Context(), t.ID, t.Subject) + } +} + +// setTicketStatus closes or reopens a ticket in scope; accounts can only +// close theirs or reopen them for the admins. +func (s *Server) setTicketStatus(c *gin.Context, scope tenant.Scope, maxOpen int, allowed ...string) { + id, ok := ticketID(c) + if !ok { + return + } + var req supportStatusRequest + if !bind(c, &req) { + return + } + if len(allowed) > 0 && !slices.Contains(allowed, req.Status) { + fail(c, http.StatusUnprocessableEntity, "invalid_input") + return + } + ctx := c.Request.Context() + var n int64 + err := s.db.Tx(ctx, scope, func(q *store.Queries) error { + if req.Status != ticketClosed && maxOpen > 0 { + cur, err := q.SupportTicketStatus(ctx, id) + if errors.Is(err, pgx.ErrNoRows) { + return nil + } + if err != nil { + return err + } + if cur == ticketClosed { + if err := checkTicketLimits(ctx, q, auth.Current(c).UserID, maxOpen, false); err != nil { + return err + } + } + } + var err error + n, err = q.SetSupportTicketStatus(ctx, store.SetSupportTicketStatusParams{ID: id, Status: req.Status}) + return err + }) + switch { + case failTicketLimit(c, err, maxOpen): + case err != nil: + internalError(c, err) + case n == 0: + fail(c, http.StatusNotFound, "not_found") + default: + auditDetail(c, "status", req.Status) + c.Status(http.StatusNoContent) + } +} + +func (s *Server) setMyTicketStatus(c *gin.Context) { + s.setTicketStatus(c, tenant.User(auth.Current(c).UserID), s.supportSettings(c.Request.Context()).MaxOpen, ticketOpen, ticketClosed) +} + +// supportStatusFilter reads the status filter of the admins' list; empty +// lists every ticket. +func supportStatusFilter(c *gin.Context) *string { + switch st := c.Query("status"); st { + case ticketOpen, ticketAnswered, ticketClosed: + return &st + case "all": + return nil + default: + open := ticketOpen + return &open + } +} + +func (s *Server) adminListTickets(c *gin.Context) { + rows, err := s.supportTickets(c.Request.Context(), supportStatusFilter(c)) + if err != nil { + internalError(c, err) + return + } + out := make([]supportTicketView, len(rows)) + for i, t := range rows { + out[i] = supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, Org: t.OrgName, User: t.UserEmail, CreatedAt: t.CreatedAt, UpdatedAt: t.UpdatedAt} + } + c.JSON(http.StatusOK, gin.H{"tickets": out}) +} + +// supportTickets lists the latest 200 tickets with status, or all. +func (s *Server) supportTickets(ctx context.Context, status *string) ([]store.ListSupportTicketsRow, error) { + var rows []store.ListSupportTicketsRow + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + var err error + rows, err = q.ListSupportTickets(ctx, status) + return err + }) + return rows, err +} + +func (s *Server) adminGetTicket(c *gin.Context) { + id, ok := ticketID(c) + if !ok { + return + } + v, err := s.loadTicket(c.Request.Context(), tenant.System(), id, true) + s.respondTicket(c, v, err) +} + +func (s *Server) adminReplyTicket(c *gin.Context) { + sess := auth.Current(c) + if t, ok := s.replyTicket(c, tenant.System(), sess.UserID, true); ok { + s.mailTicketOwner(c.Request.Context(), t) + } +} + +func (s *Server) adminSetTicketStatus(c *gin.Context) { + s.setTicketStatus(c, tenant.System(), 0) +} + +func (s *Server) ticketLink(path string) string { + return strings.TrimSuffix(s.cfg.PublicURL, "/") + path +} + +// mailAdmins tells the platform's admins that a ticket waits for them. +// Mail is a courtesy: the ticket stands without it. +func (s *Server) mailAdmins(ctx context.Context, id uuid.UUID, subject string) { + if s.smtp == nil { + return + } + var to []string + if err := s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error { + var err error + to, err = q.AdminEmails(ctx) + return err + }); err != nil || len(to) == 0 { + return + } + l := s.catalog.Match("") + data := map[string]any{"Subject": subject, "Link": s.ticketLink("/admin/support/" + id.String())} + if err := s.smtp.Send(ctx, notify.Mail{To: to, Subject: l.T("email.support_admin.subject", data), Body: l.T("email.support_admin.body", data)}); err != nil { + slog.WarnContext(ctx, "support: mail to admins failed", "ticket", id, "err", err) + } +} + +// mailTicketOwner tells the account that its ticket was answered. +func (s *Server) mailTicketOwner(ctx context.Context, t store.GetSupportTicketRow) { + if s.smtp == nil { + return + } + var locale string + _ = s.db.Tx(ctx, tenant.Global(), func(q *store.Queries) error { + u, err := q.GetUser(ctx, t.UserID) + locale = deref(u.Locale) + return err + }) + l := s.catalog.Match(locale) + data := map[string]any{"Subject": t.Subject, "Link": s.ticketLink("/support/" + t.ID.String())} + if err := s.smtp.Send(ctx, notify.Mail{To: []string{t.UserEmail}, Subject: l.T("email.support_reply.subject", data), Body: l.T("email.support_reply.body", data)}); err != nil { + slog.WarnContext(ctx, "support: mail to account failed", "ticket", t.ID, "err", err) + } +} + +// Pages. + +func toWebTicket(v supportTicketView) web.SupportTicket { + t := web.SupportTicket{ID: v.ID.String(), Subject: v.Subject, Status: v.Status, User: v.User, Updated: v.UpdatedAt.UTC().Format(timeLayout)} + if v.Org != nil { + t.Org = *v.Org + } + for _, r := range v.References { + t.References = append(t.References, web.SupportReference{Kind: r.Kind, Name: r.Name}) + } + for _, m := range v.Messages { + html, err := web.RenderMarkdown(m.Body) + if err != nil { + html = "" + } + t.Messages = append(t.Messages, web.SupportMessage{FromStaff: m.FromStaff, Author: m.Author, HTML: html, At: m.CreatedAt.UTC().Format(timeLayout)}) + } + return t +} + +// supportMe is the console frame of the support pages, which accounts +// reach also while restricted. +func (s *Server) supportMe(c *gin.Context) (*auth.Session, web.Me, *principal, bool) { + sess := auth.Current(c) + if sess == nil { + c.Redirect(http.StatusSeeOther, "/login?next="+c.Request.URL.Path) + return nil, web.Me{}, nil, false + } + me, p, err := s.consoleMe(c, sess) + if err != nil { + internalError(c, err) + return nil, web.Me{}, nil, false + } + if !me.Support { + web.Render(c, http.StatusOK, web.SupportDisabledPage(s.pageFor(c, "support.title"), me)) + return nil, web.Me{}, nil, false + } + return sess, me, p, true +} + +// supportOptions lists what of the active organization a new ticket can +// point at, as far as the account may read it. +func (s *Server) supportOptions(ctx context.Context, p *principal) (web.SupportOptions, error) { + var o web.SupportOptions + if p == nil { + return o, nil + } + o.Org = p.Org.Name + err := s.db.Tx(ctx, p.scope(), func(q *store.Queries) error { + if p.Grants.Can(authz.MonitorsRead) { + rows, err := q.SupportOptionsMonitors(ctx, p.Org.ID) + if err != nil { + return err + } + for _, r := range rows { + o.Monitors = append(o.Monitors, web.SupportOption{ID: r.ID.String(), Name: r.Name}) + } + } + if p.Grants.Can(authz.NotificationsRead) { + chans, err := q.SupportOptionsChannels(ctx, p.Org.ID) + if err != nil { + return err + } + for _, r := range chans { + o.Channels = append(o.Channels, web.SupportOption{ID: r.ID.String(), Name: r.Name + " (" + r.Type + ")"}) + } + groups, err := q.SupportOptionsAlertGroups(ctx, p.Org.ID) + if err != nil { + return err + } + for _, r := range groups { + o.AlertGroups = append(o.AlertGroups, web.SupportOption{ID: r.ID.String(), Name: r.Name}) + } + } + if p.Grants.Can(authz.StatusPagesRead) { + rows, err := q.SupportOptionsStatusPages(ctx, p.Org.ID) + if err != nil { + return err + } + for _, r := range rows { + o.StatusPages = append(o.StatusPages, web.SupportOption{ID: r.ID.String(), Name: r.Title}) + } + } + if p.Grants.Can(authz.IncidentsRead) { + rows, err := q.SupportOptionsIncidents(ctx, p.Org.ID) + if err != nil { + return err + } + for _, r := range rows { + name := r.MonitorName + if r.Title != "" { + name = r.Title + " · " + name + } + o.Incidents = append(o.Incidents, web.SupportOption{ID: r.ID.String(), Name: name + " · " + r.StartedAt.UTC().Format(timeLayout)}) + } + } + return nil + }) + return o, err +} + +func (s *Server) supportPage(c *gin.Context) { + sess, me, p, ok := s.supportMe(c) + if !ok { + return + } + ctx := c.Request.Context() + opts, err := s.supportOptions(ctx, p) + if err != nil { + internalError(c, err) + return + } + var rows []store.SupportTicket + if err := s.db.Tx(ctx, tenant.User(sess.UserID), func(q *store.Queries) error { + var err error + rows, err = q.ListUserSupportTickets(ctx, sess.UserID) + return err + }); err != nil { + internalError(c, err) + return + } + tickets := make([]web.SupportTicket, len(rows)) + for i, t := range rows { + tickets[i] = toWebTicket(supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, UpdatedAt: t.UpdatedAt}) + } + web.Render(c, http.StatusOK, web.SupportPage(s.pageFor(c, "support.title"), me, tickets, opts)) +} + +func (s *Server) supportTicketPage(c *gin.Context) { + sess, me, _, ok := s.supportMe(c) + if !ok { + return + } + s.renderTicket(c, me, tenant.User(sess.UserID), false) +} + +func (s *Server) renderTicket(c *gin.Context, me web.Me, scope tenant.Scope, staff bool) { + id, err := uuid.Parse(c.Param("id")) + var v supportTicketView + if err == nil { + v, err = s.loadTicket(c.Request.Context(), scope, id, staff) + } + if err != nil && !errors.Is(err, pgx.ErrNoRows) { + internalError(c, err) + return + } + if err != nil { + back := "/support" + if staff { + back = "/admin/support" + } + c.Redirect(http.StatusSeeOther, back) + return + } + var account *web.SupportAccount + if staff { + a, err := s.ticketAccount(c.Request.Context(), id) + if err != nil { + internalError(c, err) + return + } + account = &a + } + web.Render(c, http.StatusOK, web.SupportTicketPage(s.pageFor(c, "support.title"), me, toWebTicket(v), account)) +} + +func (s *Server) adminSupportPage(c *gin.Context) { + me, ok := s.adminMe(c) + if !ok { + return + } + status := supportStatusFilter(c) + rows, err := s.supportTickets(c.Request.Context(), status) + if err != nil { + internalError(c, err) + return + } + tickets := make([]web.SupportTicket, len(rows)) + for i, t := range rows { + tickets[i] = toWebTicket(supportTicketView{ID: t.ID, Subject: t.Subject, Status: t.Status, Org: t.OrgName, User: t.UserEmail, UpdatedAt: t.UpdatedAt}) + } + filter := "all" + if status != nil { + filter = *status + } + settings := s.supportSettings(c.Request.Context()) + web.Render(c, http.StatusOK, web.AdminSupportPage(s.pageFor(c, "support.admin_title"), me, tickets, filter, web.SupportSettings{Enabled: settings.Enabled, MaxOpen: settings.MaxOpen})) +} + +func (s *Server) adminSupportTicketPage(c *gin.Context) { + me, ok := s.adminMe(c) + if !ok { + return + } + s.renderTicket(c, me, tenant.System(), true) +} + +// ticketAccount gathers what admins need to answer a ticket: the account, +// its organizations with their limits and usage, and its other tickets. +func (s *Server) ticketAccount(ctx context.Context, ticket uuid.UUID) (web.SupportAccount, error) { + var a web.SupportAccount + platform := s.platformLimits(ctx) + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + t, err := q.GetSupportTicket(ctx, ticket) + if err != nil { + return err + } + u, err := q.GetUser(ctx, t.UserID) + if err != nil { + return err + } + a = web.SupportAccount{ + ID: u.ID.String(), Email: u.Email, Name: u.DisplayName, Created: u.CreatedAt.UTC().Format(timeLayout), + Verified: u.EmailVerifiedAt != nil, TOTP: u.TotpEnabledAt != nil, Password: u.PasswordHash != nil, + Admin: u.IsAdmin, Locale: deref(u.Locale), + } + if u.DisabledAt != nil { + a.Suspended = true + a.SuspendedReason = u.DisabledReason + } + a.OrgLimit = platform.OrgsPerAccount + if u.LimitOrgs != nil { + a.OrgLimit = int(*u.LimitOrgs) + } + owned, err := q.CountOwnedOrgs(ctx, u.ID) + if err != nil { + return err + } + a.OrgsOwned = int(owned) + if a.OpenTickets, err = q.CountOpenSupportTickets(ctx, u.ID); err != nil { + return err + } + ms, err := q.UserMemberships(ctx, u.ID) + if err != nil { + return err + } + for _, m := range ms { + o, err := q.GetOrg(ctx, m.ID) + if err != nil { + return err + } + mon, err := q.CountMonitors(ctx, o.ID) + if err != nil { + return err + } + pages, err := q.CountStatusPages(ctx, o.ID) + if err != nil { + return err + } + l := s.orgLimits(ctx, o) + org := web.SupportOrg{ + Name: o.Name, Slug: o.Slug, Owner: m.IsOwner, Current: t.OrgID != nil && *t.OrgID == o.ID, + Monitors: int(mon), MonitorLimit: l.Monitors, StatusPages: int(pages), StatusPageLimit: l.StatusPages, + RegionsPerMonitor: l.RegionsPerMonitor, + } + if o.SuspendedAt != nil { + org.Suspended = true + org.SuspendedReason = o.SuspendedReason + } + a.Orgs = append(a.Orgs, org) + } + return nil + }) + return a, err +} diff --git a/internal/api/support_settings.go b/internal/api/support_settings.go new file mode 100644 index 0000000..07dcb7c --- /dev/null +++ b/internal/api/support_settings.go @@ -0,0 +1,85 @@ +package api + +import ( + "context" + "encoding/json" + "errors" + "net/http" + + "github.com/gin-gonic/gin" + "github.com/jackc/pgx/v5" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +const settingSupport = "support" + +// supportSettings are how the platform runs its support tickets. +type supportSettings struct { + Enabled bool `json:"enabled"` + // MaxOpen limits the tickets an account has open, answered ones + // included, at the same time; 0 means unlimited. + MaxOpen int `json:"max_open_tickets" binding:"min=0,max=1000"` +} + +func defaultSupportSettings() supportSettings { return supportSettings{Enabled: true, MaxOpen: 3} } + +func (s *Server) supportSettings(ctx context.Context) supportSettings { + v, err := s.support.get(ctx, s.rdb, func(ctx context.Context) (supportSettings, error) { + v := defaultSupportSettings() + err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + raw, err := q.GetPlatformSetting(ctx, settingSupport) + if errors.Is(err, pgx.ErrNoRows) { + return nil + } + if err != nil { + return err + } + return json.Unmarshal(raw, &v) + }) + return v, err + }) + if err != nil { + s.log.WarnContext(ctx, "loading support settings failed", "error", err) + return defaultSupportSettings() + } + return v +} + +// requireSupport answers for accounts only while support is enabled; the +// admins keep their tickets either way. +func (s *Server) requireSupport() gin.HandlerFunc { + return func(c *gin.Context) { + if !s.supportSettings(c.Request.Context()).Enabled { + fail(c, http.StatusForbidden, "support_disabled") + c.Abort() + return + } + c.Next() + } +} + +func (s *Server) adminGetSupportSettings(c *gin.Context) { + c.JSON(http.StatusOK, s.supportSettings(c.Request.Context())) +} + +func (s *Server) adminSetSupportSettings(c *gin.Context) { + var req supportSettings + if !bind(c, &req) { + return + } + ctx := c.Request.Context() + raw, _ := json.Marshal(req) + auditDetail(c, "settings", req) + if err := s.db.Tx(ctx, tenant.System(), func(q *store.Queries) error { + return q.SetPlatformSetting(ctx, store.SetPlatformSettingParams{Key: settingSupport, Value: raw}) + }); err != nil { + internalError(c, err) + return + } + if err := s.support.bump(ctx, s.rdb); err != nil { + s.log.ErrorContext(ctx, "announcing support settings failed", "error", err) + } + c.Status(http.StatusNoContent) +} diff --git a/internal/api/support_test.go b/internal/api/support_test.go new file mode 100644 index 0000000..062fcee --- /dev/null +++ b/internal/api/support_test.go @@ -0,0 +1,190 @@ +package api_test + +import ( + "context" + "net/http" + "strings" + "testing" + "time" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/config" + "git.zb-server.de/ZB-Server/uptimesebi/internal/notify/notifytest" + "git.zb-server.de/ZB-Server/uptimesebi/internal/store" + "git.zb-server.de/ZB-Server/uptimesebi/internal/tenant" +) + +func TestSupportTickets(t *testing.T) { + mail := notifytest.NewSMTP(t) + e := newEnvWith(t, func(c *config.API) { c.SMTPURL, c.SignupVerify = mail.URL(), "off" }) + ctx := context.Background() + admin := e.browser(t) + admin.signup("a@"+uniq("sup")+".test", uniq("sup-")) + if err := tenant.New(e.dbPool).Tx(ctx, tenant.Global(), func(q *store.Queries) error { + return q.MakeAdmin(ctx, admin.userIDSelf()) + }); err != nil { + t.Fatal(err) + } + userEmail := "u@" + uniq("sup") + ".test" + user := e.browser(t) + user.signup(userEmail, uniq("sup-")) + userID := user.userIDSelf() + mailed := func(to, link string) { + t.Helper() + waitFor(t, 5*time.Second, "a mail with "+link, func() bool { + for _, m := range mail.Messages() { + if strings.Contains(strings.Join(m.To, ","), to) && strings.Contains(m.Data, link) { + return true + } + } + return false + }) + } + + st, body := user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": " ", "message": "x"}) + expect(t, "ticket without subject", st, body, http.StatusUnprocessableEntity, "invalid_input") + st, created := user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Checks are late", "message": "Since **Monday**."}) + if st != http.StatusCreated || created["status"] != "open" { + t.Fatalf("open ticket = %d %v", st, created) + } + id := created["id"].(string) + mailed(adminEmailOf(t, admin), "/admin/support/"+id) + + // Only the account and the admins see it. + other := e.browser(t) + other.signup("o@"+uniq("sup")+".test", uniq("sup-")) + if st, _ := other.do("GET", "/api/v1/support/tickets/"+id, nil); st != http.StatusNotFound { + t.Errorf("another account reads the ticket = %d", st) + } + if st, _ := other.do("POST", "/api/v1/support/tickets/"+id+"/messages", map[string]any{"message": "me too"}); st != http.StatusNotFound { + t.Errorf("another account replies = %d", st) + } + if st, _ := user.do("GET", "/api/v1/admin/support/tickets", nil); st != http.StatusForbidden && st != http.StatusNotFound { + t.Errorf("an account lists every ticket = %d", st) + } + _, list := admin.do("GET", "/api/v1/admin/support/tickets", nil) + if !strings.Contains(mustJSON(list), id) || !strings.Contains(mustJSON(list), userEmail) { + t.Errorf("open tickets for the admins lack it: %v", list) + } + + // Answering moves it to the account and mails it; its reply moves it back. + if st, body := admin.do("POST", "/api/v1/admin/support/tickets/"+id+"/messages", map[string]any{"message": "Fixed, sorry!"}); st != http.StatusCreated || body["status"] != "answered" { + t.Fatalf("answer = %d %v", st, body) + } + mailed(userEmail, "/support/"+id) + _, ticket := user.do("GET", "/api/v1/support/tickets/"+id, nil) + msgs, _ := ticket["messages"].([]any) + if ticket["status"] != "answered" || len(msgs) != 2 || msgs[1].(map[string]any)["from_staff"] != true || msgs[1].(map[string]any)["author"] != nil { + t.Errorf("ticket for the account = %v", ticket) + } + _, _, html := user.page("/support/" + id) + for _, want := range []string{"Checks are late", "Monday", "Fixed, sorry!", "Close ticket"} { + if !strings.Contains(html, want) { + t.Errorf("ticket page lacks %q", want) + } + } + if _, _, html := admin.page("/admin/support/" + id); !strings.Contains(html, userEmail) { + t.Error("the admins' ticket page does not name the account") + } + user.do("POST", "/api/v1/support/tickets/"+id+"/messages", map[string]any{"message": "Thanks!"}) + if _, tk := user.do("GET", "/api/v1/support/tickets/"+id, nil); tk["status"] != "open" { + t.Errorf("after the account's reply status = %v", tk["status"]) + } + + // Accounts close and reopen theirs, nothing else. + st, body = user.do("PUT", "/api/v1/support/tickets/"+id+"/status", map[string]any{"status": "answered"}) + expect(t, "account marks answered", st, body, http.StatusUnprocessableEntity, "invalid_input") + if st, _ := user.do("PUT", "/api/v1/support/tickets/"+id+"/status", map[string]any{"status": "closed"}); st != http.StatusNoContent { + t.Errorf("close = %d", st) + } + _, closed := admin.do("GET", "/api/v1/admin/support/tickets?status=closed", nil) + if !strings.Contains(mustJSON(closed), id) { + t.Error("the closed filter lacks the ticket") + } + if _, _, html := user.page("/support"); !strings.Contains(html, "Checks are late") || !strings.Contains(html, "closed") { + t.Error("the support page lacks the closed ticket") + } + + // Tickets point at things of the active organization the account can + // read, never at another's; the admins see the account at a glance. + _, mon := user.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Checkout API", "type": "heartbeat", "interval_seconds": 3600}) + _, foreign := other.do("POST", "/api/v1/org/monitors", map[string]any{"name": "Theirs", "type": "heartbeat", "interval_seconds": 3600}) + st, body = user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Peek", "message": "x", "monitor_id": foreign["id"]}) + expect(t, "ticket about another organization's monitor", st, body, http.StatusUnprocessableEntity, "invalid_input") + if _, _, page := user.page("/support"); !strings.Contains(page, `name="monitor_id"`) || !strings.Contains(page, "Checkout API") { + t.Error("the new ticket form does not offer the monitors") + } + st, withRef := user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Heartbeat missing", "message": "x", "monitor_id": mon["id"], "channel_id": ""}) + if st != http.StatusCreated { + t.Fatalf("ticket about a monitor = %d %v", st, withRef) + } + refID := withRef["id"].(string) + _, got := user.do("GET", "/api/v1/support/tickets/"+refID, nil) + if refs := mustJSON(got["references"]); !strings.Contains(refs, "Checkout API") || !strings.Contains(refs, `"org"`) { + t.Errorf("references = %s", refs) + } + if _, _, page := admin.page("/admin/support/" + refID); !strings.Contains(page, "Checkout API") || !strings.Contains(page, "Organizations owned") || !strings.Contains(page, "1 / ") { + t.Error("the admins' ticket page lacks the references or the account's details") + } + + // The admins limit open tickets per account and can switch support off. + t.Cleanup(func() { + admin.do("PUT", "/api/v1/admin/support/settings", map[string]any{"enabled": true, "max_open_tickets": 3}) + }) + if st, body := admin.do("PUT", "/api/v1/admin/support/settings", map[string]any{"enabled": true, "max_open_tickets": 2}); st != http.StatusNoContent { + t.Fatalf("set support settings = %d %v", st, body) + } + if st, body := user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Second", "message": "x"}); st != http.StatusCreated { + t.Fatalf("second open ticket = %d %v", st, body) + } + st, body = user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Third", "message": "x"}) + expect(t, "third open ticket", st, body, http.StatusConflict, "too_many_tickets") + st, body = user.do("PUT", "/api/v1/support/tickets/"+id+"/status", map[string]any{"status": "open"}) + expect(t, "reopen beyond the limit", st, body, http.StatusConflict, "too_many_tickets") + st, body = user.do("POST", "/api/v1/support/tickets/"+id+"/messages", map[string]any{"message": "again"}) + expect(t, "reply to a closed ticket beyond the limit", st, body, http.StatusConflict, "too_many_tickets") + admin.do("PUT", "/api/v1/admin/support/settings", map[string]any{"enabled": false, "max_open_tickets": 0}) + st, body = user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Off", "message": "x"}) + expect(t, "ticket while support is off", st, body, http.StatusForbidden, "support_disabled") + if _, _, page := user.page("/support"); !strings.Contains(page, "switched off") || strings.Contains(page, `href="/support"`) { + t.Error("the support page or the menu still offers support while it is off") + } + if st, _, _ := admin.page("/admin/support/" + refID); st != http.StatusOK { + t.Errorf("admins read tickets while support is off = %d", st) + } + admin.do("PUT", "/api/v1/admin/support/settings", map[string]any{"enabled": true, "max_open_tickets": 0}) + + // A suspended account can still ask why, and its export holds the + // conversation. + if st, body := admin.do("PUT", "/api/v1/admin/users/"+userID.String()+"/suspension", map[string]any{"suspended": true, "reason": "Abuse"}); st != http.StatusNoContent { + t.Fatalf("suspend = %d %v", st, body) + } + user = e.browser(t) + if st, body := user.do("POST", "/api/v1/auth/login", map[string]any{"email": userEmail, "password": password}); st != http.StatusOK { + t.Fatalf("suspended account signs in = %d %v", st, body) + } + if _, _, page := user.page("/account/suspended"); !strings.Contains(page, `href="/support"`) { + t.Error("the suspension page does not lead to support") + } + if st, body := user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Why?", "message": "I did nothing."}); st != http.StatusCreated { + t.Errorf("suspended account opens a ticket = %d %v", st, body) + } + st, body = user.do("POST", "/api/v1/support/tickets", map[string]any{"subject": "Why, again?", "message": "Hello?"}) + expect(t, "second ticket of a suspended account", st, body, http.StatusConflict, "suspended_ticket_limit") + if st, _, _ := user.page("/support"); st != http.StatusOK { + t.Errorf("support page of a suspended account = %d", st) + } + _, _, export := user.download("/api/v1/me/export") + if !strings.Contains(string(export), "Checks are late") || !strings.Contains(string(export), "Fixed, sorry!") { + t.Error("the account export lacks the tickets") + } +} + +func adminEmailOf(t *testing.T, b *browser) string { + t.Helper() + _, me := b.do("GET", "/api/v1/me", nil) + email, _ := me["email"].(string) + if email == "" { + t.Fatalf("no email in %v", me) + } + return email +} diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index d28057a..f2a8435 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -151,6 +151,11 @@ "audit.action.statuspage.groups_import": "Statusseiten-Gruppen aus Monitor-Gruppen übernommen", "audit.action.statuspage.monitors_update": "Monitore der Statusseite geändert", "audit.action.statuspage.update": "Statusseite geändert", + "audit.action.support.answer": "Support-Ticket beantwortet", + "audit.action.support.create": "Support-Ticket eröffnet", + "audit.action.support.reply": "Auf Support-Ticket geantwortet", + "audit.action.support.settings": "Support-Einstellungen geändert", + "audit.action.support.status": "Status eines Support-Tickets geändert", "audit.action.token.create": "API-Token erstellt", "audit.action.token.delete": "API-Token widerrufen", "audit.deleted_user": "Gelöschter Benutzer", @@ -513,6 +518,10 @@ "email.opened.subject": "[DOWN] {{.Monitor}}", "email.resolved.body": "{{.Monitor}} ({{.Target}}) ist nach {{.Duration}} wieder erreichbar.", "email.resolved.subject": "[UP] {{.Monitor}}", + "email.support_admin.body": "Hallo,\n\nein Support-Ticket wartet auf eine Antwort:\n\n{{.Subject}}\n\n{{.Link}}", + "email.support_admin.subject": "Support-Ticket: {{.Subject}}", + "email.support_reply.body": "Hallo,\n\nder Support hat dein Ticket „{{.Subject}}“ beantwortet:\n\n{{.Link}}\n\nWenn du weitere Fragen hast, antworte einfach dort.", + "email.support_reply.subject": "Antwort auf dein Support-Ticket: {{.Subject}}", "email.test.body": "Dies ist ein Test. Wenn du ihn lesen kannst, funktioniert der Kanal.", "email.test.subject": "Testbenachrichtigung von UptimeSebi", "email.verify.body": "Hallo,\n\nbitte bestätige deine E-Mail-Adresse, um die Registrierung abzuschließen:\n\n{{.Link}}\n\nDer Link ist {{.Hours}} Stunden gültig. Wenn du dich nicht registriert hast, ignoriere diese E-Mail; das Konto wird nach einer Woche gelöscht.", @@ -633,11 +642,14 @@ "error.status_in_use": "Updates benutzen diesen Status; er bleibt, damit ihr Verlauf verständlich bleibt. Benenne ihn um oder ändere die Farbe.", "error.status_name_taken": "Einen Status mit diesem Namen gibt es schon.", "error.status_page_limit": "Deine Organisation hat ihr Limit von {{.Max}} Statusseiten erreicht.", + "error.support_disabled": "Support-Tickets sind auf dieser Plattform abgeschaltet.", + "error.suspended_ticket_limit": "Solange dein Konto gesperrt ist, kannst du ein Ticket eröffnen. Antworte stattdessen darauf.", "error.target_is_admin": "Plattform-Admins können hier nicht gesperrt oder gelöscht werden.", "error.token_lifetime_exceeds_policy": { "one": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tag ablaufen.", "other": "Tokens in dieser Organisation müssen innerhalb von {{.Count}} Tagen ablaufen." }, + "error.too_many_tickets": "Du kannst {{.Count}} offene Tickets gleichzeitig haben. Schließe eins oder antworte stattdessen darauf.", "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.", @@ -696,6 +708,7 @@ "export.field.api_tokens": "API-Tokens", "export.field.audit_log": "Audit-Log", "export.field.avg_latency_ms": "Mittlere Latenz (ms)", + "export.field.body": "Text", "export.field.cause": "Ursache", "export.field.client_id": "Client-ID", "export.field.config": "Konfiguration", @@ -712,6 +725,7 @@ "export.field.email": "E-Mail", "export.field.enabled": "Aktiv", "export.field.expires_at": "Läuft ab", + "export.field.from_staff": "Vom Support", "export.field.generated_at": "Erstellt am", "export.field.group_id": "Gruppe", "export.field.has_password": "Passwort gesetzt", @@ -728,6 +742,7 @@ "export.field.member_since": "Mitglied seit", "export.field.members": "Mitglieder", "export.field.message": "Nachricht", + "export.field.messages": "Nachrichten", "export.field.monitor": "Monitor", "export.field.monitor_groups": "Monitorgruppen", "export.field.monitor_id": "Monitor-ID", @@ -763,6 +778,7 @@ "export.field.status": "Status", "export.field.status_pages": "Statusseiten", "export.field.subject": "Subjekt", + "export.field.support_tickets": "Support-Tickets", "export.field.target": "Ziel", "export.field.target_id": "Ziel", "export.field.time": "Zeit", @@ -1380,6 +1396,76 @@ "storage.retention": "Löschen nach", "storage.size": "Größe", "storage.title": "Datenspeicher", + "support.account": "Konto", + "support.account.active": "aktiv", + "support.account.created": "Erstellt", + "support.account.email": "E-Mail", + "support.account.email_verified": "E-Mail bestätigt", + "support.account.locale": "Sprache", + "support.account.monitors": "Monitore", + "support.account.name": "Name", + "support.account.open_tickets": "Offene Tickets", + "support.account.org_suspended": "Organisation gesperrt", + "support.account.orgs": "Organisationen", + "support.account.orgs_owned": "Eigene Organisationen", + "support.account.owner": "Owner", + "support.account.password": "Passwort", + "support.account.regions": "Regionen pro Monitor", + "support.account.role": "Rolle", + "support.account.sign_in": "Anmeldung", + "support.account.sso_only": "nur SSO", + "support.account.state": "Zustand", + "support.account.status_pages": "Statusseiten", + "support.account.suspended": "gesperrt", + "support.account.this_ticket": "im Ticket genannt", + "support.admin_intro": "Tickets aller Konten. Eine Antwort wird dem Konto per E-Mail angekündigt; schreibt es zurück, ist das Ticket wieder offen.", + "support.admin_title": "Support-Tickets", + "support.all": "Alle Tickets", + "support.attach": "Details anhängen (optional)", + "support.attach_hint": "Zeig dem Support, worum es geht – aus der aktiven Organisation.", + "support.attach_none": "keine Auswahl", + "support.attach_org": "Organisation {{.Org}}", + "support.close": "Ticket schließen", + "support.closed_hint": "Dieses Ticket ist geschlossen. Mit einer Antwort öffnest du es wieder.", + "support.contact": "Support kontaktieren", + "support.disabled": "Support-Tickets sind gerade abgeschaltet.", + "support.filter": "Tickets filtern", + "support.filter.all": "Alle", + "support.filter.answered": "Beantwortet", + "support.filter.closed": "Geschlossen", + "support.filter.open": "Offen", + "support.from_staff": "Support", + "support.from_you": "Du", + "support.intro": "Fragen, Probleme oder Feedback? Schreib dem Support der Plattform. Sobald er antwortet, bekommst du eine E-Mail.", + "support.message": "Nachricht", + "support.mine": "Deine Tickets", + "support.new": "Neues Ticket", + "support.no": "nein", + "support.none": "Du hast noch keine Tickets eröffnet.", + "support.none_admin": "Hier gibt es keine Tickets.", + "support.ref.alert_group": "Alertgruppe", + "support.ref.channel": "Alert-Typ (Benachrichtigungskanal)", + "support.ref.incident": "Incident", + "support.ref.monitor": "Monitor", + "support.ref.org": "Organisation", + "support.ref.status_page": "Statusseite", + "support.reopen": "Ticket wieder öffnen", + "support.reply": "Antworten", + "support.send": "Senden", + "support.settings": "Einstellungen", + "support.settings.enabled": "Konten können Support-Tickets eröffnen", + "support.settings.enabled_hint": "Abgeschaltet verschwinden die Support-Seiten für Konten; die bestehenden Tickets bleiben hier erhalten.", + "support.settings.max_open": "Offene Tickets pro Konto", + "support.settings.max_open_hint": "Offene und beantwortete Tickets zählen; 0 heißt unbegrenzt. Gesperrte Konten können ein Ticket eröffnen.", + "support.settings.off": "aus", + "support.settings.on": "an", + "support.settings.save": "Speichern", + "support.status.answered": "beantwortet", + "support.status.closed": "geschlossen", + "support.status.open": "offen", + "support.subject": "Betreff", + "support.title": "Support", + "support.yes": "ja", "suspended.intro": "Die Administratoren der Plattform haben dein Konto gesperrt.", "suspended.options": "Du kannst deine Daten weiterhin herunterladen oder dein Konto löschen.", "suspended.title": "Konto gesperrt", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index 0d30b25..1bd3ca1 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -151,6 +151,11 @@ "audit.action.statuspage.groups_import": "Status page groups imported from monitor groups", "audit.action.statuspage.monitors_update": "Status page monitors changed", "audit.action.statuspage.update": "Status page changed", + "audit.action.support.answer": "Support ticket answered", + "audit.action.support.create": "Support ticket opened", + "audit.action.support.reply": "Support ticket replied to", + "audit.action.support.settings": "Support settings changed", + "audit.action.support.status": "Support ticket status changed", "audit.action.token.create": "API token created", "audit.action.token.delete": "API token revoked", "audit.deleted_user": "Deleted user", @@ -513,6 +518,10 @@ "email.opened.subject": "[DOWN] {{.Monitor}}", "email.resolved.body": "{{.Monitor}} ({{.Target}}) is reachable again after {{.Duration}}.", "email.resolved.subject": "[UP] {{.Monitor}}", + "email.support_admin.body": "Hello,\n\na support ticket waits for an answer:\n\n{{.Subject}}\n\n{{.Link}}", + "email.support_admin.subject": "Support ticket: {{.Subject}}", + "email.support_reply.body": "Hello,\n\nthe support team answered your ticket \"{{.Subject}}\":\n\n{{.Link}}\n\nReply there if you have further questions.", + "email.support_reply.subject": "Answer to your support ticket: {{.Subject}}", "email.test.body": "This is a test. If you can read it, the channel works.", "email.test.subject": "Test notification from UptimeSebi", "email.verify.body": "Hello,\n\nplease confirm your email address to finish signing up:\n\n{{.Link}}\n\nThe link is valid for {{.Hours}} hours. If you did not sign up, ignore this email; the account is deleted after a week.", @@ -633,11 +642,14 @@ "error.status_in_use": "Updates use this status; it stays so their history keeps its meaning. Rename or recolor it instead.", "error.status_name_taken": "A status with this name exists already.", "error.status_page_limit": "Your organization has reached its limit of {{.Max}} status pages.", + "error.support_disabled": "Support tickets are switched off on this platform.", + "error.suspended_ticket_limit": "While your account is suspended you can open one ticket. Reply to it instead.", "error.target_is_admin": "Platform admins cannot be suspended or deleted here.", "error.token_lifetime_exceeds_policy": { "one": "Tokens in this organization must expire within {{.Count}} day.", "other": "Tokens in this organization must expire within {{.Count}} days." }, + "error.too_many_tickets": "You can have {{.Count}} open tickets at the same time. Close one or reply to it instead.", "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.", @@ -696,6 +708,7 @@ "export.field.api_tokens": "API tokens", "export.field.audit_log": "Audit log", "export.field.avg_latency_ms": "Average latency (ms)", + "export.field.body": "Text", "export.field.cause": "Cause", "export.field.client_id": "Client ID", "export.field.config": "Configuration", @@ -712,6 +725,7 @@ "export.field.email": "Email", "export.field.enabled": "Enabled", "export.field.expires_at": "Expires", + "export.field.from_staff": "From support", "export.field.generated_at": "Generated", "export.field.group_id": "Group", "export.field.has_password": "Password set", @@ -728,6 +742,7 @@ "export.field.member_since": "Member since", "export.field.members": "Members", "export.field.message": "Message", + "export.field.messages": "Messages", "export.field.monitor": "Monitor", "export.field.monitor_groups": "Monitor groups", "export.field.monitor_id": "Monitor ID", @@ -763,6 +778,7 @@ "export.field.status": "Status", "export.field.status_pages": "Status pages", "export.field.subject": "Subject", + "export.field.support_tickets": "Support tickets", "export.field.target": "Target", "export.field.target_id": "Target", "export.field.time": "Time", @@ -1380,6 +1396,76 @@ "storage.retention": "Delete after", "storage.size": "Size", "storage.title": "Data storage", + "support.account": "Account", + "support.account.active": "active", + "support.account.created": "Created", + "support.account.email": "Email", + "support.account.email_verified": "Email verified", + "support.account.locale": "Language", + "support.account.monitors": "Monitors", + "support.account.name": "Name", + "support.account.open_tickets": "Open tickets", + "support.account.org_suspended": "Organization suspended", + "support.account.orgs": "Organizations", + "support.account.orgs_owned": "Organizations owned", + "support.account.owner": "Owner", + "support.account.password": "Password", + "support.account.regions": "Regions per monitor", + "support.account.role": "Role", + "support.account.sign_in": "Sign-in", + "support.account.sso_only": "SSO only", + "support.account.state": "State", + "support.account.status_pages": "Status pages", + "support.account.suspended": "suspended", + "support.account.this_ticket": "named in the ticket", + "support.admin_intro": "Tickets of every account. Answering mails the account; its reply puts the ticket back among the open ones.", + "support.admin_title": "Support tickets", + "support.all": "All tickets", + "support.attach": "Attach details (optional)", + "support.attach_hint": "Point the support team at what your question is about, from the active organization.", + "support.attach_none": "none", + "support.attach_org": "Organization {{.Org}}", + "support.close": "Close ticket", + "support.closed_hint": "This ticket is closed. Replying opens it again.", + "support.contact": "Contact support", + "support.disabled": "Support tickets are switched off at the moment.", + "support.filter": "Filter tickets", + "support.filter.all": "All", + "support.filter.answered": "Answered", + "support.filter.closed": "Closed", + "support.filter.open": "Open", + "support.from_staff": "Support", + "support.from_you": "You", + "support.intro": "Questions, problems or feedback? Write to the platform's support team. You get an email as soon as they answer.", + "support.message": "Message", + "support.mine": "Your tickets", + "support.new": "New ticket", + "support.no": "no", + "support.none": "You have not opened any tickets yet.", + "support.none_admin": "No tickets here.", + "support.ref.alert_group": "Alert group", + "support.ref.channel": "Alert type (notification channel)", + "support.ref.incident": "Incident", + "support.ref.monitor": "Monitor", + "support.ref.org": "Organization", + "support.ref.status_page": "Status page", + "support.reopen": "Reopen ticket", + "support.reply": "Reply", + "support.send": "Send", + "support.settings": "Settings", + "support.settings.enabled": "Accounts can open support tickets", + "support.settings.enabled_hint": "Switched off, the support pages disappear for accounts; you keep the existing tickets here.", + "support.settings.max_open": "Open tickets per account", + "support.settings.max_open_hint": "Open and answered tickets count; 0 means unlimited. Suspended accounts can open one ticket.", + "support.settings.off": "off", + "support.settings.on": "on", + "support.settings.save": "Save", + "support.status.answered": "answered", + "support.status.closed": "closed", + "support.status.open": "open", + "support.subject": "Subject", + "support.title": "Support", + "support.yes": "yes", "suspended.intro": "The platform's administrators have suspended your account.", "suspended.options": "You can still download your data or delete your account.", "suspended.title": "Account suspended", diff --git a/internal/migrations/alert_groups_test.go b/internal/migrations/alert_groups_test.go index e0be053..3769b3a 100644 --- a/internal/migrations/alert_groups_test.go +++ b/internal/migrations/alert_groups_test.go @@ -34,6 +34,15 @@ func TestAlertGroupsBackfill(t *testing.T) { if _, err := tx.Exec(ctx, "SET LOCAL app.scope = 'system'"); err != nil { t.Fatal(err) } + // Support tickets point at alert groups; take them back first. + later, err := files.ReadFile("sql/00051_support_tickets.sql") + if err != nil { + t.Fatal(err) + } + _, laterDown, _ := strings.Cut(string(later), "-- +goose Down") + if _, err := tx.Exec(ctx, laterDown); err != nil { + t.Fatalf("down 00051: %v", err) + } raw, err := files.ReadFile("sql/00039_alert_groups.sql") if err != nil { t.Fatal(err) diff --git a/internal/migrations/sql/00051_support_tickets.sql b/internal/migrations/sql/00051_support_tickets.sql new file mode 100644 index 0000000..6544820 --- /dev/null +++ b/internal/migrations/sql/00051_support_tickets.sql @@ -0,0 +1,51 @@ +-- +goose Up +-- Accounts ask the platform's admins for help. A ticket belongs to the +-- account that opened it, even a suspended one; deleting the account +-- deletes its tickets. It may point at an organization and things in it +-- the question is about; deleting those leaves the ticket. +CREATE TABLE support_tickets ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE, + org_id uuid REFERENCES orgs (id) ON DELETE SET NULL, + monitor_id uuid REFERENCES monitors (id) ON DELETE SET NULL, + channel_id uuid REFERENCES notification_channels (id) ON DELETE SET NULL, + alert_group_id uuid REFERENCES alert_groups (id) ON DELETE SET NULL, + status_page_id uuid REFERENCES status_pages (id) ON DELETE SET NULL, + incident_id uuid REFERENCES incidents (id) ON DELETE SET NULL, + subject text NOT NULL CHECK (length(subject) BETWEEN 1 AND 200), + -- open waits for the admins, answered for the account. + status text NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'answered', 'closed')), + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); +CREATE INDEX support_tickets_user_idx ON support_tickets (user_id, updated_at DESC); +CREATE INDEX support_tickets_status_idx ON support_tickets (status, updated_at DESC); + +CREATE TABLE support_messages ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + ticket_id uuid NOT NULL REFERENCES support_tickets (id) ON DELETE CASCADE, + -- author_id is empty once the admin who wrote it is deleted. + author_id uuid REFERENCES users (id) ON DELETE SET NULL, + from_staff boolean NOT NULL, + body text NOT NULL CHECK (length(body) BETWEEN 1 AND 10000), + created_at timestamptz NOT NULL DEFAULT now() +); +CREATE INDEX support_messages_ticket_idx ON support_messages (ticket_id, created_at); + +ALTER TABLE support_tickets ENABLE ROW LEVEL SECURITY; +ALTER TABLE support_tickets FORCE ROW LEVEL SECURITY; +CREATE POLICY support_tickets_own ON support_tickets FOR ALL + USING (app_scope_system() OR user_id = app_user_id()) + WITH CHECK (app_scope_system() OR user_id = app_user_id()); + +ALTER TABLE support_messages ENABLE ROW LEVEL SECURITY; +ALTER TABLE support_messages FORCE ROW LEVEL SECURITY; +CREATE POLICY support_messages_own ON support_messages FOR ALL + USING (app_scope_system() OR EXISTS ( + SELECT 1 FROM support_tickets t WHERE t.id = ticket_id AND t.user_id = app_user_id())) + WITH CHECK (app_scope_system() OR (NOT from_staff AND EXISTS ( + SELECT 1 FROM support_tickets t WHERE t.id = ticket_id AND t.user_id = app_user_id()))); + +-- +goose Down +DROP TABLE support_messages; +DROP TABLE support_tickets; diff --git a/internal/store/models.go b/internal/store/models.go index 7e8c5bb..0048349 100644 --- a/internal/store/models.go +++ b/internal/store/models.go @@ -441,6 +441,30 @@ type StatusPageMonitor struct { GroupID *uuid.UUID } +type SupportMessage struct { + ID uuid.UUID + TicketID uuid.UUID + AuthorID *uuid.UUID + FromStaff bool + Body string + CreatedAt time.Time +} + +type SupportTicket struct { + ID uuid.UUID + UserID uuid.UUID + OrgID *uuid.UUID + MonitorID *uuid.UUID + ChannelID *uuid.UUID + AlertGroupID *uuid.UUID + StatusPageID *uuid.UUID + IncidentID *uuid.UUID + Subject string + Status string + CreatedAt time.Time + UpdatedAt time.Time +} + type User struct { ID uuid.UUID Email string diff --git a/internal/store/querier.go b/internal/store/querier.go index caca5b2..c8fc1ec 100644 --- a/internal/store/querier.go +++ b/internal/store/querier.go @@ -22,6 +22,8 @@ type Querier interface { AddMonitorAlertGroup(ctx context.Context, arg AddMonitorAlertGroupParams) (int64, error) AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error + AddSupportMessage(ctx context.Context, arg AddSupportMessageParams) (SupportMessage, error) + AdminEmails(ctx context.Context) ([]string, error) // System scope: organizations with their usage, limit overrides and owner, // matching search in name, slug or owner email; newest first, a page from a // keyset cursor. @@ -50,10 +52,12 @@ type Querier interface { ClearStatusPageGroups(ctx context.Context, pageID uuid.UUID) error ClearStatusPageMonitors(ctx context.Context, pageID uuid.UUID) error CountMonitors(ctx context.Context, orgID uuid.UUID) (int64, error) + CountOpenSupportTickets(ctx context.Context, userID uuid.UUID) (int64, error) CountOwnedOrgs(ctx context.Context, userID uuid.UUID) (int64, error) CountOwners(ctx context.Context, orgID uuid.UUID) (int64, error) CountRoleAssignments(ctx context.Context, roleID uuid.UUID) (int64, error) CountStatusPages(ctx context.Context, orgID uuid.UUID) (int64, error) + CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error) CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error) // Ways the account can sign in besides platform identities. CountUserSignIns(ctx context.Context, id uuid.UUID) (int32, error) @@ -77,6 +81,7 @@ type Querier interface { CreateSSOProvider(ctx context.Context, arg CreateSSOProviderParams) (SsoProvider, error) CreateStatusPage(ctx context.Context, arg CreateStatusPageParams) (StatusPage, error) CreateStatusPageGroup(ctx context.Context, arg CreateStatusPageGroupParams) (StatusPageGroup, error) + CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]DailyBucketsRow, error) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error) @@ -160,6 +165,7 @@ type Querier interface { GetRole(ctx context.Context, id uuid.UUID) (Role, error) GetSSOProvider(ctx context.Context, id uuid.UUID) (SsoProvider, error) GetStatusPage(ctx context.Context, id uuid.UUID) (StatusPage, error) + GetSupportTicket(ctx context.Context, id uuid.UUID) (GetSupportTicketRow, error) GetUser(ctx context.Context, id uuid.UUID) (User, error) GetUserByEmail(ctx context.Context, email string) (User, error) // System scope: the monitor a ping token belongs to. @@ -234,9 +240,14 @@ type Querier interface { ListSSOProviders(ctx context.Context) ([]SsoProvider, error) ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error) ListStatusPages(ctx context.Context) ([]StatusPage, error) + // Every account's tickets for the admins, those waiting for them first. + ListSupportTickets(ctx context.Context, status *string) ([]ListSupportTicketsRow, error) ListUserIdentitiesInOrg(ctx context.Context, userID uuid.UUID) ([]ListUserIdentitiesInOrgRow, error) ListUserOrgs(ctx context.Context, userID uuid.UUID) ([]ListUserOrgsRow, error) ListUserPlatformIdentities(ctx context.Context, userID uuid.UUID) ([]ListUserPlatformIdentitiesRow, error) + // The tickets row-level security lets the account see, newest activity + // first. + ListUserSupportTickets(ctx context.Context, userID uuid.UUID) ([]SupportTicket, error) // Row-level security limits this to platform regions and the scope's org; // the org's own regions come first. ListVisibleRegions(ctx context.Context) ([]Region, error) @@ -333,6 +344,7 @@ type Querier interface { // Changing the domain drops a previous verification. SetStatusPageDomain(ctx context.Context, arg SetStatusPageDomainParams) (StatusPage, error) SetStatusPageMonitorGroup(ctx context.Context, arg SetStatusPageMonitorGroupParams) error + SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error) SetUserAdmin(ctx context.Context, arg SetUserAdminParams) (int64, error) SetUserLocale(ctx context.Context, arg SetUserLocaleParams) error SetUserOrgLimit(ctx context.Context, arg SetUserOrgLimitParams) (SetUserOrgLimitRow, error) @@ -346,6 +358,18 @@ type Querier interface { StorageGet(ctx context.Context, arg StorageGetParams) (StorageGetRow, error) StorageList(ctx context.Context, arg StorageListParams) ([]StorageListRow, error) StoragePut(ctx context.Context, arg StoragePutParams) error + SupportMessages(ctx context.Context, ticketID uuid.UUID) ([]SupportMessagesRow, error) + SupportOptionsAlertGroups(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsAlertGroupsRow, error) + SupportOptionsChannels(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsChannelsRow, error) + SupportOptionsIncidents(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsIncidentsRow, error) + SupportOptionsMonitors(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsMonitorsRow, error) + SupportOptionsStatusPages(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsStatusPagesRow, error) + // Whether everything a new ticket points at belongs to org; run in the + // organization's scope so only what the account may see counts. + SupportReferencesExist(ctx context.Context, arg SupportReferencesExistParams) (*bool, error) + // The names of what a ticket points at, for showing it. + SupportTicketReferences(ctx context.Context, id uuid.UUID) (SupportTicketReferencesRow, error) + SupportTicketStatus(ctx context.Context, id uuid.UUID) (string, error) SuspendOrg(ctx context.Context, arg SuspendOrgParams) (SuspendOrgRow, error) SuspendStatusPage(ctx context.Context, arg SuspendStatusPageParams) (SuspendStatusPageRow, error) SuspendUser(ctx context.Context, arg SuspendUserParams) (SuspendUserRow, error) diff --git a/internal/store/queries/support.sql b/internal/store/queries/support.sql new file mode 100644 index 0000000..71ae15e --- /dev/null +++ b/internal/store/queries/support.sql @@ -0,0 +1,97 @@ +-- name: CreateSupportTicket :one +INSERT INTO support_tickets (user_id, org_id, subject, monitor_id, channel_id, alert_group_id, status_page_id, incident_id) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8) +RETURNING *; + +-- name: SupportReferencesExist :one +-- Whether everything a new ticket points at belongs to org; run in the +-- organization's scope so only what the account may see counts. +SELECT (sqlc.narg(monitor_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM monitors m WHERE m.id = sqlc.narg(monitor_id) AND m.org_id = sqlc.arg(org_id)::uuid)) + AND (sqlc.narg(channel_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM notification_channels c WHERE c.id = sqlc.narg(channel_id) AND c.org_id = sqlc.arg(org_id)::uuid)) + AND (sqlc.narg(alert_group_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM alert_groups g WHERE g.id = sqlc.narg(alert_group_id) AND g.org_id = sqlc.arg(org_id)::uuid)) + AND (sqlc.narg(status_page_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM status_pages p WHERE p.id = sqlc.narg(status_page_id) AND p.org_id = sqlc.arg(org_id)::uuid)) + AND (sqlc.narg(incident_id)::uuid IS NULL OR EXISTS (SELECT 1 FROM incidents i WHERE i.id = sqlc.narg(incident_id) AND i.org_id = sqlc.arg(org_id)::uuid)) + AS ok; + +-- name: SupportTicketReferences :one +-- The names of what a ticket points at, for showing it. +SELECT o.name AS org_name, o.slug AS org_slug, + m.name AS monitor_name, m.type AS monitor_type, + ch.name AS channel_name, ch.type AS channel_type, + ag.name AS alert_group_name, + sp.title AS status_page_title, sp.slug AS status_page_slug, + i.title AS incident_title, i.started_at AS incident_started_at, im.name AS incident_monitor +FROM support_tickets t +LEFT JOIN orgs o ON o.id = t.org_id +LEFT JOIN monitors m ON m.id = t.monitor_id +LEFT JOIN notification_channels ch ON ch.id = t.channel_id +LEFT JOIN alert_groups ag ON ag.id = t.alert_group_id +LEFT JOIN status_pages sp ON sp.id = t.status_page_id +LEFT JOIN incidents i ON i.id = t.incident_id +LEFT JOIN monitors im ON im.id = i.monitor_id +WHERE t.id = $1; + +-- name: SupportOptionsMonitors :many +SELECT id, name FROM monitors WHERE org_id = $1 ORDER BY lower(name) LIMIT 500; + +-- name: SupportOptionsChannels :many +SELECT id, name, type FROM notification_channels WHERE org_id = $1 ORDER BY lower(name) LIMIT 500; + +-- name: SupportOptionsAlertGroups :many +SELECT id, name FROM alert_groups WHERE org_id = $1 ORDER BY lower(name) LIMIT 500; + +-- name: SupportOptionsStatusPages :many +SELECT id, title FROM status_pages WHERE org_id = $1 ORDER BY lower(title) LIMIT 500; + +-- name: SupportOptionsIncidents :many +SELECT i.id, i.title, i.started_at, m.name AS monitor_name +FROM incidents i JOIN monitors m ON m.id = i.monitor_id +WHERE i.org_id = $1 ORDER BY i.started_at DESC LIMIT 50; + +-- name: AddSupportMessage :one +INSERT INTO support_messages (ticket_id, author_id, from_staff, body) VALUES ($1, $2, $3, $4) +RETURNING *; + +-- name: SetSupportTicketStatus :execrows +UPDATE support_tickets SET status = $2, updated_at = now() WHERE id = $1; + +-- name: GetSupportTicket :one +SELECT t.*, u.email AS user_email, o.name AS org_name +FROM support_tickets t +JOIN users u ON u.id = t.user_id +LEFT JOIN orgs o ON o.id = t.org_id +WHERE t.id = $1; + +-- name: ListUserSupportTickets :many +-- The tickets row-level security lets the account see, newest activity +-- first. +SELECT * FROM support_tickets WHERE user_id = $1 ORDER BY updated_at DESC LIMIT 200; + +-- name: ListSupportTickets :many +-- Every account's tickets for the admins, those waiting for them first. +SELECT t.*, u.email AS user_email, o.name AS org_name +FROM support_tickets t +JOIN users u ON u.id = t.user_id +LEFT JOIN orgs o ON o.id = t.org_id +WHERE sqlc.narg(status)::text IS NULL OR t.status = sqlc.narg(status)::text +ORDER BY t.status = 'open' DESC, t.updated_at DESC +LIMIT 200; + +-- name: SupportMessages :many +SELECT m.*, coalesce(u.email, '')::text AS author_email +FROM support_messages m +LEFT JOIN users u ON u.id = m.author_id +WHERE m.ticket_id = $1 +ORDER BY m.created_at, m.id; + +-- name: AdminEmails :many +SELECT email FROM users WHERE is_admin AND disabled_at IS NULL ORDER BY email; + +-- name: CountOpenSupportTickets :one +SELECT count(*) FROM support_tickets WHERE user_id = $1 AND status <> 'closed'; + +-- name: CountSupportTicketsSince :one +SELECT count(*) FROM support_tickets WHERE user_id = $1 AND created_at >= $2; + +-- name: SupportTicketStatus :one +SELECT status FROM support_tickets WHERE id = $1; diff --git a/internal/store/support.sql.go b/internal/store/support.sql.go new file mode 100644 index 0000000..c4bb668 --- /dev/null +++ b/internal/store/support.sql.go @@ -0,0 +1,607 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: support.sql + +package store + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const addSupportMessage = `-- name: AddSupportMessage :one +INSERT INTO support_messages (ticket_id, author_id, from_staff, body) VALUES ($1, $2, $3, $4) +RETURNING id, ticket_id, author_id, from_staff, body, created_at +` + +type AddSupportMessageParams struct { + TicketID uuid.UUID + AuthorID *uuid.UUID + FromStaff bool + Body string +} + +func (q *Queries) AddSupportMessage(ctx context.Context, arg AddSupportMessageParams) (SupportMessage, error) { + row := q.db.QueryRow(ctx, addSupportMessage, + arg.TicketID, + arg.AuthorID, + arg.FromStaff, + arg.Body, + ) + var i SupportMessage + err := row.Scan( + &i.ID, + &i.TicketID, + &i.AuthorID, + &i.FromStaff, + &i.Body, + &i.CreatedAt, + ) + return i, err +} + +const adminEmails = `-- name: AdminEmails :many +SELECT email FROM users WHERE is_admin AND disabled_at IS NULL ORDER BY email +` + +func (q *Queries) AdminEmails(ctx context.Context) ([]string, error) { + rows, err := q.db.Query(ctx, adminEmails) + if err != nil { + return nil, err + } + defer rows.Close() + items := []string{} + for rows.Next() { + var email string + if err := rows.Scan(&email); err != nil { + return nil, err + } + items = append(items, email) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const countOpenSupportTickets = `-- name: CountOpenSupportTickets :one +SELECT count(*) FROM support_tickets WHERE user_id = $1 AND status <> 'closed' +` + +func (q *Queries) CountOpenSupportTickets(ctx context.Context, userID uuid.UUID) (int64, error) { + row := q.db.QueryRow(ctx, countOpenSupportTickets, userID) + var count int64 + err := row.Scan(&count) + return count, err +} + +const countSupportTicketsSince = `-- name: CountSupportTicketsSince :one +SELECT count(*) FROM support_tickets WHERE user_id = $1 AND created_at >= $2 +` + +type CountSupportTicketsSinceParams struct { + UserID uuid.UUID + CreatedAt time.Time +} + +func (q *Queries) CountSupportTicketsSince(ctx context.Context, arg CountSupportTicketsSinceParams) (int64, error) { + row := q.db.QueryRow(ctx, countSupportTicketsSince, arg.UserID, arg.CreatedAt) + var count int64 + err := row.Scan(&count) + return count, err +} + +const createSupportTicket = `-- name: CreateSupportTicket :one +INSERT INTO support_tickets (user_id, org_id, subject, monitor_id, channel_id, alert_group_id, status_page_id, incident_id) +VALUES ($1, $2, $3, $4, $5, $6, $7, $8) +RETURNING id, user_id, org_id, monitor_id, channel_id, alert_group_id, status_page_id, incident_id, subject, status, created_at, updated_at +` + +type CreateSupportTicketParams struct { + UserID uuid.UUID + OrgID *uuid.UUID + Subject string + MonitorID *uuid.UUID + ChannelID *uuid.UUID + AlertGroupID *uuid.UUID + StatusPageID *uuid.UUID + IncidentID *uuid.UUID +} + +func (q *Queries) CreateSupportTicket(ctx context.Context, arg CreateSupportTicketParams) (SupportTicket, error) { + row := q.db.QueryRow(ctx, createSupportTicket, + arg.UserID, + arg.OrgID, + arg.Subject, + arg.MonitorID, + arg.ChannelID, + arg.AlertGroupID, + arg.StatusPageID, + arg.IncidentID, + ) + var i SupportTicket + err := row.Scan( + &i.ID, + &i.UserID, + &i.OrgID, + &i.MonitorID, + &i.ChannelID, + &i.AlertGroupID, + &i.StatusPageID, + &i.IncidentID, + &i.Subject, + &i.Status, + &i.CreatedAt, + &i.UpdatedAt, + ) + return i, err +} + +const getSupportTicket = `-- name: GetSupportTicket :one +SELECT t.id, t.user_id, t.org_id, t.monitor_id, t.channel_id, t.alert_group_id, t.status_page_id, t.incident_id, t.subject, t.status, t.created_at, t.updated_at, u.email AS user_email, o.name AS org_name +FROM support_tickets t +JOIN users u ON u.id = t.user_id +LEFT JOIN orgs o ON o.id = t.org_id +WHERE t.id = $1 +` + +type GetSupportTicketRow struct { + ID uuid.UUID + UserID uuid.UUID + OrgID *uuid.UUID + MonitorID *uuid.UUID + ChannelID *uuid.UUID + AlertGroupID *uuid.UUID + StatusPageID *uuid.UUID + IncidentID *uuid.UUID + Subject string + Status string + CreatedAt time.Time + UpdatedAt time.Time + UserEmail string + OrgName *string +} + +func (q *Queries) GetSupportTicket(ctx context.Context, id uuid.UUID) (GetSupportTicketRow, error) { + row := q.db.QueryRow(ctx, getSupportTicket, id) + var i GetSupportTicketRow + err := row.Scan( + &i.ID, + &i.UserID, + &i.OrgID, + &i.MonitorID, + &i.ChannelID, + &i.AlertGroupID, + &i.StatusPageID, + &i.IncidentID, + &i.Subject, + &i.Status, + &i.CreatedAt, + &i.UpdatedAt, + &i.UserEmail, + &i.OrgName, + ) + return i, err +} + +const listSupportTickets = `-- name: ListSupportTickets :many +SELECT t.id, t.user_id, t.org_id, t.monitor_id, t.channel_id, t.alert_group_id, t.status_page_id, t.incident_id, t.subject, t.status, t.created_at, t.updated_at, u.email AS user_email, o.name AS org_name +FROM support_tickets t +JOIN users u ON u.id = t.user_id +LEFT JOIN orgs o ON o.id = t.org_id +WHERE $1::text IS NULL OR t.status = $1::text +ORDER BY t.status = 'open' DESC, t.updated_at DESC +LIMIT 200 +` + +type ListSupportTicketsRow struct { + ID uuid.UUID + UserID uuid.UUID + OrgID *uuid.UUID + MonitorID *uuid.UUID + ChannelID *uuid.UUID + AlertGroupID *uuid.UUID + StatusPageID *uuid.UUID + IncidentID *uuid.UUID + Subject string + Status string + CreatedAt time.Time + UpdatedAt time.Time + UserEmail string + OrgName *string +} + +// Every account's tickets for the admins, those waiting for them first. +func (q *Queries) ListSupportTickets(ctx context.Context, status *string) ([]ListSupportTicketsRow, error) { + rows, err := q.db.Query(ctx, listSupportTickets, status) + if err != nil { + return nil, err + } + defer rows.Close() + items := []ListSupportTicketsRow{} + for rows.Next() { + var i ListSupportTicketsRow + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.OrgID, + &i.MonitorID, + &i.ChannelID, + &i.AlertGroupID, + &i.StatusPageID, + &i.IncidentID, + &i.Subject, + &i.Status, + &i.CreatedAt, + &i.UpdatedAt, + &i.UserEmail, + &i.OrgName, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUserSupportTickets = `-- name: ListUserSupportTickets :many +SELECT id, user_id, org_id, monitor_id, channel_id, alert_group_id, status_page_id, incident_id, subject, status, created_at, updated_at FROM support_tickets WHERE user_id = $1 ORDER BY updated_at DESC LIMIT 200 +` + +// The tickets row-level security lets the account see, newest activity +// first. +func (q *Queries) ListUserSupportTickets(ctx context.Context, userID uuid.UUID) ([]SupportTicket, error) { + rows, err := q.db.Query(ctx, listUserSupportTickets, userID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportTicket{} + for rows.Next() { + var i SupportTicket + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.OrgID, + &i.MonitorID, + &i.ChannelID, + &i.AlertGroupID, + &i.StatusPageID, + &i.IncidentID, + &i.Subject, + &i.Status, + &i.CreatedAt, + &i.UpdatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const setSupportTicketStatus = `-- name: SetSupportTicketStatus :execrows +UPDATE support_tickets SET status = $2, updated_at = now() WHERE id = $1 +` + +type SetSupportTicketStatusParams struct { + ID uuid.UUID + Status string +} + +func (q *Queries) SetSupportTicketStatus(ctx context.Context, arg SetSupportTicketStatusParams) (int64, error) { + result, err := q.db.Exec(ctx, setSupportTicketStatus, arg.ID, arg.Status) + if err != nil { + return 0, err + } + return result.RowsAffected(), nil +} + +const supportMessages = `-- name: SupportMessages :many +SELECT m.id, m.ticket_id, m.author_id, m.from_staff, m.body, m.created_at, coalesce(u.email, '')::text AS author_email +FROM support_messages m +LEFT JOIN users u ON u.id = m.author_id +WHERE m.ticket_id = $1 +ORDER BY m.created_at, m.id +` + +type SupportMessagesRow struct { + ID uuid.UUID + TicketID uuid.UUID + AuthorID *uuid.UUID + FromStaff bool + Body string + CreatedAt time.Time + AuthorEmail string +} + +func (q *Queries) SupportMessages(ctx context.Context, ticketID uuid.UUID) ([]SupportMessagesRow, error) { + rows, err := q.db.Query(ctx, supportMessages, ticketID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportMessagesRow{} + for rows.Next() { + var i SupportMessagesRow + if err := rows.Scan( + &i.ID, + &i.TicketID, + &i.AuthorID, + &i.FromStaff, + &i.Body, + &i.CreatedAt, + &i.AuthorEmail, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportOptionsAlertGroups = `-- name: SupportOptionsAlertGroups :many +SELECT id, name FROM alert_groups WHERE org_id = $1 ORDER BY lower(name) LIMIT 500 +` + +type SupportOptionsAlertGroupsRow struct { + ID uuid.UUID + Name string +} + +func (q *Queries) SupportOptionsAlertGroups(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsAlertGroupsRow, error) { + rows, err := q.db.Query(ctx, supportOptionsAlertGroups, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportOptionsAlertGroupsRow{} + for rows.Next() { + var i SupportOptionsAlertGroupsRow + if err := rows.Scan(&i.ID, &i.Name); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportOptionsChannels = `-- name: SupportOptionsChannels :many +SELECT id, name, type FROM notification_channels WHERE org_id = $1 ORDER BY lower(name) LIMIT 500 +` + +type SupportOptionsChannelsRow struct { + ID uuid.UUID + Name string + Type string +} + +func (q *Queries) SupportOptionsChannels(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsChannelsRow, error) { + rows, err := q.db.Query(ctx, supportOptionsChannels, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportOptionsChannelsRow{} + for rows.Next() { + var i SupportOptionsChannelsRow + if err := rows.Scan(&i.ID, &i.Name, &i.Type); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportOptionsIncidents = `-- name: SupportOptionsIncidents :many +SELECT i.id, i.title, i.started_at, m.name AS monitor_name +FROM incidents i JOIN monitors m ON m.id = i.monitor_id +WHERE i.org_id = $1 ORDER BY i.started_at DESC LIMIT 50 +` + +type SupportOptionsIncidentsRow struct { + ID uuid.UUID + Title string + StartedAt time.Time + MonitorName string +} + +func (q *Queries) SupportOptionsIncidents(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsIncidentsRow, error) { + rows, err := q.db.Query(ctx, supportOptionsIncidents, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportOptionsIncidentsRow{} + for rows.Next() { + var i SupportOptionsIncidentsRow + if err := rows.Scan( + &i.ID, + &i.Title, + &i.StartedAt, + &i.MonitorName, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportOptionsMonitors = `-- name: SupportOptionsMonitors :many +SELECT id, name FROM monitors WHERE org_id = $1 ORDER BY lower(name) LIMIT 500 +` + +type SupportOptionsMonitorsRow struct { + ID uuid.UUID + Name string +} + +func (q *Queries) SupportOptionsMonitors(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsMonitorsRow, error) { + rows, err := q.db.Query(ctx, supportOptionsMonitors, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportOptionsMonitorsRow{} + for rows.Next() { + var i SupportOptionsMonitorsRow + if err := rows.Scan(&i.ID, &i.Name); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportOptionsStatusPages = `-- name: SupportOptionsStatusPages :many +SELECT id, title FROM status_pages WHERE org_id = $1 ORDER BY lower(title) LIMIT 500 +` + +type SupportOptionsStatusPagesRow struct { + ID uuid.UUID + Title string +} + +func (q *Queries) SupportOptionsStatusPages(ctx context.Context, orgID uuid.UUID) ([]SupportOptionsStatusPagesRow, error) { + rows, err := q.db.Query(ctx, supportOptionsStatusPages, orgID) + if err != nil { + return nil, err + } + defer rows.Close() + items := []SupportOptionsStatusPagesRow{} + for rows.Next() { + var i SupportOptionsStatusPagesRow + if err := rows.Scan(&i.ID, &i.Title); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const supportReferencesExist = `-- name: SupportReferencesExist :one +SELECT ($1::uuid IS NULL OR EXISTS (SELECT 1 FROM monitors m WHERE m.id = $1 AND m.org_id = $2::uuid)) + AND ($3::uuid IS NULL OR EXISTS (SELECT 1 FROM notification_channels c WHERE c.id = $3 AND c.org_id = $2::uuid)) + AND ($4::uuid IS NULL OR EXISTS (SELECT 1 FROM alert_groups g WHERE g.id = $4 AND g.org_id = $2::uuid)) + AND ($5::uuid IS NULL OR EXISTS (SELECT 1 FROM status_pages p WHERE p.id = $5 AND p.org_id = $2::uuid)) + AND ($6::uuid IS NULL OR EXISTS (SELECT 1 FROM incidents i WHERE i.id = $6 AND i.org_id = $2::uuid)) + AS ok +` + +type SupportReferencesExistParams struct { + MonitorID *uuid.UUID + OrgID uuid.UUID + ChannelID *uuid.UUID + AlertGroupID *uuid.UUID + StatusPageID *uuid.UUID + IncidentID *uuid.UUID +} + +// Whether everything a new ticket points at belongs to org; run in the +// organization's scope so only what the account may see counts. +func (q *Queries) SupportReferencesExist(ctx context.Context, arg SupportReferencesExistParams) (*bool, error) { + row := q.db.QueryRow(ctx, supportReferencesExist, + arg.MonitorID, + arg.OrgID, + arg.ChannelID, + arg.AlertGroupID, + arg.StatusPageID, + arg.IncidentID, + ) + var ok *bool + err := row.Scan(&ok) + return ok, err +} + +const supportTicketReferences = `-- name: SupportTicketReferences :one +SELECT o.name AS org_name, o.slug AS org_slug, + m.name AS monitor_name, m.type AS monitor_type, + ch.name AS channel_name, ch.type AS channel_type, + ag.name AS alert_group_name, + sp.title AS status_page_title, sp.slug AS status_page_slug, + i.title AS incident_title, i.started_at AS incident_started_at, im.name AS incident_monitor +FROM support_tickets t +LEFT JOIN orgs o ON o.id = t.org_id +LEFT JOIN monitors m ON m.id = t.monitor_id +LEFT JOIN notification_channels ch ON ch.id = t.channel_id +LEFT JOIN alert_groups ag ON ag.id = t.alert_group_id +LEFT JOIN status_pages sp ON sp.id = t.status_page_id +LEFT JOIN incidents i ON i.id = t.incident_id +LEFT JOIN monitors im ON im.id = i.monitor_id +WHERE t.id = $1 +` + +type SupportTicketReferencesRow struct { + OrgName *string + OrgSlug *string + MonitorName *string + MonitorType *string + ChannelName *string + ChannelType *string + AlertGroupName *string + StatusPageTitle *string + StatusPageSlug *string + IncidentTitle *string + IncidentStartedAt *time.Time + IncidentMonitor *string +} + +// The names of what a ticket points at, for showing it. +func (q *Queries) SupportTicketReferences(ctx context.Context, id uuid.UUID) (SupportTicketReferencesRow, error) { + row := q.db.QueryRow(ctx, supportTicketReferences, id) + var i SupportTicketReferencesRow + err := row.Scan( + &i.OrgName, + &i.OrgSlug, + &i.MonitorName, + &i.MonitorType, + &i.ChannelName, + &i.ChannelType, + &i.AlertGroupName, + &i.StatusPageTitle, + &i.StatusPageSlug, + &i.IncidentTitle, + &i.IncidentStartedAt, + &i.IncidentMonitor, + ) + return i, err +} + +const supportTicketStatus = `-- name: SupportTicketStatus :one +SELECT status FROM support_tickets WHERE id = $1 +` + +func (q *Queries) SupportTicketStatus(ctx context.Context, id uuid.UUID) (string, error) { + row := q.db.QueryRow(ctx, supportTicketStatus, id) + var status string + err := row.Scan(&status) + return status, err +} diff --git a/internal/web/auth.templ b/internal/web/auth.templ index f85515b..d67f1a6 100644 --- a/internal/web/auth.templ +++ b/internal/web/auth.templ @@ -222,7 +222,12 @@ templ ConsentPage(p Page, me Me, docs []LegalLink, versions, next string) { @submit(i18n.T(ctx, "consent.submit")) -

+

+ if me.Support { + { i18n.T(ctx, "support.contact") } + } + +

{ i18n.T(ctx, "consent.decline") }

@accountDataBody(me) @@ -246,7 +251,12 @@ templ SuspendedPage(p Page, me Me, reason string) {

{ reason }

}

{ i18n.T(ctx, "suspended.options") }

-

+

+ if me.Support { + { i18n.T(ctx, "support.contact") } + } + +

@accountDataBody(me) } diff --git a/internal/web/auth_templ.go b/internal/web/auth_templ.go index fda5bf6..07bad25 100644 --- a/internal/web/auth_templ.go +++ b/internal/web/auth_templ.go @@ -1292,33 +1292,56 @@ func ConsentPage(p Page, me Me, docs []LegalLink, versions, next string) templ.C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "

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

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var66 string + templ_7745c5c3_Var66, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "consent.decline")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 232, Col: 71} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var66)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1326,7 +1349,7 @@ func ConsentPage(p Page, me Me, docs []LegalLink, versions, next string) templ.C if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 88, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1359,7 +1382,7 @@ func SuspendedPage(p Page, me Me, reason string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var67 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var68 := 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 { @@ -1371,7 +1394,7 @@ func SuspendedPage(p Page, me Me, reason string) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 89, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 92, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1383,82 +1406,105 @@ func SuspendedPage(p Page, me Me, reason string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var68 string - templ_7745c5c3_Var68, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 243, Col: 66} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var68)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var69 string - templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "suspended.intro")) + templ_7745c5c3_Var69, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, p.TitleID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 244, Col: 59} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 248, Col: 66} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var69)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 92, "

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

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var70 string + templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "suspended.intro")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 249, Col: 59} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "

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

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var70 string - templ_7745c5c3_Var70, templ_7745c5c3_Err = templ.JoinStringErrs(reason) + var templ_7745c5c3_Var71 string + templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(reason) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 246, Col: 64} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 251, Col: 64} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var70)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 94, "

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

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

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var71 string - templ_7745c5c3_Var71, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "suspended.options")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 248, Col: 72} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var71)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, "

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

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if me.Support { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 100, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var73 string + templ_7745c5c3_Var73, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.contact")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/auth.templ`, Line: 256, Col: 93} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var73)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 101, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 102, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1466,13 +1512,13 @@ func SuspendedPage(p Page, me Me, reason string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 98, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 104, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) - templ_7745c5c3_Err = Layout(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var67), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = Layout(p).Render(templ.WithChildren(ctx, templ_7745c5c3_Var68), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/console.templ b/internal/web/console.templ index 64d9fcc..eebfd4b 100644 --- a/internal/web/console.templ +++ b/internal/web/console.templ @@ -30,6 +30,8 @@ type Me struct { // DeletesOrgs names the organizations the account is the last owner // of; deleting it deletes them, with all their monitors. DeletesOrgs []string + // Support is set while accounts can open support tickets. + Support bool } // Org is one entry of the organization switcher. @@ -79,6 +81,9 @@ templ consoleShell(p Page, me Me) { }
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.OrgSuspended { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var17 string - templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.org_suspended")) + var templ_7745c5c3_Var18 string + templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "console.org_suspended")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 95, Col: 51} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 100, Col: 51} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, " ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.SuspendedReason != "" { - var templ_7745c5c3_Var18 string - templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(" " + i18n.T(ctx, "console.suspended_reason", "Reason", me.SuspendedReason)) + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(" " + i18n.T(ctx, "console.suspended_reason", "Reason", me.SuspendedReason)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 97, Col: 83} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 102, Col: 83} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18)) + _, 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, 32, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - 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 } @@ -392,7 +417,7 @@ func consoleShell(p Page, me Me) templ.Component { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -404,7 +429,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, 35, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -453,7 +478,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var20 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var21 := 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 { @@ -465,51 +490,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var21 string - templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.title")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 135, Col: 72} - } - _, 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, 37, "

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

") 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.totp.heading")) + templ_7745c5c3_Var22, 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: 137, Col: 114} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 140, Col: 72} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "

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

") + 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.totp.heading")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 142, Col: 114} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if me.TOTP { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "

● ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "

● ") 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.totp.active")) + var templ_7745c5c3_Var24 string + templ_7745c5c3_Var24, 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: 139, Col: 98} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 144, Col: 98} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) + _, 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, 40, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -517,25 +542,25 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud 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, 41, "

= 3)} - templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_ElementWriter, templ_7745c5c3_Var24...) + var templ_7745c5c3_Var25 = []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_Var25...) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var25 string - templ_7745c5c3_Var25, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var24).String()).Resolve(ctx) + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.CSSClasses(templ_7745c5c3_Var25).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_Var25) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var26) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\"") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "\"") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -549,33 +574,33 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } templ.ReleaseBuffer(templ_7745c5c3_Buffer) } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, ">") - 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.recovery.left", "Count", me.RecoveryCodesLeft)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 141, Col: 75} - } - _, 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, 44, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, ">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var27 string - templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) + templ_7745c5c3_Var27, 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: 144, Col: 116} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 146, Col: 75} } _, 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, 45, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var28 string + templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.recovery.regenerate")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 149, Col: 116} + } + _, 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, 48, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -599,20 +624,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "
") 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.disable")) + var templ_7745c5c3_Var29 string + templ_7745c5c3_Var29, 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: 154, Col: 109} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 159, Col: 109} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -632,51 +657,51 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, "

● ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var29 string - templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.totp.inactive")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 163, Col: 105} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 50, "

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

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var32 string - templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.heading")) + var templ_7745c5c3_Var33 string + templ_7745c5c3_Var33, 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: 180, Col: 113} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 185, Col: 113} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) + _, 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, 55, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(identities) == 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var33 string - templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.sso.none")) + var templ_7745c5c3_Var34 string + templ_7745c5c3_Var34, 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: 182, Col: 73} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 187, Col: 73} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 57, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } else { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } if canLink { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "
") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - if len(platform.Linked)+len(platform.Available) > 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "\" 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_Var38 string - templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.platform_sso.heading")) + templ_7745c5c3_Var38, 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: 196, Col: 123} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 196, Col: 190} } _, 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, 68, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(platform.Linked)+len(platform.Available) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var39 string + templ_7745c5c3_Var39, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.platform_sso.heading")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 201, Col: 123} + } + _, 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, 71, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } if len(platform.Linked) > 0 { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 84, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 82, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -962,20 +987,20 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 83, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var46 string - templ_7745c5c3_Var46, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.activity_intro")) + var templ_7745c5c3_Var47 string + templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "security.activity_intro")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 224, Col: 88} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 229, Col: 88} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var46)) + _, 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, 84, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -983,7 +1008,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 85, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 88, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -993,7 +1018,7 @@ func Security(p Page, me Me, identities []Identity, canLink bool, activity []Aud } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var20), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var21), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1020,33 +1045,33 @@ func recoveryOutput() templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 86, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1071,46 +1096,46 @@ func policyBanner(msgID, actionID, href string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 89, "

") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var51 string - templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, msgID)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 244, Col: 23} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 90, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var52 string - templ_7745c5c3_Var52, templ_7745c5c3_Err = templruntime.NewAttributeExpression(templ.SafeURL(href)).ResolveURL(ctx) + templ_7745c5c3_Var52, 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: 245, Col: 32} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 249, Col: 23} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var52) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var52)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 91, "\" class=\"underline underline-offset-2\">") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 93, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 94, "\" class=\"underline underline-offset-2\">") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var54 string + templ_7745c5c3_Var54, 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: 250, Col: 95} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var54)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 95, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1135,46 +1160,46 @@ func settingsLink(href, titleID, hintID string) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 93, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, " ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 97, "\" class=\"block border border-rule p-4 hover:border-ink\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } var templ_7745c5c3_Var57 string - templ_7745c5c3_Var57, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, hintID)) + templ_7745c5c3_Var57, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, titleID)) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 253, Col: 67} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 257, Col: 56} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var57)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 96, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 98, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var58 string + templ_7745c5c3_Var58, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, hintID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/console.templ`, Line: 258, Col: 67} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var58)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 99, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1200,7 +1225,7 @@ func SettingsIndex(p Page, me Me) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var59 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var60 := 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 { @@ -1216,7 +1241,7 @@ func SettingsIndex(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 97, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 100, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1288,13 +1313,13 @@ func SettingsIndex(p Page, me Me) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 98, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 101, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var59), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var60), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/regions.templ b/internal/web/regions.templ index 5c9d3ba..696554c 100644 --- a/internal/web/regions.templ +++ b/internal/web/regions.templ @@ -403,6 +403,7 @@ templ adminLinks() { { i18n.T(ctx, "orgs.title") } { i18n.T(ctx, "audit.platform_title") } { i18n.T(ctx, "legal.platform_title") } + { i18n.T(ctx, "support.admin_title") }

} diff --git a/internal/web/regions_templ.go b/internal/web/regions_templ.go index 910349f..af915b3 100644 --- a/internal/web/regions_templ.go +++ b/internal/web/regions_templ.go @@ -1896,7 +1896,20 @@ func adminLinks() templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var97 string + templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.admin_title")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 406, Col: 100} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var97)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 150, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1921,7 +1934,7 @@ func AdminStatusPagesPage(p Page, me Me, v ModerationView) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var98 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var99 := 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 { @@ -1933,20 +1946,20 @@ func AdminStatusPagesPage(p Page, me Me, v ModerationView) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 150, "

← ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "

← ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var99 string - templ_7745c5c3_Var99, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.title")) + var templ_7745c5c3_Var100 string + templ_7745c5c3_Var100, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 411, Col: 109} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 412, Col: 109} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var99)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var100)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1956,7 +1969,7 @@ func AdminStatusPagesPage(p Page, me Me, v ModerationView) templ.Component { } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var98), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var99), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -1981,7 +1994,7 @@ func AdminOrgsPage(p Page, me Me, v OrgsView) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Var101 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_Var102 := 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 { @@ -1993,20 +2006,20 @@ func AdminOrgsPage(p Page, me Me, v OrgsView) templ.Component { }() } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 152, "

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

← ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var102 string - templ_7745c5c3_Var102, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.title")) + var templ_7745c5c3_Var103 string + templ_7745c5c3_Var103, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "admin.title")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 418, Col: 109} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/regions.templ`, Line: 419, Col: 109} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var102)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var103)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 153, "

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

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2016,7 +2029,7 @@ func AdminOrgsPage(p Page, me Me, v OrgsView) templ.Component { } return nil }) - templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var101), templ_7745c5c3_Buffer) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var102), templ_7745c5c3_Buffer) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -2043,173 +2056,173 @@ func agentInstall(in InstallView) templ.Component { } ctx = templ.InitializeContext(ctx) ctx = templ.ClearChildren(ctx) - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 154, "

") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 169, "

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/internal/web/support.templ b/internal/web/support.templ new file mode 100644 index 0000000..6dacdac --- /dev/null +++ b/internal/web/support.templ @@ -0,0 +1,413 @@ +package web + +import ( + "strconv" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// SupportTicket is a ticket as the support pages show it; User and Org +// are filled for admins. +type SupportTicket struct { + ID, Subject, Status string + User, Org string + Updated string + References []SupportReference + Messages []SupportMessage +} + +// SupportReference is something a ticket points at; Kind is org, monitor, +// channel, alert_group, status_page or incident. +type SupportReference struct { + Kind, Name string +} + +// SupportMessage is one message of a ticket, rendered from Markdown. +type SupportMessage struct { + FromStaff bool + // Author is the admin who answered, for admins only. + Author string + HTML string + At string +} + +// SupportOptions are what of the active organization a new ticket can +// point at; Org is empty without one. +type SupportOptions struct { + Org string + Monitors, Channels, AlertGroups, StatusPages, Incidents []SupportOption +} + +// SupportOption is one choice of SupportOptions. +type SupportOption struct { + ID, Name string +} + +// SupportSettings are how the platform runs support, for its admins. +type SupportSettings struct { + Enabled bool + MaxOpen int +} + +// SupportAccount is what admins see about the account behind a ticket. +type SupportAccount struct { + ID, Email, Name, Created, Locale string + Verified, TOTP, Password, Admin bool + Suspended bool + SuspendedReason string + OrgsOwned, OrgLimit int + OpenTickets int64 + Orgs []SupportOrg +} + +// SupportOrg is an organization of the account with its limits; Current +// marks the one the ticket names. Limits of 0 are unlimited. +type SupportOrg struct { + Name, Slug string + Owner, Current, Suspended bool + SuspendedReason string + Monitors, MonitorLimit int + StatusPages, StatusPageLimit int + RegionsPerMonitor int +} + +// SupportStatuses are the states of a ticket, in the order admins filter +// them. +var SupportStatuses = []string{"open", "answered", "closed"} + +var supportFilters = append(append([]string{}, SupportStatuses...), "all") + +// supportBase is where the support pages live for staff or the account. +func supportBase(staff bool) string { + if staff { + return "/admin/support" + } + return "/support" +} + +func supportAPI(t SupportTicket, staff bool) string { + return supportBase(staff) + "/tickets/" + t.ID +} + +// usageText shows used of limit, ∞ for no limit. +func usageText(used, limit int) string { + if limit <= 0 { + return strconv.Itoa(used) + " / ∞" + } + return strconv.Itoa(used) + " / " + strconv.Itoa(limit) +} + +templ supportStatusLabel(status string) { + { i18n.T(ctx, "support.status."+status) } +} + +templ supportList(tickets []SupportTicket, base string, staff bool) { + +} + +templ supportSelect(labelID, name string, opts []SupportOption) { + if len(opts) > 0 { + + } +} + +templ SupportPage(p Page, me Me, tickets []SupportTicket, opts SupportOptions) { + @consoleShell(p, me) { + @settingsHeading("support.title", "support.intro") +
+
+ @sectionHeading("support.mine") + if len(tickets) == 0 { +

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

+ } else { + @supportList(tickets, "/support/", false) + } +
+ +
+ } +} + +templ SupportDisabledPage(p Page, me Me) { + @consoleShell(p, me) { + @settingsHeading("support.title", "") +

{ i18n.T(ctx, "support.disabled") }

+ } +} + +templ supportReferences(refs []SupportReference) { + if len(refs) > 0 { +
+ for _, r := range refs { +
{ i18n.T(ctx, "support.ref."+r.Kind) }
+
{ r.Name }
+ } +
+ } +} + +templ supportFlag(on bool, yesID, noID string) { + if on { + { i18n.T(ctx, yesID) } + } else { + { i18n.T(ctx, noID) } + } +} + +// supportAccountBox gives admins the account behind a ticket at a glance. +templ supportAccountBox(a SupportAccount) { + +} + +// SupportTicketPage shows a ticket's conversation to its account or, with +// the account's details, to the admins. +templ SupportTicketPage(p Page, me Me, t SupportTicket, account *SupportAccount) { + @consoleShell(p, me) { +

{ "← " + i18n.T(ctx, "support.all") }

+

{ t.Subject }

+
+ @supportStatusLabel(t.Status) + if account != nil { + { t.User } + } +
+
+
+ @supportReferences(t.References) +
    + for _, m := range t.Messages { +
  1. +

    + + switch { + case m.FromStaff && m.Author != "": + { i18n.T(ctx, "support.from_staff") + " · " + m.Author } + case m.FromStaff: + { i18n.T(ctx, "support.from_staff") } + case account != nil: + { t.User } + default: + { i18n.T(ctx, "support.from_you") } + } + + { m.At } +

    + +
  2. + } +
+
+ @sectionHeading("support.reply") + if t.Status == "closed" && account == nil { +

{ i18n.T(ctx, "support.closed_hint") }

+ } +
+ @formError() +
+ @MarkdownEditor("message", "", 6, 10000, MarkdownInline) +
+ @submit(i18n.T(ctx, "support.send")) +
+
+ @formError() + if t.Status == "closed" { + + + } else { + + + } +
+
+
+ if account != nil { + @supportAccountBox(*account) + } +
+ } +} + +templ AdminSupportPage(p Page, me Me, tickets []SupportTicket, filter string, settings SupportSettings) { + @consoleShell(p, me) { + @settingsHeading("support.admin_title", "support.admin_intro") + @adminLinks() +
+ + { i18n.T(ctx, "support.settings") } + if settings.Enabled { + { i18n.T(ctx, "support.settings.on") } + } else { + { i18n.T(ctx, "support.settings.off") } + } + +
+ @formError() + @checkbox(i18n.T(ctx, "support.settings.enabled"), "enabled", settings.Enabled) +

{ i18n.T(ctx, "support.settings.enabled_hint") }

+ + @submit(i18n.T(ctx, "support.settings.save")) +
+
+ + if len(tickets) == 0 { +

{ i18n.T(ctx, "support.none_admin") }

+ } else { + @supportList(tickets, "/admin/support/", true) + } + } +} diff --git a/internal/web/support_templ.go b/internal/web/support_templ.go new file mode 100644 index 0000000..d66a416 --- /dev/null +++ b/internal/web/support_templ.go @@ -0,0 +1,2129 @@ +// Code generated by templ - DO NOT EDIT. + +// templ: version: v0.3.1118 + +package web + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import templruntime "github.com/a-h/templ/runtime" + +import ( + "strconv" + + "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n" +) + +// SupportTicket is a ticket as the support pages show it; User and Org +// are filled for admins. +type SupportTicket struct { + ID, Subject, Status string + User, Org string + Updated string + References []SupportReference + Messages []SupportMessage +} + +// SupportReference is something a ticket points at; Kind is org, monitor, +// channel, alert_group, status_page or incident. +type SupportReference struct { + Kind, Name string +} + +// SupportMessage is one message of a ticket, rendered from Markdown. +type SupportMessage struct { + FromStaff bool + // Author is the admin who answered, for admins only. + Author string + HTML string + At string +} + +// SupportOptions are what of the active organization a new ticket can +// point at; Org is empty without one. +type SupportOptions struct { + Org string + Monitors, Channels, AlertGroups, StatusPages, Incidents []SupportOption +} + +// SupportOption is one choice of SupportOptions. +type SupportOption struct { + ID, Name string +} + +// SupportSettings are how the platform runs support, for its admins. +type SupportSettings struct { + Enabled bool + MaxOpen int +} + +// SupportAccount is what admins see about the account behind a ticket. +type SupportAccount struct { + ID, Email, Name, Created, Locale string + Verified, TOTP, Password, Admin bool + Suspended bool + SuspendedReason string + OrgsOwned, OrgLimit int + OpenTickets int64 + Orgs []SupportOrg +} + +// SupportOrg is an organization of the account with its limits; Current +// marks the one the ticket names. Limits of 0 are unlimited. +type SupportOrg struct { + Name, Slug string + Owner, Current, Suspended bool + SuspendedReason string + Monitors, MonitorLimit int + StatusPages, StatusPageLimit int + RegionsPerMonitor int +} + +// SupportStatuses are the states of a ticket, in the order admins filter +// them. +var SupportStatuses = []string{"open", "answered", "closed"} + +var supportFilters = append(append([]string{}, SupportStatuses...), "all") + +// supportBase is where the support pages live for staff or the account. +func supportBase(staff bool) string { + if staff { + return "/admin/support" + } + return "/support" +} + +func supportAPI(t SupportTicket, staff bool) string { + return supportBase(staff) + "/tickets/" + t.ID +} + +// usageText shows used of limit, ∞ for no limit. +func usageText(used, limit int) string { + if limit <= 0 { + return strconv.Itoa(used) + " / ∞" + } + return strconv.Itoa(used) + " / " + strconv.Itoa(limit) +} + +func supportStatusLabel(status 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_ElementWriter := templ_7745c5c3_Buffer + templ_7745c5c3_Buffer := templ.GetBuffer() + var templ_7745c5c3_ElementScripts []templ.ComponentScript + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "") + 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, "support.status."+status)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 106, Col: 41} + } + _, 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, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func supportList(tickets []SupportTicket, base string, staff bool) templ.Component { + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { + return templ_7745c5c3_CtxErr + } + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + ctx = templ.ClearChildren(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func supportSelect(labelID, name string, opts []SupportOption) 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) + if len(opts) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func SupportPage(p Page, me Me, tickets []SupportTicket, opts SupportOptions) 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_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 { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("support.title", "support.intro").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("support.mine").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(tickets) == 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var19 string + templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.none")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 152, Col: 103} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = supportList(tickets, "/support/", false).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + 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 + } + return nil + }) +} + +func SupportDisabledPage(p Page, me Me) 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_Var25 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("support.title", "").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var26 string + templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.disabled")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 191, Col: 104} + } + _, 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, 39, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var25), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func supportReferences(refs []SupportReference) 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) + if len(refs) > 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, r := range refs { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "
") + 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, "support.ref."+r.Kind)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 199, Col: 63} + } + _, 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, 42, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var29 string + templ_7745c5c3_Var29, templ_7745c5c3_Err = templ.JoinStringErrs(r.Name) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 200, Col: 44} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var29)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +func supportFlag(on bool, yesID, noID 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) + if on { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var31 string + templ_7745c5c3_Var31, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, yesID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 208, Col: 44} + } + _, 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, 46, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var32 string + templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, noID)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 210, Col: 46} + } + _, 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, 48, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) +} + +// supportAccountBox gives admins the account behind a ticket at a glance. +func supportAccountBox(a SupportAccount) 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, 49, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +// SupportTicketPage shows a ticket's conversation to its account or, with +// the account's details, to the admins. +func SupportTicketPage(p Page, me Me, t SupportTicket, account *SupportAccount) 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_Var72 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 107, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var74 string + templ_7745c5c3_Var74, templ_7745c5c3_Err = templ.JoinStringErrs("← " + i18n.T(ctx, "support.all")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 307, Col: 152} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var74)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 109, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var75 string + templ_7745c5c3_Var75, templ_7745c5c3_Err = templ.JoinStringErrs(t.Subject) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 308, Col: 64} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var75)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 110, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = supportStatusLabel(t.Status).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if account != nil { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 111, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var76 string + templ_7745c5c3_Var76, templ_7745c5c3_Err = templ.JoinStringErrs(t.User) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 312, Col: 18} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var76)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 112, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 113, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + { + 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, 114, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = supportReferences(t.References).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 117, "
    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, m := range t.Messages { + { + 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, 118, "
  1. ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + switch { + case m.FromStaff && m.Author != "": + var templ_7745c5c3_Var81 string + templ_7745c5c3_Var81, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.from_staff") + " · " + m.Author) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 325, Col: 66} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var81)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + case m.FromStaff: + var templ_7745c5c3_Var82 string + templ_7745c5c3_Var82, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.from_staff")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 327, Col: 46} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var82)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + case account != nil: + var templ_7745c5c3_Var83 string + templ_7745c5c3_Var83, templ_7745c5c3_Err = templ.JoinStringErrs(t.User) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 329, Col: 19} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var83)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + default: + var templ_7745c5c3_Var84 string + templ_7745c5c3_Var84, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.from_you")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 331, Col: 44} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var84)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 121, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var85 string + templ_7745c5c3_Var85, templ_7745c5c3_Err = templ.JoinStringErrs(m.At) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 334, Col: 49} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var85)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 122, "

    ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templ.Raw(m.HTML).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 123, "
  2. ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 124, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = sectionHeading("support.reply").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if t.Status == "closed" && account == nil { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 125, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var86 string + templ_7745c5c3_Var86, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.closed_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 345, Col: 77} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var86)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 126, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 127, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 130, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = MarkdownEditor("message", "", 6, 10000, MarkdownInline).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 131, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "support.send")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 132, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if t.Status == "closed" { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 135, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 137, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 139, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if account != nil { + templ_7745c5c3_Err = supportAccountBox(*account).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 140, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var72), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +func AdminSupportPage(p Page, me Me, tickets []SupportTicket, filter string, settings SupportSettings) 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_Var94 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) + if !templ_7745c5c3_IsBuffer { + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() + } + ctx = templ.InitializeContext(ctx) + templ_7745c5c3_Err = settingsHeading("support.admin_title", "support.admin_intro").Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = adminLinks().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 141, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var95 string + templ_7745c5c3_Var95, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.settings")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 379, Col: 37} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var95)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 144, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if settings.Enabled { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 145, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var96 string + templ_7745c5c3_Var96, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.settings.on")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 381, Col: 68} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var96)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 146, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 147, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var97 string + templ_7745c5c3_Var97, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.settings.off")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 383, Col: 71} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var97)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 148, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 149, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = formError().Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = checkbox(i18n.T(ctx, "support.settings.enabled"), "enabled", settings.Enabled).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 150, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var98 string + templ_7745c5c3_Var98, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.settings.enabled_hint")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 389, Col: 96} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var98)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 151, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = submit(i18n.T(ctx, "support.settings.save")).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 155, "
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if len(tickets) == 0 { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 163, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var106 string + templ_7745c5c3_Var106, templ_7745c5c3_Err = templ.JoinStringErrs(i18n.T(ctx, "support.none_admin")) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/web/support.templ`, Line: 408, Col: 107} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var106)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 164, "

") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } else { + templ_7745c5c3_Err = supportList(tickets, "/admin/support/", true).Render(ctx, templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + return nil + }) + templ_7745c5c3_Err = consoleShell(p, me).Render(templ.WithChildren(ctx, templ_7745c5c3_Var94), templ_7745c5c3_Buffer) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + return nil + }) +} + +var _ = templruntime.GeneratedTemplate