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:
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"supermarket/internal/appmail"
|
||||
"supermarket/internal/audit"
|
||||
"supermarket/internal/profile"
|
||||
"supermarket/internal/users"
|
||||
)
|
||||
@@ -117,6 +118,26 @@ func TestAccessEnforced(t *testing.T) {
|
||||
if rec := as(h, sc, http.MethodPost, "/seo/next/dismiss", url.Values{"page": {"/x"}}); rec.Code == http.StatusForbidden {
|
||||
t.Errorf("member POST in SEO: %d", rec.Code)
|
||||
}
|
||||
|
||||
// The log shows each step, to admins only.
|
||||
entries, _ := audit.List(s.DB, audit.Filter{}, 100)
|
||||
var steps []string
|
||||
for i := len(entries) - 1; i >= 0; i-- {
|
||||
e := entries[i]
|
||||
steps = append(steps, e.UserName+" "+e.Action+" "+e.Target)
|
||||
}
|
||||
got := strings.Join(steps, "\n")
|
||||
for _, want := range []string{"owner invited ada@example.com", "owner invited sam@example.com", "X joined ada@example.com", "X joined sam@example.com", "X signin"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("the log lacks %q:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
if rec := as(h, sc, http.MethodGet, "/settings/activity", nil); rec.Code != http.StatusForbidden {
|
||||
t.Errorf("member reads the log: %d", rec.Code)
|
||||
}
|
||||
if body := as(h, oc, http.MethodGet, "/settings/activity", nil).Body.String(); !strings.Contains(body, "invited <strong>sam@example.com</strong>") {
|
||||
t.Errorf("activity page: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewOnlyMember(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user