Commit 1c9105e2 authored by charlieablett's avatar charlieablett

Add allowlisted method to SpamActionService

parent 2114a94f
...@@ -28,6 +28,7 @@ module Spam ...@@ -28,6 +28,7 @@ module Spam
# update the spam log accordingly. # update the spam log accordingly.
SpamLog.verify_recaptcha!(user_id: user.id, id: spam_log_id) SpamLog.verify_recaptcha!(user_id: user.id, id: spam_log_id)
else else
return if allowlisted?(user)
return unless request return unless request
return unless check_for_spam? return unless check_for_spam?
...@@ -39,6 +40,10 @@ module Spam ...@@ -39,6 +40,10 @@ module Spam
private private
def allowlisted?(user)
user.respond_to?(:gitlab_employee) && user.gitlab_employee?
end
def perform_spam_service_check(api) def perform_spam_service_check(api)
# since we can check for spam, and recaptcha is not verified, # since we can check for spam, and recaptcha is not verified,
# ask the SpamVerdictService what to do with the target. # ask the SpamVerdictService what to do with the target.
......
---
title: Skip spam check for GitLab team members on gitlab.com
merge_request: 31052
author:
type: added
...@@ -73,11 +73,13 @@ describe Spam::SpamActionService do ...@@ -73,11 +73,13 @@ describe Spam::SpamActionService do
describe '#execute' do describe '#execute' do
let(:request) { double(:request, env: env) } let(:request) { double(:request, env: env) }
let(:fake_verdict_service) { double(:spam_verdict_service) } let(:fake_verdict_service) { double(:spam_verdict_service) }
let(:allowlisted) { false }
let_it_be(:existing_spam_log) { create(:spam_log, user: user, recaptcha_verified: false) } let_it_be(:existing_spam_log) { create(:spam_log, user: user, recaptcha_verified: false) }
subject do subject do
described_service = described_class.new(spammable: issue, request: request) described_service = described_class.new(spammable: issue, request: request)
allow(described_service).to receive(:allowlisted?).and_return(allowlisted)
described_service.execute(user: user, api: nil, recaptcha_verified: recaptcha_verified, spam_log_id: existing_spam_log.id) described_service.execute(user: user, api: nil, recaptcha_verified: recaptcha_verified, spam_log_id: existing_spam_log.id)
end end
...@@ -121,6 +123,16 @@ describe Spam::SpamActionService do ...@@ -121,6 +123,16 @@ describe Spam::SpamActionService do
issue.description = 'SPAM!' issue.description = 'SPAM!'
end end
context 'if allowlisted' do
let(:allowlisted) { true }
it 'does not perform spam check' do
expect(Spam::SpamVerdictService).not_to receive(:new)
subject
end
end
context 'when disallowed by the spam verdict service' do context 'when disallowed by the spam verdict service' do
before do before do
allow(fake_verdict_service).to receive(:execute).and_return(DISALLOW) allow(fake_verdict_service).to receive(:execute).and_return(DISALLOW)
......
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