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
d730b69e
Commit
d730b69e
authored
Mar 20, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spam check only when spammable attributes have changed
parent
86ef67ee
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
138 additions
and
26 deletions
+138
-26
app/models/issue.rb
app/models/issue.rb
+1
-2
app/models/snippet.rb
app/models/snippet.rb
+2
-1
app/services/spam_check_service.rb
app/services/spam_check_service.rb
+3
-0
changelogs/unreleased/29483-spam-check-only-title-and-description.yml
...nreleased/29483-spam-check-only-title-and-description.yml
+4
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+37
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+43
-0
spec/services/spam_service_spec.rb
spec/services/spam_service_spec.rb
+48
-23
No files found.
app/models/issue.rb
View file @
d730b69e
...
@@ -211,9 +211,8 @@ class Issue < ActiveRecord::Base
...
@@ -211,9 +211,8 @@ class Issue < ActiveRecord::Base
due_date
.
try
(
:past?
)
||
false
due_date
.
try
(
:past?
)
||
false
end
end
# Only issues on public projects should be checked for spam
def
check_for_spam?
def
check_for_spam?
project
.
public?
project
.
public?
&&
(
title_changed?
||
description_changed?
)
end
end
def
as_json
(
options
=
{})
def
as_json
(
options
=
{})
...
...
app/models/snippet.rb
View file @
d730b69e
...
@@ -132,7 +132,8 @@ class Snippet < ActiveRecord::Base
...
@@ -132,7 +132,8 @@ class Snippet < ActiveRecord::Base
end
end
def
check_for_spam?
def
check_for_spam?
public
?
visibility_level_changed?
(
to:
Snippet
::
PUBLIC
)
||
(
public
?
&&
(
title_changed?
||
content_changed?
))
end
end
def
spammable_entity_type
def
spammable_entity_type
...
...
app/services/spam_check_service.rb
View file @
d730b69e
...
@@ -14,6 +14,9 @@ module SpamCheckService
...
@@ -14,6 +14,9 @@ module SpamCheckService
@spam_log_id
=
params
.
delete
(
:spam_log_id
)
@spam_log_id
=
params
.
delete
(
:spam_log_id
)
end
end
# In order to be proceed to the spam check process, @spammable has to be
# a dirty instance, which means it should be already assigned with the new
# attribute values.
def
spam_check
(
spammable
,
user
)
def
spam_check
(
spammable
,
user
)
spam_service
=
SpamService
.
new
(
spammable
,
@request
)
spam_service
=
SpamService
.
new
(
spammable
,
@request
)
...
...
changelogs/unreleased/29483-spam-check-only-title-and-description.yml
0 → 100644
View file @
d730b69e
---
title
:
Spam check only when spammable attributes have changed
merge_request
:
author
:
spec/models/issue_spec.rb
View file @
d730b69e
...
@@ -670,4 +670,41 @@ describe Issue, models: true do
...
@@ -670,4 +670,41 @@ describe Issue, models: true do
expect
(
attrs_hash
).
to
include
(
'time_estimate'
)
expect
(
attrs_hash
).
to
include
(
'time_estimate'
)
end
end
end
end
describe
'#check_for_spam'
do
let
(
:project
)
{
create
:project
,
visibility_level:
visibility_level
}
let
(
:issue
)
{
create
:issue
,
project:
project
}
subject
do
issue
.
assign_attributes
(
description:
description
)
issue
.
check_for_spam?
end
context
'when project is public and spammable attributes changed'
do
let
(
:visibility_level
)
{
Gitlab
::
VisibilityLevel
::
PUBLIC
}
let
(
:description
)
{
'woo'
}
it
'returns true'
do
is_expected
.
to
be_truthy
end
end
context
'when project is private'
do
let
(
:visibility_level
)
{
Gitlab
::
VisibilityLevel
::
PRIVATE
}
let
(
:description
)
{
issue
.
description
}
it
'returns false'
do
is_expected
.
to
be_falsey
end
end
context
'when spammable attributes have not changed'
do
let
(
:visibility_level
)
{
Gitlab
::
VisibilityLevel
::
PUBLIC
}
let
(
:description
)
{
issue
.
description
}
it
'returns false'
do
is_expected
.
to
be_falsey
end
end
end
end
end
spec/models/snippet_spec.rb
View file @
d730b69e
...
@@ -198,4 +198,47 @@ describe Snippet, models: true do
...
@@ -198,4 +198,47 @@ describe Snippet, models: true do
expect
(
snippet
.
participants
).
to
include
(
note1
.
author
,
note2
.
author
)
expect
(
snippet
.
participants
).
to
include
(
note1
.
author
,
note2
.
author
)
end
end
end
end
describe
'#check_for_spam'
do
let
(
:snippet
)
{
create
:snippet
,
visibility_level:
visibility_level
}
subject
do
snippet
.
assign_attributes
(
title:
title
)
snippet
.
check_for_spam?
end
context
'when public and spammable attributes changed'
do
let
(
:visibility_level
)
{
Snippet
::
PUBLIC
}
let
(
:title
)
{
'woo'
}
it
'returns true'
do
is_expected
.
to
be_truthy
end
end
context
'when private'
do
let
(
:visibility_level
)
{
Snippet
::
PRIVATE
}
let
(
:title
)
{
snippet
.
title
}
it
'returns false'
do
is_expected
.
to
be_falsey
end
it
'returns true when switching to public'
do
snippet
.
save!
snippet
.
visibility_level
=
Snippet
::
PUBLIC
expect
(
snippet
.
check_for_spam?
).
to
be_truthy
end
end
context
'when spammable attributes have not changed'
do
let
(
:visibility_level
)
{
Snippet
::
PUBLIC
}
let
(
:title
)
{
snippet
.
title
}
it
'returns false'
do
is_expected
.
to
be_falsey
end
end
end
end
end
spec/services/spam_service_spec.rb
View file @
d730b69e
...
@@ -19,8 +19,32 @@ describe SpamService, services: true do
...
@@ -19,8 +19,32 @@ describe SpamService, services: true do
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:request
)
{
double
(
:request
,
env:
{})
}
let
(
:request
)
{
double
(
:request
,
env:
{})
}
context
'when spammable attributes have not changed'
do
before
do
issue
.
closed_at
=
Time
.
zone
.
now
allow
(
AkismetService
).
to
receive
(
:new
).
and_return
(
double
(
is_spam?:
true
))
end
it
'returns false'
do
expect
(
check_spam
(
issue
,
request
,
false
)).
to
be_falsey
end
it
'does not create a spam log'
do
expect
{
check_spam
(
issue
,
request
,
false
)
}
.
not_to
change
{
SpamLog
.
count
}
end
end
context
'when spammable attributes have changed'
do
before
do
issue
.
description
=
'SPAM!'
end
context
'when indicated as spam by akismet'
do
context
'when indicated as spam by akismet'
do
before
{
allow
(
AkismetService
).
to
receive
(
:new
).
and_return
(
double
(
is_spam?:
true
))
}
before
do
allow
(
AkismetService
).
to
receive
(
:new
).
and_return
(
double
(
is_spam?:
true
))
end
it
'doesnt check as spam when request is missing'
do
it
'doesnt check as spam when request is missing'
do
check_spam
(
issue
,
nil
,
false
)
check_spam
(
issue
,
nil
,
false
)
...
@@ -59,4 +83,5 @@ describe SpamService, services: true do
...
@@ -59,4 +83,5 @@ describe SpamService, services: true do
end
end
end
end
end
end
end
end
end
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