1class Admin::RateLimitsController < Admin::AdminController
 
2  before_action :require_sysadmin
 
3  before_action :find_rate_limit
 
4
 
5  def edit
 
6    respond_to do |format|
 
7      format.html
 
8    end
 
 9  end
 
 
11  def update
 
12    if @rate_limit.update(rate_limit_params)
 
13      redirect_to edit_admin_rate_limits_url(tab: params[:tab]), notice: :rate_limits_updated
 
14    else
 
15      respond_to do |format|
 
16        format.html { render :edit }
 
17      end
 
18    end
 
19  end
 
 
21  private
 
 
23  def rate_limit_params
 
24    params.require(:rate_limit).permit(*rate_limit_attributes)
 
25  end
 
 
27  def rate_limit_attributes
 
28    %i[
29
 
29      burst_rate burst_period sustained_rate sustained_period
 
30      allowed_domains allowed_ips blocked_domains blocked_ips
 
31      geoblocking_enabled countries country_rate_limits_enabled
 
32      country_burst_rate country_sustained_rate trending_items_notification_url
 
33      threshold_for_logging_trending_items threshold_for_notifying_trending_items
 
34      enable_logging_of_trending_items ignored_domains threshold_for_form_entry
 
35    ]
 
36  end
 
 
38  def find_rate_limit
 
39    @rate_limit = RateLimit.first_or_create!
 
40  end
 
41end