Many updates
This commit is contained in:
@@ -24,7 +24,7 @@ class WafPoliciesController < ApplicationController
|
||||
|
||||
# Set default values from URL parameters
|
||||
@waf_policy.policy_type = params[:policy_type] if params[:policy_type].present?
|
||||
@waf_policy.action = params[:action] if params[:action].present?
|
||||
@waf_policy.policy_action = params[:policy_action] if params[:policy_action].present?
|
||||
@waf_policy.targets = params[:targets] if params[:targets].present?
|
||||
end
|
||||
|
||||
@@ -37,9 +37,6 @@ class WafPoliciesController < ApplicationController
|
||||
@actions = WafPolicy::ACTIONS
|
||||
|
||||
if @waf_policy.save
|
||||
# Trigger policy processing for existing network ranges
|
||||
ProcessWafPoliciesJob.perform_later(waf_policy_id: @waf_policy.id)
|
||||
|
||||
redirect_to @waf_policy, notice: 'WAF policy was successfully created.'
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
@@ -64,11 +61,6 @@ class WafPoliciesController < ApplicationController
|
||||
@actions = WafPolicy::ACTIONS
|
||||
|
||||
if @waf_policy.update(waf_policy_params)
|
||||
# Re-process policies for existing network ranges if policy was changed
|
||||
if @waf_policy.saved_change_to_targets? || @waf_policy.saved_change_to_action?
|
||||
ProcessWafPoliciesJob.reprocess_for_policy(@waf_policy)
|
||||
end
|
||||
|
||||
redirect_to @waf_policy, notice: 'WAF policy was successfully updated.'
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
@@ -89,9 +81,6 @@ class WafPoliciesController < ApplicationController
|
||||
def activate
|
||||
@waf_policy.activate!
|
||||
|
||||
# Re-process policies for existing network ranges
|
||||
ProcessWafPoliciesJob.reprocess_for_policy(@waf_policy)
|
||||
|
||||
redirect_to @waf_policy, notice: 'WAF policy was activated.'
|
||||
end
|
||||
|
||||
@@ -105,7 +94,7 @@ class WafPoliciesController < ApplicationController
|
||||
# GET /waf_policies/new_country
|
||||
def new_country
|
||||
authorize WafPolicy
|
||||
@waf_policy = WafPolicy.new(policy_type: 'country', action: 'deny')
|
||||
@waf_policy = WafPolicy.new(policy_type: 'country', policy_action: 'deny')
|
||||
@policy_types = WafPolicy::POLICY_TYPES
|
||||
@actions = WafPolicy::ACTIONS
|
||||
end
|
||||
@@ -115,24 +104,28 @@ class WafPoliciesController < ApplicationController
|
||||
authorize WafPolicy
|
||||
|
||||
countries = params[:countries]&.reject(&:blank?) || []
|
||||
action = params[:action] || 'deny'
|
||||
policy_action = params[:policy_action] || 'deny'
|
||||
|
||||
if countries.empty?
|
||||
redirect_to new_country_waf_policies_path, alert: 'Please select at least one country.'
|
||||
return
|
||||
end
|
||||
|
||||
@waf_policy = WafPolicy.create_country_policy(
|
||||
countries,
|
||||
action: action,
|
||||
# Build the options hash with additional_data if present
|
||||
options = {
|
||||
policy_action: policy_action,
|
||||
user: Current.user,
|
||||
description: params[:description]
|
||||
)
|
||||
}
|
||||
|
||||
# Add additional_data if provided (for redirect/challenge actions)
|
||||
if params[:additional_data].present?
|
||||
options[:additional_data] = params[:additional_data].to_unsafe_hash
|
||||
end
|
||||
|
||||
@waf_policy = WafPolicy.create_country_policy(countries, **options)
|
||||
|
||||
if @waf_policy.persisted?
|
||||
# Trigger policy processing for existing network ranges
|
||||
ProcessWafPoliciesJob.reprocess_for_policy(@waf_policy)
|
||||
|
||||
redirect_to @waf_policy, notice: "Country blocking policy was successfully created for #{countries.join(', ')}."
|
||||
else
|
||||
@policy_types = WafPolicy::POLICY_TYPES
|
||||
@@ -144,10 +137,22 @@ class WafPoliciesController < ApplicationController
|
||||
private
|
||||
|
||||
def set_waf_policy
|
||||
@waf_policy = WafPolicy.find(params[:id])
|
||||
authorize @waf_policy
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to waf_policies_path, alert: 'WAF policy not found.'
|
||||
# First try to find by ID (standard Rails behavior)
|
||||
if params[:id] =~ /^\d+$/
|
||||
@waf_policy = WafPolicy.find_by(id: params[:id])
|
||||
end
|
||||
|
||||
# If not found by ID, try to find by parameterized name
|
||||
unless @waf_policy
|
||||
# Try direct parameterized comparison by parameterizing existing policy names
|
||||
@waf_policy = WafPolicy.all.find { |policy| policy.to_param == params[:id] }
|
||||
end
|
||||
|
||||
if @waf_policy
|
||||
authorize @waf_policy
|
||||
else
|
||||
redirect_to waf_policies_path, alert: 'WAF policy not found.'
|
||||
end
|
||||
end
|
||||
|
||||
def waf_policy_params
|
||||
@@ -155,7 +160,7 @@ class WafPoliciesController < ApplicationController
|
||||
:name,
|
||||
:description,
|
||||
:policy_type,
|
||||
:action,
|
||||
:policy_action,
|
||||
:enabled,
|
||||
:expires_at,
|
||||
targets: [],
|
||||
|
||||
Reference in New Issue
Block a user