ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 7m0s
ci / test (pull_request) Successful in 12m1s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m9s
Accounts open tickets under Support and admins answer them under Admin → Support tickets. - A ticket is open while it waits for the admins and answered while it waits for the account. Either side can close or reopen it, and a reply reopens it. - The admins are mailed about new tickets and replies, and the account about answers. - A ticket can name the active organization and point at a monitor, notification channel, alert group, status page or incident in it. Each must be something the account can read. - Next to the conversation, admins see the account at a glance: state, sign-in, organizations with their limits and usage, and open tickets. - Admins switch support off and limit how many tickets an account has open at once. - Suspended accounts and those yet to accept the terms reach support too; a suspended account opens one ticket. - Tickets are part of the account export and are deleted with the account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
86 lines
2.3 KiB
Go
86 lines
2.3 KiB
Go
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)
|
|
}
|