Hold donations with flagged donor names for moderation; reconcile lost side effects (schema v6)
Test and Release / test (push) Successful in 1m28s
Test and Release / release (push) Successful in 7s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 17:07:32 -08:00
1 parent 473fe192cd
commit 353f7ca5be
16 files changed
+681 -41

No files matched your search

+17 -5
View File
@@ -19,7 +19,7 @@ final class OrderValidator {
* @param array $input Raw client params (goal_id, amount, display_name, anonymous, message, cover_fees).
* @param array $goal sg_goals row as array (id, currency, status, starts_at, ends_at).
* @param array $settings Settings::all()-shaped array.
* @return array{goal_id:int,currency:string,base_minor:int,fee_minor:int,total_minor:int,donor_name:string,is_anonymous:bool,message:string,cover_fees:bool,moderation:string}
* @return array{goal_id:int,currency:string,base_minor:int,fee_minor:int,total_minor:int,donor_name:string,is_anonymous:bool,message:string,cover_fees:bool,moderation:string,moderation_flags:string}
* @throws ValidationException
*/
public static function validate( array $input, array $goal, array $settings, FeeCalculator $fees, int $nowTs ): array {
@@ -59,9 +59,20 @@ final class OrderValidator {
}
// Mask profanity before anything is stored (same-length masking, so length checks above still hold).
$filter = new ProfanityFilter( $settings );
$name = $filter->filter( $name );
$message = $filter->filter( $message );
// A donor name that trips the filter is stored masked AND held for moderation (the donation still completes
// and counts). Anonymous names were blanked above, so they can never flag.
$filter = new ProfanityFilter( $settings );
$nameFlagged = '' !== $name && $filter->matches( $name );
$name = $filter->filter( $name );
$message = $filter->filter( $message );
$msgHeld = ! empty( $settings['moderate_messages'] ) && '' !== $message;
$flags = array();
if ( $nameFlagged ) {
$flags[] = 'name';
}
if ( $msgHeld ) {
$flags[] = 'message';
}
return array(
'goal_id' => (int) $goal['id'],
@@ -73,7 +84,8 @@ final class OrderValidator {
'is_anonymous' => $anon,
'message' => $message,
'cover_fees' => $cover,
'moderation' => ( ! empty( $settings['moderate_messages'] ) && '' !== $message ) ? 'pending' : 'approved',
'moderation' => $flags ? 'pending' : 'approved',
'moderation_flags' => implode( ',', $flags ), // '', 'name', 'message' or 'name,message' (why it is held)
);
}