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
9c34fafb
Commit
9c34fafb
authored
Jul 16, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Submit new issues created via the WebUI by non project members to Akismet for spam check.
parent
8a95f1f3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
13 deletions
+64
-13
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+17
-1
doc/integration/akismet.md
doc/integration/akismet.md
+3
-0
lib/api/issues.rb
lib/api/issues.rb
+1
-12
lib/gitlab/akismet_helper.rb
lib/gitlab/akismet_helper.rb
+11
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+31
-0
No files found.
CHANGELOG
View file @
9c34fafb
...
@@ -93,6 +93,7 @@ v 8.10.0
...
@@ -93,6 +93,7 @@ v 8.10.0
- Fix viewing notification settings when a project is pending deletion
- Fix viewing notification settings when a project is pending deletion
- Updated compare dropdown menus to use GL dropdown
- Updated compare dropdown menus to use GL dropdown
- Redirects back to issue after clicking login link
- Redirects back to issue after clicking login link
- Submit issues created via the WebUI by non project members to Akismet !5333
- Eager load award emoji on notes
- Eager load award emoji on notes
- Allow to define manual actions/builds on Pipelines and Environments
- Allow to define manual actions/builds on Pipelines and Environments
- Fix pagination when sorting by columns with lots of ties (like priority)
- Fix pagination when sorting by columns with lots of ties (like priority)
...
...
app/controllers/projects/issues_controller.rb
View file @
9c34fafb
...
@@ -2,6 +2,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -2,6 +2,7 @@ class Projects::IssuesController < Projects::ApplicationController
include
ToggleSubscriptionAction
include
ToggleSubscriptionAction
include
IssuableActions
include
IssuableActions
include
ToggleAwardEmoji
include
ToggleAwardEmoji
include
Gitlab
::
AkismetHelper
before_action
:module_enabled
before_action
:module_enabled
before_action
:issue
,
only:
[
:edit
,
:update
,
:show
,
:referenced_merge_requests
,
before_action
:issue
,
only:
[
:edit
,
:update
,
:show
,
:referenced_merge_requests
,
...
@@ -79,6 +80,21 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -79,6 +80,21 @@ class Projects::IssuesController < Projects::ApplicationController
end
end
def
create
def
create
text
=
[
params
[
:issue
][
:title
],
params
[
:issue
][
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
if
check_for_spam?
(
project
,
current_user
)
&&
is_spam?
(
request
.
env
,
current_user
,
text
)
attrs
=
{
user_id:
current_user
.
id
,
project_id:
project
.
id
,
title:
params
[
:issue
][
:title
],
description:
params
[
:issue
][
:description
]
}
create_spam_log
(
project
,
current_user
,
attrs
,
request
.
env
,
api:
false
)
@issue
=
@project
.
issues
.
new
flash
[
:notice
]
=
'Your issue has been recognized as spam and has been discarded.'
render
:new
and
return
end
@issue
=
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
).
execute
@issue
=
Issues
::
CreateService
.
new
(
project
,
current_user
,
issue_params
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -89,7 +105,7 @@ class Projects::IssuesController < Projects::ApplicationController
...
@@ -89,7 +105,7 @@ class Projects::IssuesController < Projects::ApplicationController
render
:new
render
:new
end
end
end
end
format
.
js
do
|
format
|
format
.
js
do
@link
=
@issue
.
attachment
.
url
.
to_js
@link
=
@issue
.
attachment
.
url
.
to_js
end
end
end
end
...
...
doc/integration/akismet.md
View file @
9c34fafb
...
@@ -5,6 +5,9 @@ GitLab uses Akismet to prevent users who are not members of a project from
...
@@ -5,6 +5,9 @@ GitLab uses Akismet to prevent users who are not members of a project from
creating spam via the GitLab API. Detected spam will be rejected, and
creating spam via the GitLab API. Detected spam will be rejected, and
an entry in the "Spam Log" section in the Admin page will be created.
an entry in the "Spam Log" section in the Admin page will be created.
> *Note:* As of 8.10 GitLab also submits issues created via the WebUI by non
project members to Akismet to prevent spam.
Privacy note: GitLab submits the user's IP and user agent to Akismet. Note that
Privacy note: GitLab submits the user's IP and user agent to Akismet. Note that
adding a user to a project will disable the Akismet check and prevent this
adding a user to a project will disable the Akismet check and prevent this
from happening.
from happening.
...
...
lib/api/issues.rb
View file @
9c34fafb
...
@@ -21,17 +21,6 @@ module API
...
@@ -21,17 +21,6 @@ module API
def
filter_issues_milestone
(
issues
,
milestone
)
def
filter_issues_milestone
(
issues
,
milestone
)
issues
.
includes
(
:milestone
).
where
(
'milestones.title'
=>
milestone
)
issues
.
includes
(
:milestone
).
where
(
'milestones.title'
=>
milestone
)
end
end
def
create_spam_log
(
project
,
current_user
,
attrs
)
params
=
attrs
.
merge
({
source_ip:
client_ip
(
env
),
user_agent:
user_agent
(
env
),
noteable_type:
'Issue'
,
via_api:
true
})
::
CreateSpamLogService
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
resource
:issues
do
resource
:issues
do
...
@@ -171,7 +160,7 @@ module API
...
@@ -171,7 +160,7 @@ module API
text
=
[
attrs
[
:title
],
attrs
[
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
text
=
[
attrs
[
:title
],
attrs
[
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
if
check_for_spam?
(
project
,
current_user
)
&&
is_spam?
(
env
,
current_user
,
text
)
if
check_for_spam?
(
project
,
current_user
)
&&
is_spam?
(
env
,
current_user
,
text
)
create_spam_log
(
project
,
current_user
,
attrs
)
create_spam_log
(
project
,
current_user
,
attrs
,
env
)
render_api_error!
({
error:
'Spam detected'
},
400
)
render_api_error!
({
error:
'Spam detected'
},
400
)
end
end
...
...
lib/gitlab/akismet_helper.rb
View file @
9c34fafb
...
@@ -43,5 +43,16 @@ module Gitlab
...
@@ -43,5 +43,16 @@ module Gitlab
false
false
end
end
end
end
def
create_spam_log
(
project
,
current_user
,
attrs
,
env
,
api:
true
)
params
=
attrs
.
merge
({
source_ip:
client_ip
(
env
),
user_agent:
user_agent
(
env
),
noteable_type:
'Issue'
,
via_api:
api
})
::
CreateSpamLogService
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
end
end
spec/controllers/projects/issues_controller_spec.rb
View file @
9c34fafb
...
@@ -243,6 +243,37 @@ describe Projects::IssuesController do
...
@@ -243,6 +243,37 @@ describe Projects::IssuesController do
end
end
end
end
describe
'POST #create'
do
context
'Akismet is enabled'
do
before
do
allow_any_instance_of
(
Gitlab
::
AkismetHelper
).
to
receive
(
:check_for_spam?
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
AkismetHelper
).
to
receive
(
:is_spam?
).
and_return
(
true
)
end
def
post_spam_issue
sign_in
(
user
)
spam_project
=
create
(
:empty_project
,
:public
)
post
:create
,
{
namespace_id:
spam_project
.
namespace
.
to_param
,
project_id:
spam_project
.
to_param
,
issue:
{
title:
'Spam Title'
,
description:
'Spam lives here'
}
}
end
it
'rejects an issue recognized as spam'
do
expect
{
post_spam_issue
}.
not_to
change
(
Issue
,
:count
)
expect
(
response
).
to
render_template
(
:new
)
end
it
'creates a spam log'
do
post_spam_issue
spam_logs
=
SpamLog
.
all
expect
(
spam_logs
.
count
).
to
eq
(
1
)
expect
(
spam_logs
[
0
].
title
).
to
eq
(
'Spam Title'
)
end
end
end
describe
"DELETE #destroy"
do
describe
"DELETE #destroy"
do
context
"when the user is a developer"
do
context
"when the user is a developer"
do
before
{
sign_in
(
user
)
}
before
{
sign_in
(
user
)
}
...
...
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