mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: log a new staff action when rolling up banned IP addresses
This commit is contained in:
parent
a609e1b655
commit
7b0ae702e7
4 changed files with 25 additions and 11 deletions
|
@ -45,11 +45,14 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController
|
|||
action_type: ScreenedIpAddress.actions[:block],
|
||||
min_count: SiteSetting.min_ban_entries_for_roll_up).values.flatten
|
||||
|
||||
# 2 - log the call
|
||||
StaffActionLogger.new(current_user).log_roll_up(subnets) unless subnets.blank?
|
||||
|
||||
subnets.each do |subnet|
|
||||
# 2 - create subnet if not already exists
|
||||
# 3 - create subnet if not already exists
|
||||
ScreenedIpAddress.new(ip_address: subnet).save unless ScreenedIpAddress.where(ip_address: subnet).first
|
||||
|
||||
# 3 - update stats
|
||||
# 4 - update stats
|
||||
sql = <<-SQL
|
||||
UPDATE screened_ip_addresses
|
||||
SET match_count = sum_match_count,
|
||||
|
@ -70,7 +73,7 @@ class Admin::ScreenedIpAddressesController < Admin::AdminController
|
|||
|
||||
ScreenedIpAddress.exec_sql(sql, action_type: ScreenedIpAddress.actions[:block], ip_address: subnet)
|
||||
|
||||
# 4 - remove old matches
|
||||
# 5 - remove old matches
|
||||
ScreenedIpAddress.where(action_type: ScreenedIpAddress.actions[:block])
|
||||
.where("family(ip_address) = 4")
|
||||
.where("masklen(ip_address) = 32")
|
||||
|
|
|
@ -33,7 +33,8 @@ class UserHistory < ActiveRecord::Base
|
|||
:check_email,
|
||||
:delete_post,
|
||||
:delete_topic,
|
||||
:impersonate)
|
||||
:impersonate,
|
||||
:roll_up)
|
||||
end
|
||||
|
||||
# Staff actions is a subset of all actions, used to audit actions taken by staff users.
|
||||
|
@ -50,7 +51,8 @@ class UserHistory < ActiveRecord::Base
|
|||
:check_email,
|
||||
:delete_post,
|
||||
:delete_topic,
|
||||
:impersonate]
|
||||
:impersonate,
|
||||
:roll_up]
|
||||
end
|
||||
|
||||
def self.staff_action_ids
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Responsible for logging the actions of admins and moderators.
|
||||
class StaffActionLogger
|
||||
|
||||
def initialize(admin)
|
||||
@admin = admin
|
||||
raise Discourse::InvalidParameters.new('admin is nil') unless @admin && @admin.is_a?(User)
|
||||
|
@ -164,10 +165,17 @@ class StaffActionLogger
|
|||
}))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params(opts)
|
||||
{ acting_user_id: @admin.id, context: opts[:context] }
|
||||
def log_roll_up(subnets)
|
||||
UserHistory.create(params(opts).merge({
|
||||
action: UserHistory.action[:roll_up],
|
||||
details: subnets.join(", ")
|
||||
}))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params(opts)
|
||||
{ acting_user_id: @admin.id, context: opts[:context] }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,8 +21,6 @@ describe Admin::ScreenedIpAddressesController do
|
|||
describe 'roll_up' do
|
||||
|
||||
it "works" do
|
||||
SiteSetting.expects(:min_ban_entries_for_roll_up).returns(3)
|
||||
|
||||
Fabricate(:screened_ip_address, ip_address: "1.2.3.4", match_count: 1)
|
||||
Fabricate(:screened_ip_address, ip_address: "1.2.3.5", match_count: 1)
|
||||
Fabricate(:screened_ip_address, ip_address: "1.2.3.6", match_count: 1)
|
||||
|
@ -30,6 +28,9 @@ describe Admin::ScreenedIpAddressesController do
|
|||
Fabricate(:screened_ip_address, ip_address: "42.42.42.4", match_count: 1)
|
||||
Fabricate(:screened_ip_address, ip_address: "42.42.42.5", match_count: 1)
|
||||
|
||||
StaffActionLogger.any_instance.expects(:log_roll_up)
|
||||
SiteSetting.expects(:min_ban_entries_for_roll_up).returns(3)
|
||||
|
||||
xhr :post, :roll_up
|
||||
response.should be_success
|
||||
|
||||
|
|
Loading…
Reference in a new issue