Skip to content

Commit 46a07c2

Browse files
committed
AO3-6544 Add comment_type and user_role to data sent to spam checker for comments and tickets
1 parent ec6c90f commit 46a07c2

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

app/models/abuse_report.rb

+4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ def logged_in_with_matching_email?
2626

2727
def akismet_attributes
2828
name = username ? username : ""
29+
# If the user is logged in and we're sending info to Akismet, we can assume
30+
# the email does not match.
31+
role = User.current_user.present? ? "user-with-nonmatching-email" : "guest"
2932
{
3033
comment_type: "contact-form",
3134
key: ArchiveConfig.AKISMET_KEY,
3235
blog: ArchiveConfig.AKISMET_NAME,
3336
user_ip: ip_address,
37+
user_role: role,
3438
comment_author: name,
3539
comment_author_email: email,
3640
comment_content: comment

app/models/comment.rb

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def akismet_attributes
9898
blog: ArchiveConfig.AKISMET_NAME,
9999
user_ip: ip_address,
100100
user_agent: user_agent,
101+
user_role: "guest",
101102
comment_author: name,
102103
comment_author_email: email,
103104
comment_content: comment_content

app/models/feedback.rb

+5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ def logged_in_with_matching_email?
2323
end
2424

2525
def akismet_attributes
26+
# If the user is logged in and we're sending info to Akismet, we can assume
27+
# the email does not match.
28+
role = User.current_user.present? ? "user-with-nonmatching-email" : "guest"
2629
{
30+
comment_type: "contact-form",
2731
key: ArchiveConfig.AKISMET_KEY,
2832
blog: ArchiveConfig.AKISMET_NAME,
2933
user_ip: ip_address,
3034
user_agent: user_agent,
35+
user_role: role,
3136
comment_author_email: email,
3237
comment_content: comment
3338
}

app/models/work.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ def akismet_attributes
10981098
key: ArchiveConfig.AKISMET_KEY,
10991099
blog: ArchiveConfig.AKISMET_NAME,
11001100
user_ip: ip_address,
1101+
user_role: "user",
11011102
comment_date_gmt: created_at.to_time.iso8601,
11021103
blog_lang: language.short,
11031104
comment_author: user.login,

spec/models/abuse_report_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,23 @@
353353
end
354354
end
355355

356+
context "when report is submitted to Akismet" do
357+
let(:report) { build(:abuse_report) }
358+
359+
it "has comment_type \"contact-form\"" do
360+
expect(report.akismet_attributes[:comment_type]).to eq("contact-form")
361+
end
362+
363+
it "has user_role \"user-with-nonmatching-email\" when reporter is logged in" do
364+
User.current_user = create(:user)
365+
expect(report.akismet_attributes[:user_role]).to eq("user-with-nonmatching-email")
366+
end
367+
368+
it "has user_role \"guest\" when reporter is logged out" do
369+
expect(report.akismet_attributes[:user_role]).to eq("guest")
370+
end
371+
end
372+
356373
describe "#attach_work_download" do
357374
include ActiveJob::TestHelper
358375

spec/models/comment_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
.to raise_error(ActiveRecord::RecordNotFound)
2929
end
3030
end
31+
32+
context "when submitting comment to Akismet" do
33+
subject { build(:comment) }
34+
35+
it "has user_role \"guest\"" do
36+
expect(subject.akismet_attributes[:user_role]).to eq("guest")
37+
end
38+
end
3139
end
3240

3341
context "with an existing comment from the same user" do

spec/models/feedback_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,21 @@
8383
expect(safe_report.save).to be_truthy
8484
end
8585
end
86+
87+
context "when report is submitted to Akismet" do
88+
let(:report) { build(:feedback) }
89+
90+
it "has comment_type \"contact-form\"" do
91+
expect(report.akismet_attributes[:comment_type]).to eq("contact-form")
92+
end
93+
94+
it "has user_role \"user-with-nonmatching-email\" when reporter is logged in" do
95+
User.current_user = create(:user)
96+
expect(report.akismet_attributes[:user_role]).to eq("user-with-nonmatching-email")
97+
end
98+
99+
it "has user_role \"guest\" when reporter is logged out" do
100+
expect(report.akismet_attributes[:user_role]).to eq("guest")
101+
end
102+
end
86103
end

0 commit comments

Comments
 (0)