admin: add account spam restriction (join/message gate)

Adds a narrower spam sanction alongside the existing account freeze: a
restricted account keeps every existing membership and conversation, but
cannot join new channels/groups (public join or invite link) and cannot
start a new conversation with a non-contact. Reachable both as a standalone
admin action and as a decision on a reported user's moderation case, with
the same idempotent-supersession and appeal wiring freeze already has.
This commit is contained in:
Astra 2026-09-16 14:03:15 +01:00
parent 3ca8ef1a16
commit f33e25af8d
32 changed files with 750 additions and 44 deletions

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS account_message_restrictions;

View file

@ -0,0 +1,23 @@
CREATE TABLE IF NOT EXISTS account_message_restrictions (
user_id bigint PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
restricted boolean NOT NULL DEFAULT false,
version bigint NOT NULL DEFAULT 0,
restricted_since timestamptz,
restricted_until timestamptz,
reason text NOT NULL DEFAULT '',
actor text NOT NULL DEFAULT '',
command_id text NOT NULL DEFAULT '',
updated_at timestamptz NOT NULL DEFAULT now(),
CONSTRAINT account_message_restrictions_user_id_check CHECK (user_id > 0),
CONSTRAINT account_message_restrictions_shape_check CHECK (
(restricted AND restricted_since IS NOT NULL
AND (restricted_until IS NULL OR restricted_until > restricted_since)
AND (restricted_until IS NULL OR restricted_until <= to_timestamp(2147483647)))
OR
(NOT restricted AND restricted_since IS NULL AND restricted_until IS NULL)
)
);
CREATE INDEX IF NOT EXISTS account_message_restrictions_restricted_idx
ON account_message_restrictions (user_id)
WHERE restricted;

View file

@ -0,0 +1,9 @@
ALTER TABLE public.moderation_actions
DROP CONSTRAINT moderation_actions_kind_check;
ALTER TABLE public.moderation_actions
ADD CONSTRAINT moderation_actions_kind_check CHECK (kind IN (
'mark_scam', 'mark_fake', 'clear_peer_flags', 'freeze_account',
'unfreeze_account', 'delete_private_message',
'delete_channel_message', 'delete_account'
));

View file

@ -0,0 +1,9 @@
ALTER TABLE public.moderation_actions
DROP CONSTRAINT moderation_actions_kind_check;
ALTER TABLE public.moderation_actions
ADD CONSTRAINT moderation_actions_kind_check CHECK (kind IN (
'mark_scam', 'mark_fake', 'clear_peer_flags', 'freeze_account',
'unfreeze_account', 'restrict_account', 'unrestrict_account',
'delete_private_message', 'delete_channel_message', 'delete_account'
));