canonical_email_blocks_cli.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'concurrent'
  3. require_relative '../../config/boot'
  4. require_relative '../../config/environment'
  5. require_relative 'cli_helper'
  6. module Mastodon
  7. class CanonicalEmailBlocksCLI < Thor
  8. include CLIHelper
  9. def self.exit_on_failure?
  10. true
  11. end
  12. desc 'find EMAIL', 'Find a given e-mail address in the canonical e-mail blocks'
  13. long_desc <<-LONG_DESC
  14. When suspending a local user, a hash of a "canonical" version of their e-mail
  15. address is stored to prevent them from signing up again.
  16. This command can be used to find whether a known email address is blocked.
  17. LONG_DESC
  18. def find(email)
  19. accts = CanonicalEmailBlock.matching_email(email)
  20. if accts.empty?
  21. say("#{email} is not blocked", :green)
  22. else
  23. say("#{email} is blocked", :red)
  24. end
  25. end
  26. desc 'remove EMAIL', 'Remove a canonical e-mail block'
  27. long_desc <<-LONG_DESC
  28. When suspending a local user, a hash of a "canonical" version of their e-mail
  29. address is stored to prevent them from signing up again.
  30. This command allows removing a canonical email block.
  31. LONG_DESC
  32. def remove(email)
  33. blocks = CanonicalEmailBlock.matching_email(email)
  34. if blocks.empty?
  35. say("#{email} is not blocked", :green)
  36. else
  37. blocks.destroy_all
  38. say("Unblocked #{email}", :green)
  39. end
  40. end
  41. end
  42. end