diff options
author | Patricio Cano <suprnova32@gmail.com> | 2016-07-21 18:11:53 -0500 |
---|---|---|
committer | Patricio Cano <suprnova32@gmail.com> | 2016-07-26 19:29:16 -0500 |
commit | f01fce7f4683e06e83d3f91d38ca5b749e27e7ec (patch) | |
tree | 4e43e365de7cc27cc7c22458fa0a8d079e35add6 /lib/api/issues.rb | |
parent | 8f04cf0eadbcde7fc5d1c970741e30ca8b97967d (diff) | |
download | gitlab-ce-f01fce7f4683e06e83d3f91d38ca5b749e27e7ec.tar.gz |
Refactor spam validation to a concern that can be easily reused and improve legibility in `SpamCheckService`akismet-ui-check
Diffstat (limited to 'lib/api/issues.rb')
-rw-r--r-- | lib/api/issues.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 21b9eb367e7..c4d3134da6c 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -158,15 +158,13 @@ module API project = user_project - issue = ::Issues::CreateService.new(project, current_user, attrs.merge({ request: request })).execute + issue = ::Issues::CreateService.new(project, current_user, attrs.merge(request: request, api: true)).execute + + if issue.spam? + render_api_error!({ error: 'Spam detected' }, 400) + end if issue.valid? - # Need to check if id is nil here, because if issue is spam, errors - # get added, but Rails still thinks it's valid, but it is never saved - # so id will be nil - if issue.id.nil? - render_api_error!({ error: 'Spam detected' }, 400) - end # Find or create labels and attach to issue. Labels are valid because # we already checked its name, so there can't be an error here if params[:labels].present? |