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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
8f04cf0e
Commit
8f04cf0e
authored
Jul 20, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `SpamCheckService` to make it cleaner and clearer.
parent
f7807c5b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
39 deletions
+38
-39
CHANGELOG
CHANGELOG
+0
-1
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-7
app/services/issues/create_service.rb
app/services/issues/create_service.rb
+3
-2
app/services/issues/spam_check_service.rb
app/services/issues/spam_check_service.rb
+0
-25
app/services/spam_check_service.rb
app/services/spam_check_service.rb
+28
-0
lib/api/issues.rb
lib/api/issues.rb
+6
-4
No files found.
CHANGELOG
View file @
8f04cf0e
...
...
@@ -93,7 +93,6 @@ v 8.10.0
- Fix viewing notification settings when a project is pending deletion
- Updated compare dropdown menus to use GL dropdown
- Redirects back to issue after clicking login link
- Submit issues created via the WebUI by non project members to Akismet !5333
- All created issues, API or WebUI, can be submitted to Akismet for spam check !5333
- Eager load award emoji on notes
- Allow to define manual actions/builds on Pipelines and Environments
...
...
app/controllers/projects/issues_controller.rb
View file @
8f04cf0e
...
...
@@ -81,15 +81,9 @@ class Projects::IssuesController < Projects::ApplicationController
def
create
@issue
=
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
.
merge
({
request:
request
})).
execute
if
@issue
.
nil?
@issue
=
@project
.
issues
.
new
flash
[
:notice
]
=
'Your issue has been recognized as spam and has been discarded.'
render
:new
and
return
end
respond_to
do
|
format
|
format
.
html
do
if
@issue
.
valid?
if
@issue
.
errors
.
empty?
&&
@issue
.
valid?
redirect_to
issue_path
(
@issue
)
else
render
:new
...
...
app/services/issues/create_service.rb
View file @
8f04cf0e
...
...
@@ -6,8 +6,9 @@ module Issues
issue
=
project
.
issues
.
new
(
params
.
except
(
:label_ids
,
:request
))
issue
.
author
=
params
[
:author
]
||
current_user
if
Issues
::
SpamCheckService
.
new
(
project
,
current_user
,
params
).
spam_detected?
return
nil
if
SpamCheckService
.
new
(
project
,
current_user
,
params
).
spam_detected?
issue
.
errors
.
add
(
:base
,
'Your issue has been recognized as spam and has been discarded.'
)
return
issue
end
if
issue
.
save
...
...
app/services/issues/spam_check_service.rb
deleted
100644 → 0
View file @
f7807c5b
module
Issues
class
SpamCheckService
<
BaseService
include
Gitlab
::
AkismetHelper
def
spam_detected?
text
=
[
params
[
:title
],
params
[
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
request
=
params
[
:request
]
if
request
if
check_for_spam?
(
project
)
&&
is_spam?
(
request
.
env
,
current_user
,
text
)
attrs
=
{
user_id:
current_user
.
id
,
project_id:
project
.
id
,
title:
params
[
:title
],
description:
params
[
:description
]
}
create_spam_log
(
project
,
current_user
,
attrs
,
request
.
env
,
api:
false
)
return
true
end
end
false
end
end
end
app/services/spam_check_service.rb
0 → 100644
View file @
8f04cf0e
class
SpamCheckService
include
Gitlab
::
AkismetHelper
attr_accessor
:subject
,
:current_user
,
:params
def
initialize
(
subject
,
user
,
params
=
{})
@subject
,
@current_user
,
@params
=
subject
,
user
,
params
.
dup
end
def
spam_detected?
request
=
params
[
:request
]
return
false
unless
request
||
check_for_spam?
(
subject
)
text
=
[
params
[
:title
],
params
[
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
return
false
unless
is_spam?
(
request
.
env
,
current_user
,
text
)
attrs
=
{
user_id:
current_user
.
id
,
project_id:
subject
.
id
,
title:
params
[
:title
],
description:
params
[
:description
]
}
create_spam_log
(
subject
,
current_user
,
attrs
,
request
.
env
,
api:
false
)
true
end
end
lib/api/issues.rb
View file @
8f04cf0e
...
...
@@ -160,11 +160,13 @@ module API
issue
=
::
Issues
::
CreateService
.
new
(
project
,
current_user
,
attrs
.
merge
({
request:
request
})).
execute
if
issue
.
nil?
render_api_error!
({
error:
'Spam detected'
},
400
)
end
if
issue
.
valid?
# Need to check if id is nil here, because if issue is spam, errors
# get added, but Rails still thinks it's valid, but it is never saved
# so id will be nil
if
issue
.
id
.
nil?
render_api_error!
({
error:
'Spam detected'
},
400
)
end
# Find or create labels and attach to issue. Labels are valid because
# we already checked its name, so there can't be an error here
if
params
[
:labels
].
present?
...
...
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