Commit 3ba168f2 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '206895-spammable-to-target' into 'master'

Rename 'spammable' to 'target'

See merge request gitlab-org/gitlab!25392
parents e463ec38 d1b49397
......@@ -11,7 +11,7 @@ module SpammableActions
end
def mark_as_spam
if Spam::MarkAsSpamService.new(spammable: spammable).execute
if Spam::MarkAsSpamService.new(target: spammable).execute
redirect_to spammable_path, notice: _("%{spammable_titlecase} was submitted to Akismet successfully.") % { spammable_titlecase: spammable.spammable_entity_type.titlecase }
else
redirect_to spammable_path, alert: _('Error with Akismet. Please check the logs for more info.')
......
# frozen_string_literal: true
module AkismetMethods
def spammable_owner
@user ||= User.find(spammable.author_id)
def target_owner
@user ||= User.find(target.author_id)
end
def akismet
@akismet ||= Spam::AkismetService.new(
spammable_owner.name,
spammable_owner.email,
spammable.try(:spammable_text) || spammable&.text,
target_owner.name,
target_owner.email,
target.try(:spammable_text) || target&.text,
options
)
end
......
......@@ -23,6 +23,6 @@ module Spam
end
end
alias_method :spammable, :spam_log
alias_method :target, :spam_log
end
end
......@@ -4,21 +4,21 @@ module Spam
class MarkAsSpamService
include ::AkismetMethods
attr_accessor :spammable, :options
attr_accessor :target, :options
def initialize(spammable:)
@spammable = spammable
def initialize(target:)
@target = target
@options = {}
@options[:ip_address] = @spammable.ip_address
@options[:user_agent] = @spammable.user_agent
@options[:ip_address] = @target.ip_address
@options[:user_agent] = @target.user_agent
end
def execute
return unless spammable.submittable_as_spam?
return unless target.submittable_as_spam?
return unless akismet.submit_spam
spammable.user_agent_detail.update_attribute(:submitted, true)
target.user_agent_detail.update_attribute(:submitted, true)
end
end
end
......@@ -4,11 +4,11 @@ module Spam
class SpamCheckService
include AkismetMethods
attr_accessor :spammable, :request, :options
attr_accessor :target, :request, :options
attr_reader :spam_log
def initialize(spammable:, request:)
@spammable = spammable
@target = spammable
@request = request
@options = {}
......@@ -17,8 +17,8 @@ module Spam
@options[:user_agent] = @request.env['HTTP_USER_AGENT']
@options[:referrer] = @request.env['HTTP_REFERRER']
else
@options[:ip_address] = @spammable.ip_address
@options[:user_agent] = @spammable.user_agent
@options[:ip_address] = @target.ip_address
@options[:user_agent] = @target.user_agent
end
end
......@@ -31,8 +31,8 @@ module Spam
# Otherwise, it goes to Akismet for spam check.
# If so, it assigns spammable object as "spam" and creates a SpamLog record.
possible_spam = check(api)
spammable.spam = possible_spam unless spammable.allow_possible_spam?
spammable.spam_log = spam_log
target.spam = possible_spam unless target.allow_possible_spam?
target.spam_log = spam_log
end
end
......@@ -48,18 +48,18 @@ module Spam
end
def check_for_spam?
spammable.check_for_spam?
target.check_for_spam?
end
def create_spam_log(api)
@spam_log = SpamLog.create!(
{
user_id: spammable.author_id,
title: spammable.spam_title,
description: spammable.spam_description,
user_id: target.author_id,
title: target.spam_title,
description: target.spam_description,
source_ip: options[:ip_address],
user_agent: options[:user_agent],
noteable_type: spammable.class.to_s,
noteable_type: target.class.to_s,
via_api: api
}
)
......
......@@ -740,16 +740,16 @@ describe Projects::IssuesController do
.to log_spam(title: 'Spam title', noteable_type: 'Issue')
end
it 'renders recaptcha_html json response' do
update_issue
expect(json_response).to have_key('recaptcha_html')
end
context 'renders properly' do
render_views
it 'returns 200 status' do
update_issue
it 'renders recaptcha_html json response' do
update_issue
expect(response).to have_gitlab_http_status(:ok)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key('recaptcha_html')
expect(json_response['recaptcha_html']).not_to be_empty
end
end
end
......
......@@ -7,7 +7,7 @@ describe Spam::MarkAsSpamService do
let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) }
let(:fake_akismet_service) { double(:akismet_service, submit_spam: true) }
subject { described_class.new(spammable: spammable) }
subject { described_class.new(target: spammable) }
describe '#execute' do
before do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment