ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 10m49s
ci / test (pull_request) Successful in 14m39s
ci / build (pull_request) Canceled after 14m22s
ci / image (pull_request) Canceled after 0s
The monitor list gets a sort switcher: the organization's own order, by default, or by name, status (problems first), uptime (worst first) or latency (slowest first). The choice is remembered in a cookie; paging follows it. "Arrange monitors" shows the whole tree with each group's monitors to drag, or move with up and down, into the order wanted; every change is saved at once through PUT /api/v1/org/monitors/order, which needs write access to every monitor given and is audited. Monitors without a position follow the positioned ones, by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5"
|
|
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/authz"
|
|
"git.zb-server.de/ZB-Server/uptimesebi/internal/store"
|
|
)
|
|
|
|
type monitorOrderRequest struct {
|
|
// MonitorIDs in the order wanted; usually the monitors of one group.
|
|
MonitorIDs []uuid.UUID `json:"monitor_ids" binding:"required,min=1,max=1000"`
|
|
}
|
|
|
|
// orderMonitors stores the organization's own order of the monitors given,
|
|
// which the monitor list follows when sorted by its own order. It needs
|
|
// write access to every one of them.
|
|
func (s *Server) orderMonitors(c *gin.Context) {
|
|
var req monitorOrderRequest
|
|
if !bind(c, &req) {
|
|
return
|
|
}
|
|
p := current(c)
|
|
ctx := c.Request.Context()
|
|
t, err := s.loadGroupTree(ctx, p.scope())
|
|
if err != nil {
|
|
internalError(c, err)
|
|
return
|
|
}
|
|
errDenied := errors.New("denied")
|
|
seen := map[uuid.UUID]bool{}
|
|
err = s.db.Tx(ctx, p.scope(), func(q *store.Queries) error {
|
|
for i, id := range req.MonitorIDs {
|
|
if seen[id] {
|
|
return pgx.ErrNoRows
|
|
}
|
|
seen[id] = true
|
|
m, err := q.GetMonitor(ctx, id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !canInGroup(p, authz.MonitorsWrite, t, m.GroupID) {
|
|
return errDenied
|
|
}
|
|
if _, err := q.SetMonitorPosition(ctx, store.SetMonitorPositionParams{ID: id, Position: new(int32(i))}); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
switch {
|
|
case errors.Is(err, errDenied):
|
|
fail(c, http.StatusForbidden, "forbidden")
|
|
case errors.Is(err, pgx.ErrNoRows):
|
|
fail(c, http.StatusUnprocessableEntity, "invalid_monitor")
|
|
case err != nil:
|
|
internalError(c, err)
|
|
default:
|
|
c.Status(http.StatusNoContent)
|
|
}
|
|
}
|