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:
2026-11-25 09:31:33 -07:00
co-authored by Claude Opus 5.5
parent bb4772637c
commit c8964cec12
23 changed files with 601 additions and 11 deletions
+9 -2
View File
@@ -50,6 +50,7 @@ type Message struct {
RepliedAt time.Time
Reply string
Error string
CreatedBy int64 // who drafted it; 0: unknown, or the local edition
// Filled in when listing.
Contact prospects.Contact
@@ -86,7 +87,7 @@ func nullID(id int64) any {
}
const columns = `o.id, o.contact_id, coalesce(o.signal_id, 0), o.channel, o.status, o.subject, o.body, o.to_addr,
o.message_id, o.created_at, o.queued_at, o.sent_at, o.replied_at, o.reply, o.error,
o.message_id, o.created_at, o.queued_at, o.sent_at, o.replied_at, o.reply, o.error, o.created_by,
p.first_name, p.last_name, p.title, p.email, p.email_status, p.linkedin, coalesce(p.company_id, 0),
coalesce(c.name, '')`
@@ -101,7 +102,7 @@ func scan(rows *sql.Rows) ([]Message, error) {
var created string
var queued, sent, replied sql.NullString
if err := rows.Scan(&m.ID, &m.ContactID, &m.SignalID, &m.Channel, &m.Status, &m.Subject, &m.Body, &m.To,
&m.MessageID, &created, &queued, &sent, &replied, &m.Reply, &m.Error,
&m.MessageID, &created, &queued, &sent, &replied, &m.Reply, &m.Error, &m.CreatedBy,
&m.Contact.FirstName, &m.Contact.LastName, &m.Contact.Title, &m.Contact.Email, &m.Contact.EmailStatus,
&m.Contact.LinkedIn, &m.Contact.CompanyID, &m.Company); err != nil {
return nil, err
@@ -405,3 +406,9 @@ func lastSent(d *db.DB) (time.Time, error) {
err := d.QueryRow(`SELECT max(sent_at) FROM outreach WHERE channel = 'email'`).Scan(&s)
return parseTime(s), err
}
// SetCreatedBy records who drafted a message.
func SetCreatedBy(d *db.DB, id, user int64) error {
_, err := d.Exec(`UPDATE outreach SET created_by = ? WHERE id = ?`, user, id)
return err
}