闭社主体 forked from https://github.com/tootsuite/mastodon
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
875 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: domain_blocks
  5. #
  6. # id :integer 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
  12. #
  13. class DomainBlock < ApplicationRecord
  14. enum severity: [:silence, :suspend]
  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