diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-12-17 23:02:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 23:02:14 +0100 |
commit | 76761d5fc0886e44a7a6eb94ab62aae8204d9e6e (patch) | |
tree | 95cd6ad55eb9c249e212af2378c23160785ec34c /lib | |
parent | 7f803c41e2ca54b7b787b1f111f91357136c0e68 (diff) |
Add ability for admins to delete canonical email blocks (#16644)
* Add admin option to remove canonical email blocks from a deleted account * Add tootctl canonical_email_blocks to inspect and remove canonical email blocks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cli.rb | 4 | ||||
-rw-r--r-- | lib/mastodon/canonical_email_blocks_cli.rb | 64 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/cli.rb b/lib/cli.rb index 8815e137a..35c00e736 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -13,6 +13,7 @@ require_relative 'mastodon/preview_cards_cli' require_relative 'mastodon/cache_cli' require_relative 'mastodon/upgrade_cli' require_relative 'mastodon/email_domain_blocks_cli' +require_relative 'mastodon/canonical_email_blocks_cli' require_relative 'mastodon/ip_blocks_cli' require_relative 'mastodon/maintenance_cli' require_relative 'mastodon/version' @@ -62,6 +63,9 @@ module Mastodon desc 'ip_blocks SUBCOMMAND ...ARGS', 'Manage IP blocks' subcommand 'ip_blocks', Mastodon::IpBlocksCLI + desc 'canonical_email_blocks SUBCOMMAND ...ARGS', 'Manage canonical e-mail blocks' + subcommand 'canonical_email_blocks', Mastodon::CanonicalEmailBlocksCLI + desc 'maintenance SUBCOMMAND ...ARGS', 'Various maintenance utilities' subcommand 'maintenance', Mastodon::MaintenanceCLI diff --git a/lib/mastodon/canonical_email_blocks_cli.rb b/lib/mastodon/canonical_email_blocks_cli.rb new file mode 100644 index 000000000..64b72e603 --- /dev/null +++ b/lib/mastodon/canonical_email_blocks_cli.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'concurrent' +require_relative '../../config/boot' +require_relative '../../config/environment' +require_relative 'cli_helper' + +module Mastodon + class CanonicalEmailBlocksCLI < Thor + include CLIHelper + + def self.exit_on_failure? + true + end + + desc 'find EMAIL', 'Find a given e-mail address in the canonical e-mail blocks' + long_desc <<-LONG_DESC + When suspending a local user, a hash of a "canonical" version of their e-mail + address is stored to prevent them from signing up again. + + This command can be used to find whether a known email address is blocked, + and if so, which account it was attached to. + LONG_DESC + def find(email) + accts = CanonicalEmailBlock.find_blocks(email).map(&:reference_account).map(&:acct).to_a + if accts.empty? + say("#{email} is not blocked", :yellow) + else + accts.each do |acct| + say(acct, :white) + end + end + end + + desc 'remove EMAIL', 'Remove a canonical e-mail block' + long_desc <<-LONG_DESC + When suspending a local user, a hash of a "canonical" version of their e-mail + address is stored to prevent them from signing up again. + + This command allows removing a canonical email block. + LONG_DESC + def remove(email) + blocks = CanonicalEmailBlock.find_blocks(email) + if blocks.empty? + say("#{email} is not blocked", :yellow) + else + blocks.destroy_all + say("Removed canonical email block for #{email}", :green) + end + end + + private + + def color(processed, failed) + if !processed.zero? && failed.zero? + :green + elsif failed.zero? + :yellow + else + :red + end + end + end +end |