Class: Admin::ScreenedIpAddressesController

Inherits:
StaffController
  • Object
show all
Defined in:
app/controllers/admin/screened_ip_addresses_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
# File 'app/controllers/admin/screened_ip_addresses_controller.rb', line 28

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

#destroyObject



45
46
47
48
# File 'app/controllers/admin/screened_ip_addresses_controller.rb', line 45

def destroy
  @screened_ip_address.destroy
  render json: success_json
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/admin/screened_ip_addresses_controller.rb', line 6

def index
  filter = params[:filter]
  filter = IPAddr.handle_wildcards(filter)

  screened_ip_addresses = ScreenedIpAddress
  screened_ip_addresses =
    screened_ip_addresses.where(
      "cidr :filter >>= ip_address OR ip_address >>= cidr :filter",
      filter: filter,
    ) if filter.present?
  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

#updateObject



37
38
39
40
41
42
43
# File 'app/controllers/admin/screened_ip_addresses_controller.rb', line 37

def update
  if @screened_ip_address.update(allowed_params)
    render_serialized(@screened_ip_address, ScreenedIpAddressSerializer)
  else
    render_json_error(@screened_ip_address)
  end
end