Privacy policy: the forum, and the export and retention it states
Both languages: rows for the forum profile, posts, last visit, private conversations, reports and the moderation log (DSA legal obligation); what is public and what moderators see; forum content never goes to AI; retention periods; the forum theme cookie; the rights (the export covers the forum, posts kept as "Törölt tag" can be deleted on request). In force from 2026-11-26. So that it holds: the account export includes the forum, and the hourly cleanup clears text removed by moderators after a year, closed reports and old ban reasons after a year, the moderation log after two years, and requests never accepted after 90 days. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -8,7 +8,7 @@ use tokio::sync::watch;
|
||||
const INTERVAL: Duration = Duration::from_secs(3600);
|
||||
|
||||
/// (what, statement) pairs; each returns the number of deleted rows.
|
||||
const STATEMENTS: [(&str, &str); 8] = [
|
||||
const STATEMENTS: [(&str, &str); 16] = [
|
||||
("sessions", "DELETE FROM sessions WHERE expires_at < now()"),
|
||||
("auth_tokens", "DELETE FROM auth_tokens WHERE expires_at < now()"),
|
||||
// Sent e-mails contain links with tokens; keep them a week for support.
|
||||
@@ -30,6 +30,36 @@ const STATEMENTS: [(&str, &str); 8] = [
|
||||
// Gifts never paid (Stripe's payment page is long closed by then), with
|
||||
// the recipient's address in them.
|
||||
("gifts", "DELETE FROM gifts WHERE paid_at IS NULL AND created_at < now() - interval '7 days'"),
|
||||
// The forum (the privacy policy's retention periods): what moderators
|
||||
// removed is kept a year for objections, then only its place and reason stay.
|
||||
(
|
||||
"forum_removed_posts",
|
||||
"UPDATE forum.posts SET body = '' WHERE deleted_at < now() - interval '1 year' AND body <> ''",
|
||||
),
|
||||
(
|
||||
"forum_removed_threads",
|
||||
"UPDATE forum.posts p SET body = '' FROM forum.threads th \
|
||||
WHERE th.id = p.thread_id AND th.deleted_at < now() - interval '1 year' AND p.body <> ''",
|
||||
),
|
||||
(
|
||||
"forum_removed_titles",
|
||||
"UPDATE forum.threads SET title = 'Eltávolított szál' \
|
||||
WHERE deleted_at < now() - interval '1 year' AND title <> 'Eltávolított szál'",
|
||||
),
|
||||
("forum_nicknames", "DELETE FROM forum.retired_nicknames WHERE until < now()"),
|
||||
("forum_reports", "DELETE FROM forum.reports WHERE status <> 'open' AND handled_at < now() - interval '1 year'"),
|
||||
("forum_mod_log", "DELETE FROM forum.mod_log WHERE created_at < now() - interval '2 years'"),
|
||||
(
|
||||
"forum_bans",
|
||||
"UPDATE forum.members SET banned_until = NULL, ban_reason = NULL WHERE banned_until < now() - interval '1 year'",
|
||||
),
|
||||
// Requests never accepted (declined or expired), with their introduction;
|
||||
// a block stays as long as the blocker keeps it.
|
||||
(
|
||||
"forum_requests",
|
||||
"DELETE FROM forum.conversations WHERE status IN ('pending', 'declined') AND last_message_at IS NULL \
|
||||
AND coalesce(responded_at, created_at) < now() - interval '90 days'",
|
||||
),
|
||||
];
|
||||
|
||||
pub async fn run_once(db: &PgPool) -> Result<Vec<(&'static str, u64)>, sqlx::Error> {
|
||||
|
||||
@@ -273,6 +273,14 @@ async fn cleanup_removes_only_expired_data(db: PgPool) {
|
||||
("prompt_previews", 0),
|
||||
("generation_errors", 0),
|
||||
("gifts", 1),
|
||||
("forum_removed_posts", 0),
|
||||
("forum_removed_threads", 0),
|
||||
("forum_removed_titles", 0),
|
||||
("forum_nicknames", 0),
|
||||
("forum_reports", 0),
|
||||
("forum_mod_log", 0),
|
||||
("forum_bans", 0),
|
||||
("forum_requests", 0),
|
||||
]
|
||||
);
|
||||
let kept: Vec<Uuid> = sqlx::query_scalar("SELECT id FROM gifts ORDER BY id").fetch_all(&db).await.unwrap();
|
||||
@@ -282,6 +290,60 @@ async fn cleanup_removes_only_expired_data(db: PgPool) {
|
||||
assert_eq!(left, vec![recent, unsent]);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn cleanup_keeps_the_forum_retention_periods(db: PgPool) {
|
||||
let (anna, bea) = (Uuid::now_v7(), Uuid::now_v7());
|
||||
for (id, email) in [(anna, "anna@example.com"), (bea, "bea@example.com")] {
|
||||
sqlx::query("INSERT INTO users (id, email) VALUES ($1, $2)").bind(id).bind(email).execute(&db).await.unwrap();
|
||||
}
|
||||
let thread: i64 = sqlx::query_scalar(
|
||||
"INSERT INTO forum.threads (topic_id, author_id, title) VALUES (2, $1, 'Csend') RETURNING id",
|
||||
)
|
||||
.bind(anna)
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
// Removed 13 months ago, removed last week, never removed.
|
||||
let mut posts = Vec::new();
|
||||
for removed in ["now() - interval '13 months'", "now() - interval '7 days'", "NULL"] {
|
||||
let id: i64 = sqlx::query_scalar(&format!(
|
||||
"INSERT INTO forum.posts (thread_id, author_id, body, deleted_at, delete_reason) VALUES ($1, $2, 'szöveg', {removed}, 'hirdetés') RETURNING id"
|
||||
))
|
||||
.bind(thread)
|
||||
.bind(bea)
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
posts.push(id);
|
||||
}
|
||||
// A request declined long ago goes; an old conversation with messages stays.
|
||||
let (a, b) = if anna < bea { (anna, bea) } else { (bea, anna) };
|
||||
sqlx::query(
|
||||
"INSERT INTO forum.conversations (user_a, user_b, requested_by, intro, status, created_at, responded_at, last_message_at) VALUES ($1, $2, $1, 'Szia', 'declined', now() - interval '100 days', now() - interval '100 days', NULL)",
|
||||
)
|
||||
.bind(a)
|
||||
.bind(b)
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let done = crate::cleanup::run_once(&db).await.unwrap();
|
||||
let count = |what: &str| done.iter().find(|(w, _)| *w == what).unwrap().1;
|
||||
assert_eq!((count("forum_removed_posts"), count("forum_requests")), (1, 1));
|
||||
let bodies: Vec<String> = sqlx::query_scalar("SELECT body FROM forum.posts WHERE id = ANY($1) ORDER BY id")
|
||||
.bind(&posts)
|
||||
.fetch_all(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(bodies, vec!["", "szöveg", "szöveg"], "only the text removed over a year ago goes");
|
||||
let reason: Option<String> = sqlx::query_scalar("SELECT delete_reason FROM forum.posts WHERE id = $1")
|
||||
.bind(posts[0])
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(reason.as_deref(), Some("hirdetés"), "its place and reason stay");
|
||||
}
|
||||
|
||||
// --- analyses ----------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user