-
Notifications
You must be signed in to change notification settings - Fork 83
Add ActivityPub moderation system with hierarchical blocking #2020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d1348fd
Add comprehensive ActivityPub moderation system
obenland d640adf
Add comprehensive PHPUnit tests for Moderation API
obenland 202047e
Apply PHPCBF code formatting fixes
obenland 2892d71
Improve moderation JavaScript UX and fix terminology
obenland cc9cf01
Add code coverage annotations and refactor blocking logic
obenland db625c1
Add changelog entry for blocking and moderation system
obenland 72f919e
Fix AJAX nonce verification order for better security
obenland 3c8d6f0
Consolidate moderation admin functionality and fix AJAX parameter con…
obenland ecaacac
Add moderation meta and settings for ActivityPub
obenland 2084082
Align variable assignments in ajax_moderation_settings
obenland c4b48e6
Fix test_add_user_block_valid_types by mocking remote actor response
obenland b4f9c68
Remove explicit cap check
obenland 42bb423
Backslashit
obenland 52b0423
Remove actor block functionality from moderation settings
obenland 11dd52a
Merge branch 'trunk' into add/block-lists
obenland d225429
Moderation: Refine UI with singular class names and table-only handling
obenland 1d94cf3
Use namespaced functions and improve moderation labels
obenland 15679ca
Refactor moderation to remove actor-level blocking
obenland 889aa91
Merge branch 'trunk' into add/block-lists
obenland dcf1cc1
Fix feedback
obenland 9308e9f
Merge branch 'trunk' into add/block-lists
obenland 51038f8
Refactor moderation to use Activity objects
obenland 2d264e2
Improve ActivityPub moderation JavaScript with duplicate prevention a…
obenland 92cc5be
add summary and name
pfefferle f1b9224
Improve object URI handling and keyword checks in moderation
pfefferle 8150dd9
Merge branch 'trunk' into add/block-lists
pfefferle 605c73c
Add 'id' field to Note objects in moderation tests
pfefferle 439c17f
Add tests for blocked activity attributes in moderation
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Add comprehensive blocking and moderation system for ActivityPub with user-specific and site-wide controls for actors, domains, and keywords. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,305 @@ | ||
| /** | ||
| * ActivityPub Moderation Admin JavaScript | ||
| */ | ||
|
|
||
| (function( $ ) { | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Helper function to validate domain format | ||
| */ | ||
| function isValidDomain( domain ) { | ||
| // Basic domain validation - must contain at least one dot and valid characters | ||
| var domainRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; | ||
| return domainRegex.test( domain ) && domain.includes( '.' ) && domain.length > 3; | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to check if a term already exists in the UI | ||
| */ | ||
| function isTermAlreadyBlocked( type, value, context, userId ) { | ||
| var selector; | ||
| if ( context === 'user' ) { | ||
| selector = '.activitypub-user-block-list[data-user-id="' + userId + '"] .remove-user-block-btn[data-type="' + type + '"][data-value="' + value + '"]'; | ||
| } else if ( context === 'site' ) { | ||
| selector = '.remove-site-block-btn[data-type="' + type + '"][data-value="' + value + '"]'; | ||
| } | ||
| return $( selector ).length > 0; | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to add a blocked term to the UI | ||
| */ | ||
| function addBlockedTermToUI( type, value, context, userId ) { | ||
| if ( context === 'user' ) { | ||
| // For user moderation, add to the appropriate table | ||
| var container = $( '.activitypub-user-block-list[data-user-id="' + userId + '"]' ); | ||
|
|
||
| var table = container.find( '.activitypub-blocked-' + type ); | ||
| if ( table.length === 0 ) { | ||
| table = $( '<table class="widefat striped activitypub-blocked-' + type + '" role="presentation" style="max-width: 500px; margin: 15px 0;"><tbody></tbody></table>' ); | ||
| container.find( '#new_user_' + type ).closest( '.add-user-block-form' ).before( table ); | ||
| } | ||
| table.append( '<tr><td>' + value + '</td><td style="width: 80px;"><button type="button" class="button button-small remove-user-block-btn" data-type="' + type + '" data-value="' + value + '">Remove</button></td></tr>' ); | ||
| } else if ( context === 'site' ) { | ||
| // For site moderation, add to the appropriate table | ||
| var container = $( '#new_site_' + type ).closest( '.activitypub-site-block-list' ); | ||
| var table = container.find( '.activitypub-site-blocked-' + type ); | ||
| if ( table.length === 0 ) { | ||
| table = $( '<table class="widefat striped activitypub-site-blocked-' + type + '" role="presentation" style="max-width: 500px; margin: 15px 0;"><tbody></tbody></table>' ); | ||
| container.find( '.add-site-block-form' ).before( table ); | ||
| } | ||
| table.append( '<tr><td>' + value + '</td><td style="width: 80px;"><button type="button" class="button button-small remove-site-block-btn" data-type="' + type + '" data-value="' + value + '">Remove</button></td></tr>' ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Helper function to remove a blocked term from the UI | ||
| */ | ||
| function removeBlockedTermFromUI( type, value, context ) { | ||
| // Find and remove the specific blocked term element | ||
| var selector = '.remove-' + context + '-block-btn[data-type="' + type + '"][data-value="' + value + '"]'; | ||
| var button = $( selector ); | ||
|
|
||
| if ( button.length > 0 ) { | ||
| // Remove the parent table row | ||
| var parent = button.closest( 'tr' ); | ||
| var container = parent.closest( 'table' ); | ||
| parent.remove(); | ||
|
|
||
| // If the container is now empty, remove it | ||
| if ( container.find( 'tr' ).length === 0 ) { | ||
| container.remove(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Initialize moderation functionality | ||
| */ | ||
| function init() { | ||
| // User moderation management. | ||
| initUserModeration(); | ||
|
|
||
| // Site moderation management. | ||
| initSiteModeration(); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize user moderation management | ||
| */ | ||
| function initUserModeration() { | ||
| // Function to add user blocked term. | ||
| function addUserBlockedTerm( type, userId ) { | ||
| var input = $( '#new_user_' + type ); | ||
| var value = input.val().trim(); | ||
|
|
||
| if ( ! value ) { | ||
| // Use wp.a11y.speak for better accessibility. | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( activitypubModerationL10n.enterValue, 'assertive' ); | ||
| } else { | ||
| alert( activitypubModerationL10n.enterValue ); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Validate domain format if this is a domain block | ||
| if ( type === 'domain' && ! isValidDomain( value ) ) { | ||
| var message = activitypubModerationL10n.invalidDomain || 'Please enter a valid domain (e.g., example.com).'; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } | ||
| alert( message ); | ||
| return; | ||
| } | ||
|
|
||
| // Check if the term is already blocked | ||
| if ( isTermAlreadyBlocked( type, value, 'user', userId ) ) { | ||
| var message = activitypubModerationL10n.alreadyBlocked || 'This term is already blocked.'; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } | ||
| alert( message ); | ||
| return; | ||
| } | ||
|
|
||
| wp.ajax.post( 'activitypub_moderation_settings', { | ||
| context: 'user', | ||
| operation: 'add', | ||
| user_id: userId, | ||
| type: type, | ||
| value: value, | ||
| _wpnonce: activitypubModerationL10n.nonce | ||
| }).done( function() { | ||
| // Clear input and add item to the UI. | ||
| input.val( '' ); | ||
| addBlockedTermToUI( type, value, 'user', userId ); | ||
| }).fail( function( response ) { | ||
| var message = response && response.message ? response.message : activitypubModerationL10n.addBlockFailed; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } else { | ||
| alert( message ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Function to remove user blocked term. | ||
| function removeUserBlockedTerm( type, value, userId ) { | ||
| wp.ajax.post( 'activitypub_moderation_settings', { | ||
| context: 'user', | ||
| operation: 'remove', | ||
| user_id: userId, | ||
| type: type, | ||
| value: value, | ||
| _wpnonce: activitypubModerationL10n.nonce | ||
| }).done( function() { | ||
| removeBlockedTermFromUI( type, value, 'user' ); | ||
| }).fail( function( response ) { | ||
| var message = response && response.message ? response.message : activitypubModerationL10n.removeBlockFailed; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } else { | ||
| alert( message ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Add user block functionality (button click). | ||
| $( document ).on( 'click', '.add-user-block-btn', function( e ) { | ||
| e.preventDefault(); | ||
| var type = $( this ).data( 'type' ); | ||
| var userId = $( this ).closest( '.activitypub-user-block-list' ).data( 'user-id' ); | ||
| addUserBlockedTerm( type, userId ); | ||
| }); | ||
|
|
||
| // Add user block functionality (Enter key). | ||
| $( document ).on( 'keypress', '#new_user_domain, #new_user_keyword', function( e ) { | ||
| if ( e.which === 13 ) { // Enter key. | ||
| e.preventDefault(); | ||
| var inputId = $( this ).attr( 'id' ); | ||
| var type = inputId.replace( 'new_user_', '' ); | ||
| var userId = $( this ).closest( '.activitypub-user-block-list' ).data( 'user-id' ); | ||
| addUserBlockedTerm( type, userId ); | ||
| } | ||
| }); | ||
|
|
||
| // Remove user block functionality. | ||
| $( document ).on( 'click', '.remove-user-block-btn', function( e ) { | ||
| e.preventDefault(); | ||
| var type = $( this ).data( 'type' ); | ||
| var value = $( this ).data( 'value' ); | ||
| var userId = $( this ).closest( '.activitypub-user-block-list' ).data( 'user-id' ); | ||
| removeUserBlockedTerm( type, value, userId ); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize site moderation management | ||
| */ | ||
| function initSiteModeration() { | ||
| // Function to add site blocked term. | ||
| function addSiteBlockedTerm( type ) { | ||
| var input = $( '#new_site_' + type ); | ||
| var value = input.val().trim(); | ||
|
|
||
| if ( ! value ) { | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( activitypubModerationL10n.enterValue, 'assertive' ); | ||
| } else { | ||
| alert( activitypubModerationL10n.enterValue ); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Validate domain format if this is a domain block | ||
| if ( type === 'domain' && ! isValidDomain( value ) ) { | ||
| var message = activitypubModerationL10n.invalidDomain || 'Please enter a valid domain (e.g., example.com).'; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } | ||
| alert( message ); | ||
| return; | ||
| } | ||
|
|
||
| // Check if the term is already blocked | ||
| if ( isTermAlreadyBlocked( type, value, 'site' ) ) { | ||
| var message = activitypubModerationL10n.alreadyBlocked || 'This term is already blocked.'; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } | ||
| alert( message ); | ||
| return; | ||
| } | ||
|
|
||
| wp.ajax.post( 'activitypub_moderation_settings', { | ||
| context: 'site', | ||
| operation: 'add', | ||
| type: type, | ||
| value: value, | ||
| _wpnonce: activitypubModerationL10n.nonce | ||
| }).done( function() { | ||
| // Clear input and add item to the UI. | ||
| input.val( '' ); | ||
| addBlockedTermToUI( type, value, 'site' ); | ||
| }).fail( function( response ) { | ||
| var message = response && response.message ? response.message : activitypubModerationL10n.addBlockFailed; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } else { | ||
| alert( message ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Function to remove site blocked term. | ||
| function removeSiteBlockedTerm( type, value ) { | ||
| wp.ajax.post( 'activitypub_moderation_settings', { | ||
| context: 'site', | ||
| operation: 'remove', | ||
| type: type, | ||
| value: value, | ||
| _wpnonce: activitypubModerationL10n.nonce | ||
| }).done( function() { | ||
| removeBlockedTermFromUI( type, value, 'site' ); | ||
| }).fail( function( response ) { | ||
| var message = response && response.message ? response.message : activitypubModerationL10n.removeBlockFailed; | ||
| if ( wp.a11y && wp.a11y.speak ) { | ||
| wp.a11y.speak( message, 'assertive' ); | ||
| } else { | ||
| alert( message ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Add site block functionality (button click). | ||
| $( document ).on( 'click', '.add-site-block-btn', function( e ) { | ||
| e.preventDefault(); | ||
| var type = $( this ).data( 'type' ); | ||
| addSiteBlockedTerm( type ); | ||
| }); | ||
|
|
||
| // Add site block functionality (Enter key). | ||
| $( document ).on( 'keypress', '#new_site_domain, #new_site_keyword', function( e ) { | ||
| if ( e.which === 13 ) { // Enter key. | ||
| e.preventDefault(); | ||
| var inputId = $( this ).attr( 'id' ); | ||
| var type = inputId.replace( 'new_site_', '' ); | ||
| addSiteBlockedTerm( type ); | ||
| } | ||
| }); | ||
|
|
||
| // Remove site block functionality. | ||
| $( document ).on( 'click', '.remove-site-block-btn', function( e ) { | ||
| e.preventDefault(); | ||
| var type = $( this ).data( 'type' ); | ||
| var value = $( this ).data( 'value' ); | ||
| removeSiteBlockedTerm( type, value ); | ||
| }); | ||
| } | ||
|
|
||
| // Initialize when document is ready. | ||
| $( document ).ready( init ); | ||
|
|
||
| })( jQuery ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.