Repository navigation
moderate 1.0.0.beta3
Pre-releaseAdded
- Human labels for reportable fields.
has_reportable_content :body, :files, labels: { body: "Chat message", files: "Chat photo" }(andreportable_fields …, labels:) names
each field once, next to its declaration, so moderators and affected users stop reading raw
column names («Body») for what was reported. Resolution: the declared label (a String, or a
lambda evaluated at read time) → i18nmoderate.reportable_fields.<model>.<field>(walking
reportable STI parents) →moderate.reportable_fields.<field>→field.humanize. Read it
withModerate.reportable_field_label(record_or_class_or_type, field),
Report#reported_field_label,Flag#field_label, orrecord.reportable_field_label(field);
labels resolve from the stored type, so they survive the content being deleted. A label key
for an undeclared field raises. Hosts that kept their own field → label map can delete it. - Labels everywhere the gem names a field. The public appeal page shows the reported
content's label; the statement-of-reasons payload (affected_user_decision,report_decision)
carriesreported_field+reported_field_label;report_receivedcarries both and appends
the label to its summary;content_flaggedand theflag_decisionaudit carryfield_label,
and thecontent_flaggedsummary prints the label instead ofType#field. - Default locale files (
config/locales/en.yml,es.yml): the appeal page's new string and
generic labels for common field names (body→ "Text"/"Texto",avatar→ "Profile
photo"/"Foto de perfil", …). - Labels for every value list the gem defines, in English and Spanish.
Moderate.taxonomy_label(kind, value)names a community category, a DSA legal reason, an
EU member state, a content type, a resolution basis, a decision, an intake kind, a report /
flag / appeal status, a flag source or mode, or an appeal source in the current locale, from
moderate.<scope>.<value>(scopes inModerate::TAXONOMY_LABEL_SCOPES), falling back to
the value humanized so a host's own category or adapter name still renders. The gem's
config/locales/{en,es}.ymlnow carry every value, and a host's translation wins. The
public notice form, which always readmoderate.legal_reasons/content_types/member_states,
now shows real copy in both languages.Moderate::Report.category_optionsgives a
report form's select its[label, value]pairs, honoringconfig.report_categories. Hosts
that translated the regulator's vocabulary themselves can drop their copies for en/es. - An in-app report's details are optional. A community report with a blank message now
files with the category's label (in the reporter's language) as its message, instead of
failing "Message can't be blank": the category a person picked is the reason. A DSA notice
still needs its own explanation (Art. 16(2)(a)). Hosts that filled the message with the
category label themselves, or whose forms said "optional" while the gem refused it, can
stop. - "Report and block":
report!(…, block: true)blocks the person responsible for the
content in the same transaction as the report (both or neither; the receipt goes out
after), through the one block path (idempotent, audited,on_block,user_blocked).Report#block_reported_user, which has existed since beta1
and which nothing read, is what it sets. Nothing is blocked when the content has no person
behind it. - Reports know what kind of content they're about. A community report with no
content_typetakes the reportable'smoderation_content_type(with or without the field
argument, since chats' takes none), stored if it is one ofReport::CONTENT_TYPES, else
"other", so a host's own word never fails an intake.Moderate::Reportabledefines it
(nil) andModerate::Actoranswers"user_profile". Hosts that mapped their models to
content types in the report controller can delete the map. Reportable#to_moderation_sgidand the view helper
moderate_report_target_path(record, field:): the signed report target and the report
form's path, public and non-expiring, for markup rendered once for many viewers (a chat
bubble broadcast to everyone in the thread, a fragment cache), where
moderate_report_link's per-viewer check can't run. The helper always probed for
to_moderation_sgid; now it exists. Hosts building
to_sgid_param(for: Moderate::Report::SIGNED_GLOBAL_ID_PURPOSE)by hand can use these
(withoutexpires_in: nil, that token changed on every render and died after a month).- The
content_removedevent is emitted. It was in the documented vocabulary from
beta1 and nothing sent it. A decision whoseremove_reported_field!removed something now
auditscontent_removedinside the decision's transaction and announces it with the
decision notices, to the content's person, withreported_field, its label and the
moderator's reason. (notice_received, which the DSA form has always sent, joins the
vocabulary lists in the README, the configuration guide and the initializer.) examples/regexp_pattern_adapter.rb: a reference adapter for what a word list can't
express (phone numbers, links, "contact me on…"), each pattern filed under the category it
means, synchronous so:blockworks too, the matched fragments inraw[:matches]. The
idea is @killondark's (#1, written against the 0.x validator).- Enforce from a flag.
flag.action!(by:, note:, remove_content: true)and
flag.action!(by:, note:, ban_user: true)(any combination, plusresolution_basis:)
escalate to a report and resolve it: the newest open report on the same content and field
if a person already filed one, else a system report (no reporter, so no receipt and no
reporter-facing decision). Content is removed through the reportable's
remove_reported_field!, the ban goes through yourban_handler, and the affected user
gets the statement of reasons and the appeal window a restriction requires. It runs under
the flag's row lock and then the content's, so two moderators enforcing the same flag, or
two flags on the same content, enforce once: the second closes against the decision the
first took (unless it asks for more, say a ban after a removal). A recorded removal only
counts if the content is gone now, so an older decision that said "removed" without
removing anything doesn't stand in for a real one. A system report may name the flag's
field even when people can't report that field (a filtered image) — an exception only
the escalation sets, on a report with no reporter, never on a DSA notice — and
enforcing a classifier's flag through a person's earlier report adds the classifier to
that report's automated-means disclosure.flag.reportis the report it went through.
Hosts that hand-wrote this bridge (find-or-create a report, resolve it, then close the
flag) can delete it. Without those optionsaction!is the triage close it was. Moderate::Flag.flag_for_review!(record, field:, by:, note: nil): an administrator
filing content for review by hand (the "Flag for review" button on a transcript line). It
returns the pending flag on that field if one already waits, else files a
source: "manual"flag owned by the content's person, with the evidence snapshot as
excerpt andcontextnaming who filed it;flag.previously_new_record?says which. The
check and the insert run under the record's row lock, so two administrators pressing it
together file one flag. Audited as:flag_filed. Hosts that hand-assembled the nine
Flag.flag!arguments (and, without a lock, could file two) can call this instead.Flag#resolve!, an alias ofaction!: reports and flags now share one verb and one
keyword contract, which is whatModerate::Moderation#resolveanddocs/madmin.md
always assumed.
Changed
-
Flag#action!/#dismiss!go throughModerate::Services::ResolveFlag. The beta2
model methods were a second closing path with no row lock and noflag_decisionaudit;
now there is one. Re-closing an already decided flag returns it unchanged (as the service
always did) instead of overwriting the first decision. -
ResolveReport.new(report, by:, deliver: false)holds the decision notices back for a
caller that decides inside a lock of its own;#deliver_decision_noticessends them. -
Notices follow Active Record's after_commit rules, on every supported Rails. Report,
flag and appeal decisions (with theiruser_bannedandcontent_removed), the in-app
report receipt, anduser_blocked/user_unblockedare owned by the transaction they
were queued in (Moderate::DeferredNotices,record.after_commit_notice { … }): each is
enrolled in the current transaction as a transaction record, exactly as a saved record
is, so the transaction sends it on commit and drops it on rollback or when an exception
ends it. Nested transactions and savepoints under a joinable parent send at the
outermost commit; a rolled-back savepoint drops only its own; under a parent that isn't
joinable (including the wrapper of Rails' transactional tests) it's sent at the
savepoint's release, when after_commit runs too; with no transaction open, at once.
Under multiple databases or shards, the notice joins the transaction of the connection
it's queued on:record.after_commit_notice(on: connection) { … },on:defaulting to
the record class's connection at call time. Queue it inside the transaction that saved
the record, on that transaction's connection. The gem's services do: each captures its
model's connection at the top of its transaction, before any save, and passes it to
every notice it queues, so a host callback that switches databases or shards mid-save
can't move them. A host that callsafter_commit_noticeitself passeson:when it uses
connected_to.
Nothing lives on a record instance or on the thread. A host that decides, reports or
blocks inside a transaction of its own and rolls it back tells nobody; Rails 7.1, 7.2 and
8.x behave the same.Moderate.apply_ban(…, announce: false)+
Moderate.announce_bansplit the ban's notice from the ban for the same reason. (The
public notice and appeal forms' own receipts are unchanged.) -
One lock order for enforcement: flag, then content, then the person (for a ban), then
the report. Row locks are taken by query (Moderate.with_row_lock), so concurrent
decisions on the same content, or bans of the same person from different content,
serialize instead of enforcing twice or deadlocking. -
One ban per person per episode. A decision asked to ban someone who a decision on
any content or field has already banned since this conduct was raised (the report's
creation; the flag's, for an escalation) doesn't call theban_handleragain: it records
resolution_actions["ban_already_applied_by"]with that decision's id. An older ban
doesn't count (the person may have been unbanned since). -
A manual flag is not automated means. A report's automated-processing disclosure
(DSA Art. 17(3)(c)) no longer countssource: "manual"flags on the same content. -
Removing content that isn't removable refuses the decision.
remove_content: true
when the reportable'sremove_reported_field!removes nothing (the default for a
reportable that defines no removal, a field that isn't removable, content already gone),
when the content was deleted (the report's reportable is nil), or when the reportable has
no removal method at all, now raisesRecordInvalid("Nothing was removed…",moderate.errors.nothing_removed)
and rolls the decision back, a ban with it. Before, the report was closed with
decision_visibility: "content_removed"and the affected person was told their content
was removed while it was still up. Behavior change: offer "remove content" only where
removable_reported_field?says it can happen. -
A ban needs a
ban_handler. With none configured,ban_user: true(on a report or a
flag) andModerate.apply_banraiseModerate::ConfigurationErrorbefore anything
changes. Before, the default no-op handler let the decision record
decision_visibility: "account_suspended", audit and announceuser_banned, and send the
person a statement of reasons saying their account was suspended, while nothing had
suspended it: a false Art. 17 statement.config.ban_handler = nilrestores the default;
a non-callable raisesArgumentError;config.ban_handler_configured?tells. Decisions
without a ban are unaffected. Behavior change for hosts that never wired one and
relied on the no-op. -
An in-app report is refused when its reporter may not report the content. A community
report filed by a signed-in person now validates the reportable's ownreport_visible_to?
(never your own content; for a chats message, only a conversation you're in), with an
error on:reportable("isn't something you can report",
moderate.errors.not_reportable_by_reporter). The report link always hid itself on that
rule, and chats' docs said moderate re-checks it server-side, but nothing did: a signed
target replayed or pasted from elsewhere reached the model unchecked. DSA notices and
system reports (no reporter) are not affected. Behavior change: a host that files
community reports on behalf of people who couldn't see the content now gets a validation
error; use a manual flag (Flag.flag_for_review!) for an administrator's own concern.
Fixed
moderate_report_target_path(andmoderate_report_link) find the host's report route
from inside another engine's views, throughmain_app. Rendered in a chats slot, the
helper fell back to the hard-coded/reports/new.- The transparency page labels its counters from the gem's own keys. Two of its cards
readmoderation.legal_reasons.*/moderation.resolution_bases.*, a namespace from the
app the gem was extracted from that no other part of the gem uses; the rest printed raw
values humanized. Every card now goes throughModerate.taxonomy_label. Moderate.blocked_ids_for(nil)returns the same type as every other call: an empty
relation selecting user ids, not[]. Composing the two shapes was a real bug in a host
(relation | arrayyields User records, andinclude?(id)silently missed). Call.ids
for an Array.Report#pending?andAppeal#pending?exist, twins of thependingscopes all three
queues share (docs/madmin.mdcalled them and they didn't exist).Moderate::Moderation#resolveworks on flags. It calledrecord.resolve!, which
Moderate::Flagdidn't have, so a host following the concern's own documentation got a
NoMethodError(as an alert flash) on every flag. It also passesresolution_basiswhen
the form sends one, and its flash says "Flag actioned." / "Flag dismissed." for flags.- Content spoken by something that isn't a person no longer breaks reports and flags.
moderate storedreportable.reported_ownerstraight intoReport#reported_userand
Flag#owner, both associations toconfig.user_class. A support desk or a bot behind the
content (chats answersauthor || sender, which is a desk for an unsigned support reply)
raisedActiveRecord::AssociationTypeMismatchand the report never filed. The new
Moderate.responsible_user(record)keeps the owner only if it is a person; anything else
means "nobody to reach": the report files, the evidence is kept, content can still be
removed, and only a decision notice or a ban has no addressee. Report intake,Flag.flag!,
the:flagafter_commit andClassifyJoball go through it. A reportable that never
definedreported_ownerstill raises at the first report. Hosts that overrode
Chats::Message#reported_ownerto return nil for non-users can delete the override. - The gem's locale files can no longer override the host's. The engine appended its
config/localestoconfig.i18n.load_path, which Rails loads AFTER the app's own locale
files — harmless while the directory was empty, but any shipped default would have silently
beaten the host's translation of the same key. Rails already loads an engine's
config/localesbefore the app's, so the initializer is gone.
Documentation
docs/chats.md: the whole chats integration from moderate's side (reportable and
filtered messages, blocks, Report on a broadcast bubble, Block in the thread menu, the
admin side, a launch checklist), the shape two production hosts converged on.docs/madmin.mdruns as written. It calledscope :resolved(the scopes are
actioned),attribute :kind/:details(the columns areintake_kind/message),
report.pending?(now real),Moderate.system_actor(never existed; automated decisions
passby: nil) andflag.scores[:csam](scores are JSON with string keys, and the
canonical category issexual/minors). The flag controller now shows enforcement, and a
new section covers "Flag for review" from a browse screen.
Upgrading from 1.0.0.beta2
No migrations. Check these against your app:
- Wire
config.ban_handlerif any moderator can press "ban": without one, a ban now
raises instead of being a silent no-op. - Reports are visibility-checked. If you file community reports with a
reporter:who
couldn't see the content, they now fail validation. UseFlag.flag_for_review!for an
administrator's own concern. - Delete the workarounds this release makes unnecessary, if you wrote them:
- a
reported_owneroverride that returns nil for non-users; - a find-or-create-report bridge for removing or banning from a flag (use
flag.action!(remove_content:, ban_user:)); - a hand-assembled manual
Flag.flag!(useFlag.flag_for_review!); - a model-to-
content_typemap in your report controller; - your own "report and block" (use
report!(…, block: true)); to_sgid_param(for: Moderate::Report::SIGNED_GLOBAL_ID_PURPOSE)(use
to_moderation_sgidormoderate_report_target_path);- en/es translations of the gem's taxonomies and field names (keep only the ones you
changed); - a duplicated
config.filternext to amoderatesdeclaration for the same field.
- a
- "Remove content" must remove something. If your admin offers it on content whose
remove_reported_field!returns false, those decisions now fail instead of claiming a
removal. Gate the checkbox onremovable_reported_field?. Flag#action!re-closing an already decided flag no longer overwrites the first
decision: it returns the flag as it was.Moderate.blocked_ids_for(nil)is an empty relation, not[]. Call.idsif you
need an Array.