You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
541 B

  1. # frozen_string_literal: true
  2. class DomainBlock < ApplicationRecord
  3. enum severity: [:silence, :suspend]
  4. attr_accessor :retroactive
  5. validates :domain, presence: true, uniqueness: true
  6. has_many :accounts, foreign_key: :domain, primary_key: :domain
  7. delegate :count, to: :accounts, prefix: true
  8. def self.blocked?(domain)
  9. where(domain: domain, severity: :suspend).exists?
  10. end
  11. before_validation :normalize_domain
  12. private
  13. def normalize_domain
  14. self.domain = TagManager.instance.normalize_domain(domain)
  15. end
  16. end