Skip to main content

zaun_community_protocol/command/object/
audit.rs

1//! Audit-log entries (specification §8.8).
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::ids::{AuditId, MemberId};
7
8/// Every audit action of §8.8, expanded from its `a.b|c` notation.
9///
10/// SPEC: governance §8 names the ban entry `member.banned`; §8.8's `member.ban` is used.
11pub const AUDIT_ACTIONS: &[&str] = &[
12    "channel.create",
13    "channel.update",
14    "channel.delete",
15    "channel.permissions_update",
16    "role.create",
17    "role.update",
18    "role.delete",
19    "role.reorder",
20    "member.roles_update",
21    "member.update",
22    "member.kick",
23    "member.ban",
24    "member.unban",
25    "member.timeout",
26    "message.delete",
27    "invite.create",
28    "invite.revoke",
29    "community.update",
30    "community.descriptor_publish",
31    "membership.approve",
32    "membership.reject",
33    "membership.suspend",
34    "membership.restore",
35    "membership.probation_end",
36    "admission.policy_update",
37    "lockdown.enable",
38    "lockdown.update",
39    "lockdown.disable",
40    "lockdown.expire",
41    "report.review",
42    "report.resolve",
43    "channel.public_distribution",
44    "voice.moderate",
45    "bot.install",
46    "bot.update",
47    "bot.grant",
48    "bot.enable",
49    "bot.disable",
50    "bot.remove",
51    "bot.register",
52    "bot.configure",
53    "bot.crashed",
54];
55
56/// An audit entry (§8.8).
57#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58pub struct AuditEntry {
59    /// Host-assigned id.
60    pub audit_id: AuditId,
61    /// The acting member; `null` (always written) when the host itself acted: a timer's
62    /// `lockdown.expire`, `membership.probation_end` or `membership.restore` (§8.8, as §7.4
63    /// for host-initiated events).
64    pub actor_id: Option<MemberId>,
65    /// One of [`AUDIT_ACTIONS`] (kept as text so newer actions still parse).
66    pub action: String,
67    /// What was acted on.
68    pub target: AuditTarget,
69    /// Time, ms.
70    pub at: u64,
71    /// The moderator's reason.
72    #[serde(default, skip_serializing_if = "Option::is_none")]
73    pub reason: Option<String>,
74    /// Field changes; never message content or report evidence.
75    pub changes: Vec<AuditChange>,
76}
77
78/// `target: {t, c}` of an audit entry.
79///
80/// SPEC: the variants are never listed, so `t` is kept as text and `c` as raw JSON.
81#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82pub struct AuditTarget {
83    /// The kind of target (`channel`, `role`, `member`, …).
84    pub t: String,
85    /// Its id or content.
86    #[serde(default, skip_serializing_if = "Option::is_none")]
87    pub c: Option<Value>,
88}
89
90/// `changes: [{field, old, new}]`. SPEC: value types are never given; raw JSON.
91#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
92pub struct AuditChange {
93    /// The changed field.
94    pub field: String,
95    /// Its old value.
96    pub old: Value,
97    /// Its new value.
98    pub new: Value,
99}