canonical_email_blocks_cli.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. and if so, which account it was attached to.
  18. LONG_DESC
  19. def find(email)
  20. accts = CanonicalEmailBlock.find_blocks(email).map(&:reference_account).map(&:acct).to_a
  21. if accts.empty?
  22. say("#{email} is not blocked", :yellow)
  23. else
  24. accts.each do |acct|
  25. say(acct, :white)
  26. end
  27. end
  28. end
  29. desc 'remove EMAIL', 'Remove a canonical e-mail block'
  30. long_desc <<-LONG_DESC
  31. When suspending a local user, a hash of a "canonical" version of their e-mail
  32. address is stored to prevent them from signing up again.
  33. This command allows removing a canonical email block.
  34. LONG_DESC
  35. def remove(email)
  36. blocks = CanonicalEmailBlock.find_blocks(email)
  37. if blocks.empty?
  38. say("#{email} is not blocked", :yellow)
  39. else
  40. blocks.destroy_all
  41. say("Removed canonical email block for #{email}", :green)
  42. end
  43. end
  44. private
  45. def color(processed, failed)
  46. if !processed.zero? && failed.zero?
  47. :green
  48. elsif failed.zero?
  49. :yellow
  50. else
  51. :red
  52. end
  53. end
  54. end
  55. end