discourse/app/controllers/admin/screened_ip_addresses_contr...

Failed to ignore revisions in .git-blame-ignore-revs.

64 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Admin::ScreenedIpAddressesController < Admin::AdminController
before_action :fetch_screened_ip_address, only: [:update, :destroy]
def index
2015-02-10 13:38:59 -05:00
filter = params[:filter]
filter = IPAddr.handle_wildcards(filter)
screened_ip_addresses = ScreenedIpAddress
screened_ip_addresses = screened_ip_addresses.where("cidr :filter >>= ip_address", filter: filter) if filter.present?
2015-02-10 13:38:59 -05:00
screened_ip_addresses = screened_ip_addresses.limit(200).order('match_count desc')
begin
screened_ip_addresses = screened_ip_addresses.to_a
rescue ActiveRecord::StatementInvalid
# postgresql throws a PG::InvalidTextRepresentation exception when filter isn't a valid cidr expression
screened_ip_addresses = []
end
render_serialized(screened_ip_addresses, ScreenedIpAddressSerializer)
end
def create
screened_ip_address = ScreenedIpAddress.new(allowed_params)
if screened_ip_address.save
render_serialized(screened_ip_address, ScreenedIpAddressSerializer)
else
render_json_error(screened_ip_address)
end
end
def update
if @screened_ip_address.update(allowed_params)
render_serialized(@screened_ip_address, ScreenedIpAddressSerializer)
else
render_json_error(@screened_ip_address)
end
end
def destroy
@screened_ip_address.destroy
render json: success_json
end
def roll_up
subnets = ScreenedIpAddress.roll_up(current_user)
2017-07-27 21:20:09 -04:00
render json: success_json.merge!(subnets: subnets)
end
private
2018-06-07 01:28:18 -04:00
def allowed_params
params.require(:ip_address)
params.permit(:ip_address, :action_name)
end
2018-06-07 01:28:18 -04:00
def fetch_screened_ip_address
@screened_ip_address = ScreenedIpAddress.find(params[:id])
end
end