mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Log IP addresses with screened emails and urls
This commit is contained in:
parent
612c0ccccb
commit
25e0c3eac1
14 changed files with 24 additions and 12 deletions
|
@ -16,7 +16,7 @@ Discourse.StaffActionLog = Discourse.Model.extend({
|
||||||
formattedDetails: function() {
|
formattedDetails: function() {
|
||||||
var formatted = "";
|
var formatted = "";
|
||||||
formatted += this.format('email', 'email');
|
formatted += this.format('email', 'email');
|
||||||
formatted += this.format('admin.logs.staff_actions.ip_address', 'ip_address');
|
formatted += this.format('admin.logs.ip_address', 'ip_address');
|
||||||
if (!this.get('useCustomModalForDetails')) {
|
if (!this.get('useCustomModalForDetails')) {
|
||||||
formatted += this.format('admin.logs.staff_actions.new_value', 'new_value');
|
formatted += this.format('admin.logs.staff_actions.new_value', 'new_value');
|
||||||
formatted += this.format('admin.logs.staff_actions.previous_value', 'previous_value');
|
formatted += this.format('admin.logs.staff_actions.previous_value', 'previous_value');
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<div class="col heading match_count">{{i18n admin.logs.match_count}}</div>
|
<div class="col heading match_count">{{i18n admin.logs.match_count}}</div>
|
||||||
<div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div>
|
<div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div>
|
||||||
<div class="col heading created_at">{{i18n admin.logs.created_at}}</div>
|
<div class="col heading created_at">{{i18n admin.logs.created_at}}</div>
|
||||||
|
<div class="col heading ip_address">{{i18n admin.logs.ip_address}}</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
<div class="col match_count">{{match_count}}</div>
|
<div class="col match_count">{{match_count}}</div>
|
||||||
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
|
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
|
||||||
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
|
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
|
||||||
|
<div class="col ip_address">{{ip_address}}</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
|
@ -12,6 +12,7 @@
|
||||||
<div class="col heading match_count">{{i18n admin.logs.match_count}}</div>
|
<div class="col heading match_count">{{i18n admin.logs.match_count}}</div>
|
||||||
<div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div>
|
<div class="col heading last_match_at">{{i18n admin.logs.last_match_at}}</div>
|
||||||
<div class="col heading created_at">{{i18n admin.logs.created_at}}</div>
|
<div class="col heading created_at">{{i18n admin.logs.created_at}}</div>
|
||||||
|
<div class="col heading ip_address">{{i18n admin.logs.ip_address}}</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
<div class="col match_count">{{match_count}}</div>
|
<div class="col match_count">{{match_count}}</div>
|
||||||
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
|
<div class="col last_match_at">{{unboundAgeWithTooltip last_match_at}}</div>
|
||||||
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
|
<div class="col created_at">{{unboundAgeWithTooltip created_at}}</div>
|
||||||
|
<div class="col ip_address">{{ip_address}}</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
|
@ -703,9 +703,9 @@ table {
|
||||||
.screened-emails, .screened-urls {
|
.screened-emails, .screened-urls {
|
||||||
width: 900px;
|
width: 900px;
|
||||||
.email, .url {
|
.email, .url {
|
||||||
width: 400px;
|
width: 300px;
|
||||||
}
|
}
|
||||||
.action, .match_count, .last_match_at, .created_at {
|
.action, .match_count, .last_match_at, .created_at, .ip_address {
|
||||||
width: 110px;
|
width: 110px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class ScreenedEmail < ActiveRecord::Base
|
||||||
validates :email, presence: true, uniqueness: true
|
validates :email, presence: true, uniqueness: true
|
||||||
|
|
||||||
def self.block(email, opts={})
|
def self.block(email, opts={})
|
||||||
find_by_email(email) || create(opts.slice(:action_type).merge({email: email}))
|
find_by_email(email) || create(opts.slice(:action_type, :ip_address).merge({email: email}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.should_block?(email)
|
def self.should_block?(email)
|
||||||
|
|
|
@ -21,6 +21,6 @@ class ScreenedUrl < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.watch(url, domain, opts={})
|
def self.watch(url, domain, opts={})
|
||||||
find_by_url(url) || create(opts.slice(:action_type).merge(url: url, domain: domain))
|
find_by_url(url) || create(opts.slice(:action_type, :ip_address).merge(url: url, domain: domain))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,8 @@ class ScreenedEmailSerializer < ApplicationSerializer
|
||||||
:action,
|
:action,
|
||||||
:match_count,
|
:match_count,
|
||||||
:last_match_at,
|
:last_match_at,
|
||||||
:created_at
|
:created_at,
|
||||||
|
:ip_address
|
||||||
|
|
||||||
def action
|
def action
|
||||||
ScreenedEmail.actions.key(object.action_type).to_s
|
ScreenedEmail.actions.key(object.action_type).to_s
|
||||||
|
|
|
@ -4,7 +4,8 @@ class ScreenedUrlSerializer < ApplicationSerializer
|
||||||
:action,
|
:action,
|
||||||
:match_count,
|
:match_count,
|
||||||
:last_match_at,
|
:last_match_at,
|
||||||
:created_at
|
:created_at,
|
||||||
|
:ip_address
|
||||||
|
|
||||||
def action
|
def action
|
||||||
ScreenedUrl.actions.key(object.action_type).to_s
|
ScreenedUrl.actions.key(object.action_type).to_s
|
||||||
|
|
|
@ -1183,6 +1183,7 @@ en:
|
||||||
created_at: "Created"
|
created_at: "Created"
|
||||||
last_match_at: "Last Matched"
|
last_match_at: "Last Matched"
|
||||||
match_count: "Matches"
|
match_count: "Matches"
|
||||||
|
ip_address: "IP"
|
||||||
screened_actions:
|
screened_actions:
|
||||||
block: "block"
|
block: "block"
|
||||||
do_nothing: "do nothing"
|
do_nothing: "do nothing"
|
||||||
|
@ -1196,7 +1197,6 @@ en:
|
||||||
when: "When"
|
when: "When"
|
||||||
context: "Context"
|
context: "Context"
|
||||||
details: "Details"
|
details: "Details"
|
||||||
ip_address: "IP"
|
|
||||||
previous_value: "Previous"
|
previous_value: "Previous"
|
||||||
new_value: "New"
|
new_value: "New"
|
||||||
diff: "Diff"
|
diff: "Diff"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddIpAddressToScreeningTables < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :screened_emails, :ip_address, :inet
|
||||||
|
add_column :screened_urls, :ip_address, :inet
|
||||||
|
end
|
||||||
|
end
|
|
@ -20,7 +20,7 @@ class UserDestroyer
|
||||||
if opts[:block_urls]
|
if opts[:block_urls]
|
||||||
post.topic_links.each do |link|
|
post.topic_links.each do |link|
|
||||||
unless link.internal or Oneboxer.oneboxer_exists_for_url?(link.url)
|
unless link.internal or Oneboxer.oneboxer_exists_for_url?(link.url)
|
||||||
ScreenedUrl.watch(link.url, link.domain).try(:record_match!)
|
ScreenedUrl.watch(link.url, link.domain, ip_address: user.ip_address).try(:record_match!)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ class UserDestroyer
|
||||||
user.destroy.tap do |u|
|
user.destroy.tap do |u|
|
||||||
if u
|
if u
|
||||||
if opts[:block_email]
|
if opts[:block_email]
|
||||||
b = ScreenedEmail.block(u.email)
|
b = ScreenedEmail.block(u.email, ip_address: u.ip_address)
|
||||||
b.record_match! if b
|
b.record_match! if b
|
||||||
end
|
end
|
||||||
Post.with_deleted.where(user_id: user.id).update_all("nuked_user = true")
|
Post.with_deleted.where(user_id: user.id).update_all("nuked_user = true")
|
||||||
|
|
|
@ -80,7 +80,7 @@ describe UserDestroyer do
|
||||||
|
|
||||||
it "adds email to block list if block_email is true" do
|
it "adds email to block list if block_email is true" do
|
||||||
b = Fabricate.build(:screened_email, email: @user.email)
|
b = Fabricate.build(:screened_email, email: @user.email)
|
||||||
ScreenedEmail.expects(:block).with(@user.email).returns(b)
|
ScreenedEmail.expects(:block).with(@user.email, has_key(:ip_address)).returns(b)
|
||||||
b.expects(:record_match!).once.returns(true)
|
b.expects(:record_match!).once.returns(true)
|
||||||
UserDestroyer.new(@admin).destroy(@user, destroy_opts.merge({block_email: true}))
|
UserDestroyer.new(@admin).destroy(@user, destroy_opts.merge({block_email: true}))
|
||||||
end
|
end
|
||||||
|
@ -178,7 +178,7 @@ describe UserDestroyer do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds ScreenedUrl records when :block_urls is true" do
|
it "adds ScreenedUrl records when :block_urls is true" do
|
||||||
ScreenedUrl.expects(:watch).at_least_once
|
ScreenedUrl.expects(:watch).with(anything, anything, has_key(:ip_address)).at_least_once
|
||||||
UserDestroyer.new(@admin).destroy(@user, {delete_posts: true, block_urls: true})
|
UserDestroyer.new(@admin).destroy(@user, {delete_posts: true, block_urls: true})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue