Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6544 Send comment_type and user_role to spam checker for tickets and comments #5084

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/abuse_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def logged_in_with_matching_email?

def akismet_attributes
name = username ? username : ""
# If the user is logged in and we're sending info to Akismet, we can assume
# the email does not match.
role = User.current_user.present? ? "user-with-nonmatching-email" : "guest"
{
comment_type: "contact-form",
key: ArchiveConfig.AKISMET_KEY,
blog: ArchiveConfig.AKISMET_NAME,
user_ip: ip_address,
user_role: role,
comment_author: name,
comment_author_email: email,
comment_content: comment
Expand Down
1 change: 1 addition & 0 deletions app/models/comment.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to set comment_type on comments, or is comment assumed by Akismet to be the default?

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def akismet_attributes
blog: ArchiveConfig.AKISMET_NAME,
user_ip: ip_address,
user_agent: user_agent,
user_role: "guest",
comment_author: name,
comment_author_email: email,
comment_content: comment_content
Expand Down
5 changes: 5 additions & 0 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ def logged_in_with_matching_email?
end

def akismet_attributes
# If the user is logged in and we're sending info to Akismet, we can assume
# the email does not match.
role = User.current_user.present? ? "user-with-nonmatching-email" : "guest"
{
comment_type: "contact-form",
key: ArchiveConfig.AKISMET_KEY,
blog: ArchiveConfig.AKISMET_NAME,
user_ip: ip_address,
user_agent: user_agent,
user_role: role,
comment_author_email: email,
comment_content: comment
}
Expand Down
1 change: 1 addition & 0 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ def akismet_attributes
key: ArchiveConfig.AKISMET_KEY,
blog: ArchiveConfig.AKISMET_NAME,
user_ip: ip_address,
user_role: "user",
comment_date_gmt: created_at.to_time.iso8601,
blog_lang: language.short,
comment_author: user.login,
Expand Down
17 changes: 17 additions & 0 deletions spec/models/abuse_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@
end
end

context "when report is submitted to Akismet" do
let(:report) { build(:abuse_report) }

it "has comment_type \"contact-form\"" do
expect(report.akismet_attributes[:comment_type]).to eq("contact-form")
end

it "has user_role \"user-with-nonmatching-email\" when reporter is logged in" do
User.current_user = create(:user)
expect(report.akismet_attributes[:user_role]).to eq("user-with-nonmatching-email")
end

it "has user_role \"guest\" when reporter is logged out" do
expect(report.akismet_attributes[:user_role]).to eq("guest")
end
end

describe "#attach_work_download" do
include ActiveJob::TestHelper

Expand Down
8 changes: 8 additions & 0 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
.to raise_error(ActiveRecord::RecordNotFound)
end
end

context "when submitting comment to Akismet" do
subject { build(:comment) }

it "has user_role \"guest\"" do
expect(subject.akismet_attributes[:user_role]).to eq("guest")
end
end
end

context "with an existing comment from the same user" do
Expand Down
17 changes: 17 additions & 0 deletions spec/models/feedback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,21 @@
expect(safe_report.save).to be_truthy
end
end

context "when report is submitted to Akismet" do
let(:report) { build(:feedback) }

it "has comment_type \"contact-form\"" do
expect(report.akismet_attributes[:comment_type]).to eq("contact-form")
end

it "has user_role \"user-with-nonmatching-email\" when reporter is logged in" do
User.current_user = create(:user)
expect(report.akismet_attributes[:user_role]).to eq("user-with-nonmatching-email")
end

it "has user_role \"guest\" when reporter is logged out" do
expect(report.akismet_attributes[:user_role]).to eq("guest")
end
end
end
Loading