مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
feat: add priorities to IP address assignment
هذا الالتزام موجود في:
@@ -33,7 +33,7 @@ class IPAddressesController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def safe_params
|
def safe_params
|
||||||
params.require(:ip_address).permit(:ipv4, :ipv6, :hostname)
|
params.require(:ip_address).permit(:ipv4, :ipv6, :hostname, :priority)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# hostname :string(255)
|
# hostname :string(255)
|
||||||
|
# priority :integer
|
||||||
#
|
#
|
||||||
|
|
||||||
class IPAddress < ApplicationRecord
|
class IPAddress < ApplicationRecord
|
||||||
@@ -18,5 +19,26 @@ class IPAddress < ApplicationRecord
|
|||||||
validates :ipv4, :presence => true, :uniqueness => true
|
validates :ipv4, :presence => true, :uniqueness => true
|
||||||
validates :hostname, :presence => true
|
validates :hostname, :presence => true
|
||||||
validates :ipv6, :uniqueness => {:allow_blank => true}
|
validates :ipv6, :uniqueness => {:allow_blank => true}
|
||||||
|
validates :priority, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 100, only_integer: true }
|
||||||
|
|
||||||
|
scope :order_by_priority, -> { order(priority: :desc) }
|
||||||
|
|
||||||
|
before_validation :set_default_priority
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_default_priority
|
||||||
|
return if priority.present?
|
||||||
|
|
||||||
|
self.priority = 100
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self
|
||||||
|
|
||||||
|
def select_by_priority
|
||||||
|
order(Arel.sql("RAND() * priority DESC")).first
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class QueuedMessage < ApplicationRecord
|
|||||||
|
|
||||||
def allocate_ip_address
|
def allocate_ip_address
|
||||||
if Postal.ip_pools? && self.message && pool = self.server.ip_pool_for_message(self.message)
|
if Postal.ip_pools? && self.message && pool = self.server.ip_pool_for_message(self.message)
|
||||||
self.ip_address = pool.ip_addresses.order("RAND()").first
|
self.ip_address = pool.ip_addresses.select_by_priority
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,19 @@
|
|||||||
.fieldSet__field
|
.fieldSet__field
|
||||||
= f.label :hostname, :class => 'fieldSet__label'
|
= f.label :hostname, :class => 'fieldSet__label'
|
||||||
.fieldSet__input= f.text_field :hostname, :class => 'input input--text'
|
.fieldSet__input= f.text_field :hostname, :class => 'input input--text'
|
||||||
|
.fieldSet__field
|
||||||
|
= f.label :priority, :class => 'fieldSet__label'
|
||||||
|
.fieldSet__input
|
||||||
|
= f.text_field :priority, :class => 'input input--text', placeholder: '100'
|
||||||
|
%p.fieldSet__text
|
||||||
|
This priority will determine the likelihood of this IP address being selected
|
||||||
|
for use when sending a message. The higher the number the more likely the IP
|
||||||
|
is to be chosen. By defalt, the priority is set to the maximum value of 100.
|
||||||
|
This can be used to warm up new IP addresses by adding them with a low priority.
|
||||||
|
To give an indication of how this works, if you have three IPs with 1, 50 and 100
|
||||||
|
as their priorities, and you send 100,000 emails, the priority 1 address will receive
|
||||||
|
a tiny percentage, the priority 50 will receive roughly 25% and the priority 100 will
|
||||||
|
receive roughly 75%.
|
||||||
|
|
||||||
.fieldSetSubmit.buttonSet
|
.fieldSetSubmit.buttonSet
|
||||||
= f.submit :class => 'button button--positive js-form-submit'
|
= f.submit :class => 'button button--positive js-form-submit'
|
||||||
|
|||||||
@@ -12,16 +12,19 @@
|
|||||||
%td IPv4
|
%td IPv4
|
||||||
%td IPv6
|
%td IPv6
|
||||||
%td Hostname
|
%td Hostname
|
||||||
|
%td Priority
|
||||||
%tbody
|
%tbody
|
||||||
- if @ip_pool.ip_addresses.empty?
|
- ips = @ip_pool.ip_addresses.order_by_priority
|
||||||
|
- if ips.empty?
|
||||||
%tr
|
%tr
|
||||||
%td.dataTable__empty{:colspan => 3} There are no IP addresses assigned to this pool yet.
|
%td.dataTable__empty{:colspan => 3} There are no IP addresses assigned to this pool yet.
|
||||||
- else
|
- else
|
||||||
- for ip in @ip_pool.ip_addresses
|
- for ip in ips
|
||||||
%tr
|
%tr
|
||||||
%td{:width => "20%"}= link_to ip.ipv4, [:edit, @ip_pool, ip], :class => "u-link"
|
%td{:width => "20%"}= link_to ip.ipv4, [:edit, @ip_pool, ip], :class => "u-link"
|
||||||
%td{:width => "40%"}= ip.ipv6
|
%td{:width => "35%"}= ip.ipv6
|
||||||
%td{:width => "40%"}= ip.hostname
|
%td{:width => "35%"}= ip.hostname
|
||||||
|
%td{:width => "10%"}= ip.priority
|
||||||
%p= link_to "Add an IP address to pool", [:new, @ip_pool, :ip_address], :class => "u-link"
|
%p= link_to "Add an IP address to pool", [:new, @ip_pool, :ip_address], :class => "u-link"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class AddPriorityToIPAddresses < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :ip_addresses, :priority, :integer
|
||||||
|
IPAddress.where(priority: nil).update_all(priority: 100)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_07_17_083943) do
|
ActiveRecord::Schema.define(version: 2021_07_27_210551) do
|
||||||
|
|
||||||
create_table "additional_route_endpoints", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
create_table "additional_route_endpoints", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||||
t.integer "route_id"
|
t.integer "route_id"
|
||||||
@@ -124,6 +124,7 @@ ActiveRecord::Schema.define(version: 2020_07_17_083943) do
|
|||||||
t.datetime "created_at", precision: 6
|
t.datetime "created_at", precision: 6
|
||||||
t.datetime "updated_at", precision: 6
|
t.datetime "updated_at", precision: 6
|
||||||
t.string "hostname"
|
t.string "hostname"
|
||||||
|
t.integer "priority"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "ip_pool_rules", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
create_table "ip_pool_rules", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم