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
iv
gitlab-ce
Commits
a2bbf004
Commit
a2bbf004
authored
Jan 26, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor spam filtering on issues API
parent
62cad887
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
lib/api/issues.rb
lib/api/issues.rb
+8
-7
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+8
-3
No files found.
lib/api/issues.rb
View file @
a2bbf004
...
@@ -23,11 +23,13 @@ module API
...
@@ -23,11 +23,13 @@ module API
end
end
def
create_spam_log
(
project
,
current_user
,
attrs
)
def
create_spam_log
(
project
,
current_user
,
attrs
)
params
=
attrs
.
dup
params
=
attrs
.
merge
({
params
[
:source_ip
]
=
env
[
'REMOTE_ADDR'
]
source_ip:
env
[
'REMOTE_ADDR'
],
params
[
:user_agent
]
=
env
[
'HTTP_USER_AGENT'
]
user_agent:
env
[
'HTTP_USER_AGENT'
],
params
[
:noteable_type
]
=
'Issue'
noteable_type:
'Issue'
,
params
[
:via_api
]
=
true
via_api:
true
})
::
CreateSpamLogService
.
new
(
project
,
current_user
,
params
).
execute
::
CreateSpamLogService
.
new
(
project
,
current_user
,
params
).
execute
end
end
end
end
...
@@ -126,8 +128,7 @@ module API
...
@@ -126,8 +128,7 @@ module API
end
end
project
=
user_project
project
=
user_project
text
=
attrs
[
:title
]
text
=
[
attrs
[
:title
],
attrs
[
:description
]].
reject
(
&
:blank?
).
join
(
"
\n
"
)
text
+=
"
\n
#{
attrs
[
:description
]
}
"
if
attrs
[
:description
].
present?
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
)
...
...
spec/requests/api/issues_spec.rb
View file @
a2bbf004
...
@@ -249,14 +249,19 @@ describe API::API, api: true do
...
@@ -249,14 +249,19 @@ describe API::API, api: true do
end
end
end
end
it
"should create a new project issue"
do
it
"should not create a new project issue"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
expect
{
title:
'new issue'
,
labels:
'label, label2'
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
title:
'new issue'
,
description:
'content here'
,
labels:
'label, label2'
}.
not_to
change
(
Issue
,
:count
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
({
"error"
=>
"Spam detected"
})
expect
(
json_response
[
'message'
]).
to
eq
({
"error"
=>
"Spam detected"
})
spam_logs
=
SpamLog
.
all
spam_logs
=
SpamLog
.
all
expect
(
spam_logs
.
count
).
to
eq
(
1
)
expect
(
spam_logs
.
count
).
to
eq
(
1
)
expect
(
spam_logs
[
0
].
title
).
to
eq
(
'new issue'
)
expect
(
spam_logs
[
0
].
title
).
to
eq
(
'new issue'
)
expect
(
spam_logs
[
0
].
description
).
to
eq
(
'content here'
)
expect
(
spam_logs
[
0
].
user
).
to
eq
(
user
)
expect
(
spam_logs
[
0
].
user
).
to
eq
(
user
)
expect
(
spam_logs
[
0
].
noteable_type
).
to
eq
(
'Issue'
)
expect
(
spam_logs
[
0
].
noteable_type
).
to
eq
(
'Issue'
)
expect
(
spam_logs
[
0
].
project_id
).
to
eq
(
project
.
id
)
expect
(
spam_logs
[
0
].
project_id
).
to
eq
(
project
.
id
)
...
...
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