1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-11-30 21:32:30 +00:00

admin UI for managing ip pools & ip addresses

هذا الالتزام موجود في:
Adam Cooke
2017-04-21 11:09:31 +01:00
الأصل 6eb425eaed
التزام c09c501ef4
11 ملفات معدلة مع 232 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,39 @@
class IPAddressesController < ApplicationController
before_action :admin_required
before_action { @ip_pool = IPPool.find_by_uuid!(params[:ip_pool_id]) }
before_action { params[:id] && @ip_address = @ip_pool.ip_addresses.find(params[:id]) }
def new
@ip_address = @ip_pool.ip_addresses.build
end
def create
@ip_address = @ip_pool.ip_addresses.build(safe_params)
if @ip_address.save
redirect_to_with_json [:edit, @ip_pool]
else
render_form_errors 'new', @ip_address
end
end
def update
if @ip_address.update(safe_params)
redirect_to_with_json [:edit, @ip_pool]
else
render_form_errors 'edit', @ip_address
end
end
def destroy
@ip_address.destroy
redirect_to_with_json [:edit, @ip_pool]
end
private
def safe_params
params.require(:ip_address).permit(:ipv4, :ipv6, :hostname)
end
end

عرض الملف

@@ -0,0 +1,44 @@
class IPPoolsController < ApplicationController
before_action :admin_required
before_action { params[:id] && @ip_pool = IPPool.find_by_uuid!(params[:id]) }
def index
@ip_pools = IPPool.order(:name).to_a
end
def new
@ip_pool = IPPool.new
end
def create
@ip_pool = IPPool.new(safe_params)
if @ip_pool.save
redirect_to_with_json [:edit, @ip_pool], :notice => "IP Pool has been added successfully. You can now add IP addresses to it."
else
render_form_errors 'new', @ip_pool
end
end
def update
if @ip_pool.update(safe_params)
redirect_to_with_json [:edit, @ip_pool], :notice => "IP Pool has been updated."
else
render_form_errors 'edit', @ip_pool
end
end
def destroy
@ip_pool.destroy
redirect_to_with_json :ip_pools, :notice => "IP pool has been removed successfully."
rescue ActiveRecord::DeleteRestrictionError => e
redirect_to_with_json [:edit, @ip_pool], :alert => "IP pool cannot be removed because it is still assigned to servers/rules."
end
private
def safe_params
params.require(:ip_pool).permit(:name, :type, :default)
end
end