مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
style(rubocop): fix all safe auto correctable offenses
هذا الالتزام موجود في:
@@ -18,7 +18,7 @@
|
||||
# excluded_click_domains :text(65535)
|
||||
#
|
||||
|
||||
require 'resolv'
|
||||
require "resolv"
|
||||
|
||||
class TrackDomain < ApplicationRecord
|
||||
|
||||
@@ -27,16 +27,16 @@ class TrackDomain < ApplicationRecord
|
||||
belongs_to :server
|
||||
belongs_to :domain
|
||||
|
||||
validates :name, :presence => true, :format => {:with => /\A[a-z0-9\-]+\z/}, :uniqueness => {:scope => :domain_id, :message => "is already added"}
|
||||
validates :domain_id, :uniqueness => {:scope => :server_id, :message => "already has a track domain for this server"}
|
||||
validates :name, presence: true, format: { with: /\A[a-z0-9-]+\z/ }, uniqueness: { scope: :domain_id, message: "is already added" }
|
||||
validates :domain_id, uniqueness: { scope: :server_id, message: "already has a track domain for this server" }
|
||||
validate :validate_domain_belongs_to_server
|
||||
|
||||
scope :ok, -> { where(:dns_status => 'OK')}
|
||||
scope :ok, -> { where(dns_status: "OK") }
|
||||
|
||||
after_create :check_dns, :unless => :dns_status
|
||||
after_create :check_dns, unless: :dns_status
|
||||
|
||||
before_validation do
|
||||
self.server = self.domain.server if self.domain && self.server.nil?
|
||||
self.server = domain.server if domain && server.nil?
|
||||
end
|
||||
|
||||
def full_name
|
||||
@@ -48,26 +48,24 @@ class TrackDomain < ApplicationRecord
|
||||
end
|
||||
|
||||
def dns_ok?
|
||||
self.dns_status == 'OK'
|
||||
dns_status == "OK"
|
||||
end
|
||||
|
||||
def check_dns
|
||||
result = self.domain.resolver.getresources(self.full_name, Resolv::DNS::Resource::IN::CNAME)
|
||||
result = domain.resolver.getresources(full_name, Resolv::DNS::Resource::IN::CNAME)
|
||||
records = result.map { |r| r.name.to_s.downcase }
|
||||
if records.empty?
|
||||
self.dns_status = 'Missing'
|
||||
self.dns_error = "There is no record at #{self.full_name}"
|
||||
self.dns_status = "Missing"
|
||||
self.dns_error = "There is no record at #{full_name}"
|
||||
elsif records.size == 1 && records.first == Postal.config.dns.track_domain
|
||||
self.dns_status = "OK"
|
||||
self.dns_error = nil
|
||||
else
|
||||
if records.size == 1 && records.first == Postal.config.dns.track_domain
|
||||
self.dns_status = 'OK'
|
||||
self.dns_error = nil
|
||||
else
|
||||
self.dns_status = 'Invalid'
|
||||
self.dns_error = "There is a CNAME record at #{self.full_name} but it points to #{records.first} which is incorrect. It should point to #{Postal.config.dns.track_domain}."
|
||||
end
|
||||
self.dns_status = "Invalid"
|
||||
self.dns_error = "There is a CNAME record at #{full_name} but it points to #{records.first} which is incorrect. It should point to #{Postal.config.dns.track_domain}."
|
||||
end
|
||||
self.dns_checked_at = Time.now
|
||||
self.save!
|
||||
save!
|
||||
dns_ok?
|
||||
end
|
||||
|
||||
@@ -76,9 +74,9 @@ class TrackDomain < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_domain_belongs_to_server
|
||||
if self.domain && ![self.server, self.server.organization].include?(self.domain.owner)
|
||||
errors.add :domain, "does not belong to the server or the server's organization"
|
||||
end
|
||||
return unless domain && ![server, server.organization].include?(domain.owner)
|
||||
|
||||
errors.add :domain, "does not belong to the server or the server's organization"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم