Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b5976140
Commit
b5976140
authored
Jan 29, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move SpamCheckService into spam folder
Part of a general tidy of spam logic
parent
a796a807
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
71 deletions
+73
-71
app/services/concerns/spam_check_methods.rb
app/services/concerns/spam_check_methods.rb
+1
-1
app/services/spam/spam_check_service.rb
app/services/spam/spam_check_service.rb
+68
-0
app/services/spam_check_service.rb
app/services/spam_check_service.rb
+0
-66
spec/requests/api/issues/post_projects_issues_spec.rb
spec/requests/api/issues/post_projects_issues_spec.rb
+1
-1
spec/requests/api/issues/put_projects_issues_spec.rb
spec/requests/api/issues/put_projects_issues_spec.rb
+1
-1
spec/services/issues/create_service_spec.rb
spec/services/issues/create_service_spec.rb
+1
-1
spec/services/spam/spam_check_service_spec.rb
spec/services/spam/spam_check_service_spec.rb
+1
-1
No files found.
app/services/concerns/spam_check_methods.rb
View file @
b5976140
...
...
@@ -23,7 +23,7 @@ module SpamCheckMethods
# attribute values.
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def
spam_check
(
spammable
,
user
)
SpamCheckService
.
new
(
Spam
::
Spam
CheckService
.
new
(
spammable:
spammable
,
request:
@request
).
execute
(
...
...
app/services/spam/spam_check_service.rb
0 → 100644
View file @
b5976140
# frozen_string_literal: true
module
Spam
class
SpamCheckService
include
AkismetMethods
attr_accessor
:spammable
,
:request
,
:options
attr_reader
:spam_log
def
initialize
(
spammable
:,
request
:)
@spammable
=
spammable
@request
=
request
@options
=
{}
if
@request
@options
[
:ip_address
]
=
@request
.
env
[
'action_dispatch.remote_ip'
].
to_s
@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
end
end
def
execute
(
api:
false
,
recaptcha_verified
:,
spam_log_id
:,
user_id
:)
if
recaptcha_verified
# If it's a request which is already verified through recaptcha,
# update the spam log accordingly.
SpamLog
.
verify_recaptcha!
(
user_id:
user_id
,
id:
spam_log_id
)
else
# 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
end
end
private
def
check
(
api
)
return
unless
request
return
unless
check_for_spam?
return
unless
akismet
.
spam?
create_spam_log
(
api
)
true
end
def
check_for_spam?
spammable
.
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
,
source_ip:
options
[
:ip_address
],
user_agent:
options
[
:user_agent
],
noteable_type:
spammable
.
class
.
to_s
,
via_api:
api
}
)
end
end
end
app/services/spam_check_service.rb
deleted
100644 → 0
View file @
a796a807
# frozen_string_literal: true
class
SpamCheckService
include
AkismetMethods
attr_accessor
:spammable
,
:request
,
:options
attr_reader
:spam_log
def
initialize
(
spammable
:,
request
:)
@spammable
=
spammable
@request
=
request
@options
=
{}
if
@request
@options
[
:ip_address
]
=
@request
.
env
[
'action_dispatch.remote_ip'
].
to_s
@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
end
end
def
execute
(
api:
false
,
recaptcha_verified
:,
spam_log_id
:,
user_id
:)
if
recaptcha_verified
# If it's a request which is already verified through recaptcha,
# update the spam log accordingly.
SpamLog
.
verify_recaptcha!
(
user_id:
user_id
,
id:
spam_log_id
)
else
# 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
end
end
private
def
check
(
api
)
return
unless
request
return
unless
check_for_spam?
return
unless
akismet
.
spam?
create_spam_log
(
api
)
true
end
def
check_for_spam?
spammable
.
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
,
source_ip:
options
[
:ip_address
],
user_agent:
options
[
:user_agent
],
noteable_type:
spammable
.
class
.
to_s
,
via_api:
api
}
)
end
end
spec/requests/api/issues/post_projects_issues_spec.rb
View file @
b5976140
...
...
@@ -389,7 +389,7 @@ describe API::Issues do
end
before
do
expect_next_instance_of
(
SpamCheckService
)
do
|
spam_service
|
expect_next_instance_of
(
Spam
::
Spam
CheckService
)
do
|
spam_service
|
expect
(
spam_service
).
to
receive_messages
(
check_for_spam?:
true
)
end
expect_next_instance_of
(
AkismetService
)
do
|
akismet_service
|
...
...
spec/requests/api/issues/put_projects_issues_spec.rb
View file @
b5976140
...
...
@@ -194,7 +194,7 @@ describe API::Issues do
end
before
do
expect_next_instance_of
(
SpamCheckService
)
do
|
spam_service
|
expect_next_instance_of
(
Spam
::
Spam
CheckService
)
do
|
spam_service
|
expect
(
spam_service
).
to
receive_messages
(
check_for_spam?:
true
)
end
expect_next_instance_of
(
AkismetService
)
do
|
akismet_service
|
...
...
spec/services/issues/create_service_spec.rb
View file @
b5976140
...
...
@@ -385,7 +385,7 @@ describe Issues::CreateService do
context
'when recaptcha was not verified'
do
before
do
expect_next_instance_of
(
SpamCheckService
)
do
|
spam_service
|
expect_next_instance_of
(
Spam
::
Spam
CheckService
)
do
|
spam_service
|
expect
(
spam_service
).
to
receive_messages
(
check_for_spam?:
true
)
end
end
...
...
spec/services/spam_check_service_spec.rb
→
spec/services/spam
/spam
_check_service_spec.rb
View file @
b5976140
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
SpamCheckService
do
describe
Spam
::
Spam
CheckService
do
let
(
:fake_ip
)
{
'1.2.3.4'
}
let
(
:fake_user_agent
)
{
'fake-user-agent'
}
let
(
:fake_referrer
)
{
'fake-http-referrer'
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment