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.

35 lines
916 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: domain_blocks
  5. #
  6. # domain :string default(""), not null
  7. # created_at :datetime not null
  8. # updated_at :datetime not null
  9. # severity :integer default("silence")
  10. # reject_media :boolean default(FALSE), not null
  11. # id :bigint not null, primary key
  12. #
  13. class DomainBlock < ApplicationRecord
  14. enum severity: [:silence, :suspend, :noop]
  15. attr_accessor :retroactive
  16. validates :domain, presence: true, uniqueness: true
  17. has_many :accounts, foreign_key: :domain, primary_key: :domain
  18. delegate :count, to: :accounts, prefix: true
  19. def self.blocked?(domain)
  20. where(domain: domain, severity: :suspend).exists?
  21. end
  22. before_validation :normalize_domain
  23. private
  24. def normalize_domain
  25. self.domain = TagManager.instance.normalize_domain(domain)
  26. end
  27. end