summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-07-28 19:02:56 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-08-15 13:18:15 -0500
commit722fc84e3d4785fb3a9db5f1c7d2aabad22e8e01 (patch)
treebc87237d15d15216cb6b59af27eee36278e7b962 /lib
parent95419679f23f0628d1885dd9656cc159e9d55ea9 (diff)
downloadgitlab-ce-722fc84e3d4785fb3a9db5f1c7d2aabad22e8e01.tar.gz
Complete refactor of the `Spammable` concern and tests:
- Merged `AkismetSubmittable` into `Spammable` - Clean up `SpamCheckService` - Added tests for `Spammable` - Added submit (ham or spam) options to `AkismetHelper`
Diffstat (limited to 'lib')
-rw-r--r--lib/api/issues.rb2
-rw-r--r--lib/gitlab/akismet_helper.rb34
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index c4d3134da6c..7bbfc137c2c 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -160,7 +160,7 @@ module API
issue = ::Issues::CreateService.new(project, current_user, attrs.merge(request: request, api: true)).execute
- if issue.spam?
+ if issue.spam_detected?
render_api_error!({ error: 'Spam detected' }, 400)
end
diff --git a/lib/gitlab/akismet_helper.rb b/lib/gitlab/akismet_helper.rb
index 207736b59db..19e73820321 100644
--- a/lib/gitlab/akismet_helper.rb
+++ b/lib/gitlab/akismet_helper.rb
@@ -43,5 +43,39 @@ module Gitlab
false
end
end
+
+ def ham!(details, text, user)
+ client = akismet_client
+
+ params = {
+ type: 'comment',
+ text: text,
+ author: user.name,
+ author_email: user.email
+ }
+
+ begin
+ client.submit_ham(details.ip_address, details.user_agent, params)
+ rescue => e
+ Rails.logger.error("Unable to connect to Akismet: #{e}, skipping!")
+ end
+ end
+
+ def spam!(details, text, user)
+ client = akismet_client
+
+ params = {
+ type: 'comment',
+ text: text,
+ author: user.name,
+ author_email: user.email
+ }
+
+ begin
+ client.submit_spam(details.ip_address, details.user_agent, params)
+ rescue => e
+ Rails.logger.error("Unable to connect to Akismet: #{e}, skipping!")
+ end
+ end
end
end