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.

36 lines
989 B

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