Phase 10, part 8: the audit log, and who made what
Sign-ins and failed ones, everything admins do to users, connections, posting accounts, each post published and email sent, pull requests and deletions go in an audit log (schema 36), kept two years; admins read it under Settings → Activity. Drafts, published posts and outreach emails show who made them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,16 @@ var services = []service{
|
||||
{"listmonk", "Listmonk", "Mailing lists", "/settings/email", []string{secrets.ListmonkToken}},
|
||||
}
|
||||
|
||||
// serviceName is a service as people say it.
|
||||
func serviceName(id string) string {
|
||||
for _, sv := range services {
|
||||
if sv.ID == id {
|
||||
return sv.Name
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// serviceOf is the service a secret belongs to, by its name's prefix.
|
||||
func serviceOf(secret string) string {
|
||||
prefix, _, _ := strings.Cut(secret, ".")
|
||||
@@ -107,6 +117,7 @@ func (s *Server) setSecrets(r *http.Request, updates map[string]string) error {
|
||||
removed := !set && !s.serviceSet(sv)
|
||||
changes[sv] = connChange{By: who, UserID: id, At: now, Removed: removed}
|
||||
s.Log.Info("connections: changed", "service", sv, "removed", removed, "by", who)
|
||||
s.audit(r, ifElse(removed, "disconnected", "connected"), serviceName(sv), "")
|
||||
}
|
||||
return s.DB.PutJSON(connChangesKey, changes)
|
||||
}
|
||||
@@ -125,6 +136,7 @@ func (s *Server) recordConnection(r *http.Request, service string, set bool) {
|
||||
}
|
||||
}
|
||||
changes[service] = connChange{By: who, UserID: id, At: time.Now().UTC(), Removed: !set}
|
||||
s.audit(r, ifElse(set, "connected", "disconnected"), serviceName(service), "")
|
||||
if err := s.DB.PutJSON(connChangesKey, changes); err != nil {
|
||||
s.Log.Warn("connections: recording a change", "err", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user