Skip to content

Commit

Permalink
FIX: Send blog attribute to Akismet to improve accuracy and false pos…
Browse files Browse the repository at this point in the history
…itives detection
  • Loading branch information
romanrizzi committed Aug 21, 2020
1 parent e41f371 commit 63690f8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/discourse_akismet/posts_bouncer.rb
Expand Up @@ -67,6 +67,7 @@ def self.reset_munge

def args_for(post)
extra_args = {
blog: Discourse.base_url,
content_type: 'forum-post',
referrer: post.custom_fields['AKISMET_REFERRER'],
permalink: "#{Discourse.base_url}#{post.url}",
Expand Down
45 changes: 23 additions & 22 deletions lib/discourse_akismet/users_bouncer.rb
Expand Up @@ -21,6 +21,29 @@ def suspect?(user)
user.user_auth_token_logs&.last&.client_ip.present?
end

def args_for(user)
profile = user.user_profile
token = user.user_auth_token_logs.last

extra_args = {
blog: Discourse.base_url,
content_type: 'signup',
permalink: "#{Discourse.base_url}/u/#{user.username_lower}",
comment_author: user.username,
comment_content: profile.bio_raw,
comment_author_url: profile.website,
user_ip: token.client_ip.to_s,
user_agent: token.user_agent
}

# Sending the email to akismet is optional
if SiteSetting.akismet_transmit_email?
extra_args[:comment_author_email] = user.email
end

extra_args
end

private

def enqueue_job(user)
Expand Down Expand Up @@ -51,27 +74,5 @@ def mark_as_errored(user, reason)
)
end
end

def args_for(user)
profile = user.user_profile
token = user.user_auth_token_logs.last

extra_args = {
content_type: 'signup',
permalink: "#{Discourse.base_url}/u/#{user.username_lower}",
comment_author: user.username,
comment_content: profile.bio_raw,
comment_author_url: profile.website,
user_ip: token.client_ip.to_s,
user_agent: token.user_agent
}

# Sending the email to akismet is optional
if SiteSetting.akismet_transmit_email?
extra_args[:comment_author_email] = user.email
end

extra_args
end
end
end
1 change: 1 addition & 0 deletions spec/lib/posts_bouncer_spec.rb
Expand Up @@ -30,6 +30,7 @@
expect(result[:user_agent]).to eq('Discourse Agent')
expect(result[:comment_author]).to eq(post.user.username)
expect(result[:comment_author_email]).to eq(post.user.email)
expect(result[:blog]).to eq(Discourse.base_url)
end

it "will omit email if the site setting is enabled" do
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/users_bouncer_spec.rb
Expand Up @@ -17,6 +17,23 @@
SiteSetting.akismet_api_key = 'fake_key'
end

describe '#args_for' do
it "returns args for a user" do
profile = user.user_profile
token = user.user_auth_token_logs.last

result = subject.args_for(user)
expect(result[:content_type]).to eq('signup')
expect(result[:permalink]).to eq("#{Discourse.base_url}/u/#{user.username_lower}")
expect(result[:comment_author]).to eq(user.username)
expect(result[:comment_content]).to eq(profile.bio_raw)
expect(result[:comment_author_url]).to eq(profile.website)
expect(result[:user_ip]).to eq(token.client_ip.to_s)
expect(result[:user_agent]).to eq(token.user_agent)
expect(result[:blog]).to eq(Discourse.base_url)
end
end

describe "#should_check?" do

it "returns false when setting is disabled" do
Expand Down

0 comments on commit 63690f8

Please sign in to comment.