1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2026-01-21 07:09:48 +00:00

style(rubocop): fix all safe auto correctable offenses

هذا الالتزام موجود في:
Charlie Smurthwaite
2023-03-16 15:50:53 +00:00
الأصل 02c93a4850
التزام fd289c46fd
204 ملفات معدلة مع 2611 إضافات و2486 حذوفات

عرض الملف

@@ -17,24 +17,24 @@ class IPPoolRule < ApplicationRecord
include HasUUID
belongs_to :owner, :polymorphic => true
belongs_to :owner, polymorphic: true
belongs_to :ip_pool
validate :validate_from_and_to_addresses
validate :validate_ip_pool_belongs_to_organization
def from
from_text ? from_text.gsub(/\r/, '').split(/\n/).map(&:strip) : []
from_text ? from_text.gsub(/\r/, "").split(/\n/).map(&:strip) : []
end
def to
to_text ? to_text.gsub(/\r/, '').split(/\n/).map(&:strip) : []
to_text ? to_text.gsub(/\r/, "").split(/\n/).map(&:strip) : []
end
def apply_to_message?(message)
if from.present? && message.headers['from'].present?
if from.present? && message.headers["from"].present?
from.each do |condition|
if message.headers['from'].any? { |f| self.class.address_matches?(condition, f) }
if message.headers["from"].any? { |f| self.class.address_matches?(condition, f) }
return true
end
end
@@ -54,28 +54,29 @@ class IPPoolRule < ApplicationRecord
private
def validate_from_and_to_addresses
if self.from.empty? && self.to.empty?
errors.add :base, "At least one rule condition must be specified"
end
return unless from.empty? && to.empty?
errors.add :base, "At least one rule condition must be specified"
end
def validate_ip_pool_belongs_to_organization
org = self.owner.is_a?(Organization) ? self.owner : self.owner.organization
if self.ip_pool && self.ip_pool_id_changed? && !org.ip_pools.include?(self.ip_pool)
errors.add :ip_pool_id, "must belong to the organization"
end
org = owner.is_a?(Organization) ? owner : owner.organization
return unless ip_pool && ip_pool_id_changed? && !org.ip_pools.include?(ip_pool)
errors.add :ip_pool_id, "must belong to the organization"
end
def self.address_matches?(condition, address)
address = Postal::Helpers.strip_name_from_address(address)
if condition =~ /@/
parts = address.split('@')
domain, uname = parts.pop, parts.join('@')
uname, _ = uname.split('+', 2)
parts = address.split("@")
domain = parts.pop
uname = parts.join("@")
uname, = uname.split("+", 2)
condition == "#{uname}@#{domain}"
else
# Match as a domain
condition == address.split('@').last
condition == address.split("@").last
end
end