مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2026-01-17 05:33:35 +00:00
style(rubocop): fix all safe auto correctable offenses
هذا الالتزام موجود في:
@@ -13,22 +13,21 @@
|
||||
class AdditionalRouteEndpoint < ApplicationRecord
|
||||
|
||||
belongs_to :route
|
||||
belongs_to :endpoint, :polymorphic => true
|
||||
belongs_to :endpoint, polymorphic: true
|
||||
|
||||
validate :validate_endpoint_belongs_to_server
|
||||
validate :validate_wildcard
|
||||
validate :validate_uniqueness
|
||||
|
||||
def self.find_by_endpoint(endpoint)
|
||||
class_name, id = endpoint.split('#', 2)
|
||||
class_name, id = endpoint.split("#", 2)
|
||||
unless Route::ENDPOINT_TYPES.include?(class_name)
|
||||
raise Postal::Error, "Invalid endpoint class name '#{class_name}'"
|
||||
end
|
||||
if uuid = class_name.constantize.find_by_uuid(id)
|
||||
where(:endpoint_type => class_name, :endpoint_id => uuid).first
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
return unless uuid = class_name.constantize.find_by_uuid(id)
|
||||
|
||||
where(endpoint_type: class_name, endpoint_id: uuid).first
|
||||
end
|
||||
|
||||
def _endpoint
|
||||
@@ -38,39 +37,37 @@ class AdditionalRouteEndpoint < ApplicationRecord
|
||||
def _endpoint=(value)
|
||||
if value.blank?
|
||||
self.endpoint = nil
|
||||
else
|
||||
if value =~ /\#/
|
||||
class_name, id = value.split('#', 2)
|
||||
unless Route::ENDPOINT_TYPES.include?(class_name)
|
||||
raise Postal::Error, "Invalid endpoint class name '#{class_name}'"
|
||||
end
|
||||
self.endpoint = class_name.constantize.find_by_uuid(id)
|
||||
else
|
||||
self.endpoint = nil
|
||||
elsif value =~ /\#/
|
||||
class_name, id = value.split("#", 2)
|
||||
unless Route::ENDPOINT_TYPES.include?(class_name)
|
||||
raise Postal::Error, "Invalid endpoint class name '#{class_name}'"
|
||||
end
|
||||
|
||||
self.endpoint = class_name.constantize.find_by_uuid(id)
|
||||
else
|
||||
self.endpoint = nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_endpoint_belongs_to_server
|
||||
if self.endpoint && self.endpoint&.server != self.route.server
|
||||
errors.add :endpoint, :invalid
|
||||
end
|
||||
return unless endpoint && endpoint&.server != route.server
|
||||
|
||||
errors.add :endpoint, :invalid
|
||||
end
|
||||
|
||||
def validate_uniqueness
|
||||
if self.endpoint == self.route.endpoint
|
||||
errors.add :base, "You can only add an endpoint to a route once"
|
||||
end
|
||||
return unless endpoint == route.endpoint
|
||||
|
||||
errors.add :base, "You can only add an endpoint to a route once"
|
||||
end
|
||||
|
||||
def validate_wildcard
|
||||
if self.route.wildcard?
|
||||
if self.endpoint_type == 'SMTPEndpoint' || self.endpoint_type == 'AddressEndpoint'
|
||||
errors.add :base, "SMTP or address endpoints are not permitted on wildcard routes"
|
||||
end
|
||||
end
|
||||
return unless route.wildcard?
|
||||
return unless endpoint_type == "SMTPEndpoint" || endpoint_type == "AddressEndpoint"
|
||||
|
||||
errors.add :base, "SMTP or address endpoints are not permitted on wildcard routes"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم