mirror of
https://github.com/funamitech/mastodon
synced 2024-12-01 00:08:39 +09:00
parent
699db454c3
commit
7a1f8a58df
@ -15,7 +15,7 @@ class AccountDomainBlock < ApplicationRecord
|
|||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
validates :domain, presence: true, uniqueness: { scope: :account_id }
|
validates :domain, presence: true, uniqueness: { scope: :account_id }, domain: true
|
||||||
|
|
||||||
after_commit :remove_blocking_cache
|
after_commit :remove_blocking_cache
|
||||||
after_commit :remove_relationship_cache
|
after_commit :remove_relationship_cache
|
||||||
|
@ -4,7 +4,7 @@ module DomainNormalizable
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_validation :normalize_domain
|
before_save :normalize_domain
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
class DomainAllow < ApplicationRecord
|
class DomainAllow < ApplicationRecord
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
|
|
||||||
validates :domain, presence: true, uniqueness: true
|
validates :domain, presence: true, uniqueness: true, domain: true
|
||||||
|
|
||||||
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class DomainBlock < ApplicationRecord
|
|||||||
|
|
||||||
enum severity: [:silence, :suspend, :noop]
|
enum severity: [:silence, :suspend, :noop]
|
||||||
|
|
||||||
validates :domain, presence: true, uniqueness: true
|
validates :domain, presence: true, uniqueness: true, domain: true
|
||||||
|
|
||||||
has_many :accounts, foreign_key: :domain, primary_key: :domain
|
has_many :accounts, foreign_key: :domain, primary_key: :domain
|
||||||
delegate :count, to: :accounts, prefix: true
|
delegate :count, to: :accounts, prefix: true
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
class EmailDomainBlock < ApplicationRecord
|
class EmailDomainBlock < ApplicationRecord
|
||||||
include DomainNormalizable
|
include DomainNormalizable
|
||||||
|
|
||||||
validates :domain, presence: true, uniqueness: true
|
validates :domain, presence: true, uniqueness: true, domain: true
|
||||||
|
|
||||||
def self.block?(email)
|
def self.block?(email)
|
||||||
_, domain = email.split('@', 2)
|
_, domain = email.split('@', 2)
|
||||||
|
17
app/validators/domain_validator.rb
Normal file
17
app/validators/domain_validator.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class DomainValidator < ActiveModel::EachValidator
|
||||||
|
def validate_each(record, attribute, value)
|
||||||
|
return if value.blank?
|
||||||
|
|
||||||
|
record.errors.add(attribute, I18n.t('domain_validator.invalid_domain')) unless compliant?(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def compliant?(value)
|
||||||
|
Addressable::URI.new.tap { |uri| uri.host = value }
|
||||||
|
rescue Addressable::URI::InvalidURIError
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
@ -628,6 +628,8 @@ en:
|
|||||||
people:
|
people:
|
||||||
one: "%{count} person"
|
one: "%{count} person"
|
||||||
other: "%{count} people"
|
other: "%{count} people"
|
||||||
|
domain_validator:
|
||||||
|
invalid_domain: is not a valid domain name
|
||||||
errors:
|
errors:
|
||||||
'403': You don't have permission to view this page.
|
'403': You don't have permission to view this page.
|
||||||
'404': The page you are looking for isn't here.
|
'404': The page you are looking for isn't here.
|
||||||
|
Loading…
Reference in New Issue
Block a user