diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-07-19 02:17:43 +0300 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-07-26 23:17:52 +0300 |
commit | f7807c5b68b59f6a5b984ee64a6c82a3bd993d92 (patch) | |
tree | 48e30fc7667ca0a2df6d67b9ee692aede869656d /app/services | |
parent | 9c34fafb8b728358a516a25120aa5f28567eae48 (diff) |
Submit all issues on public projects to Akismet if enabled.
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issues/create_service.rb | 6 | ||||
-rw-r--r-- | app/services/issues/spam_check_service.rb | 25 |
2 files changed, 30 insertions, 1 deletions
diff --git a/app/services/issues/create_service.rb b/app/services/issues/create_service.rb index e63e1af8766..496ea5a86a2 100644 --- a/app/services/issues/create_service.rb +++ b/app/services/issues/create_service.rb @@ -3,9 +3,13 @@ module Issues def execute filter_params label_params = params[:label_ids] - issue = project.issues.new(params.except(:label_ids)) + issue = project.issues.new(params.except(:label_ids, :request)) issue.author = params[:author] || current_user + if Issues::SpamCheckService.new(project, current_user, params).spam_detected? + return nil + end + if issue.save issue.update_attributes(label_ids: label_params) notification_service.new_issue(issue, current_user) diff --git a/app/services/issues/spam_check_service.rb b/app/services/issues/spam_check_service.rb new file mode 100644 index 00000000000..b8d4e37faf5 --- /dev/null +++ b/app/services/issues/spam_check_service.rb @@ -0,0 +1,25 @@ +module Issues + class SpamCheckService < BaseService + include Gitlab::AkismetHelper + + def spam_detected? + text = [params[:title], params[:description]].reject(&:blank?).join("\n") + request = params[:request] + + if request + if check_for_spam?(project) && is_spam?(request.env, current_user, text) + attrs = { + user_id: current_user.id, + project_id: project.id, + title: params[:title], + description: params[:description] + } + create_spam_log(project, current_user, attrs, request.env, api: false) + return true + end + end + + false + end + end +end |