diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-07-28 19:02:56 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-08-15 13:18:15 -0500 |
commit | 722fc84e3d4785fb3a9db5f1c7d2aabad22e8e01 (patch) | |
tree | bc87237d15d15216cb6b59af27eee36278e7b962 /lib | |
parent | 95419679f23f0628d1885dd9656cc159e9d55ea9 (diff) | |
download | gitlab-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.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/akismet_helper.rb | 34 |
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 |