summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/api/issues.rb15
-rw-r--r--spec/requests/api/issues_spec.rb11
2 files changed, 16 insertions, 10 deletions
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index cdadd13c13a..252744515da 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -23,11 +23,13 @@ module API
end
def create_spam_log(project, current_user, attrs)
- params = attrs.dup
- params[:source_ip] = env['REMOTE_ADDR']
- params[:user_agent] = env['HTTP_USER_AGENT']
- params[:noteable_type] = 'Issue'
- params[:via_api] = true
+ params = attrs.merge({
+ source_ip: env['REMOTE_ADDR'],
+ user_agent: env['HTTP_USER_AGENT'],
+ noteable_type: 'Issue',
+ via_api: true
+ })
+
::CreateSpamLogService.new(project, current_user, params).execute
end
end
@@ -126,8 +128,7 @@ module API
end
project = user_project
- text = attrs[:title]
- text += "\n#{attrs[:description]}" if attrs[:description].present?
+ text = [attrs[:title], attrs[:description]].reject(&:blank?).join("\n")
if check_for_spam?(project, current_user) && is_spam?(env, current_user, text)
create_spam_log(project, current_user, attrs)
diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb
index 2e50344c149..dcf1b394a3f 100644
--- a/spec/requests/api/issues_spec.rb
+++ b/spec/requests/api/issues_spec.rb
@@ -249,14 +249,19 @@ describe API::API, api: true do
end
end
- it "should create a new project issue" do
- post api("/projects/#{project.id}/issues", user),
- title: 'new issue', labels: 'label, label2'
+ it "should not create a new project issue" do
+ expect {
+ post api("/projects/#{project.id}/issues", user),
+ title: 'new issue', description: 'content here', labels: 'label, label2'
+ }.not_to change(Issue, :count)
+
expect(response.status).to eq(400)
expect(json_response['message']).to eq({ "error" => "Spam detected" })
+
spam_logs = SpamLog.all
expect(spam_logs.count).to eq(1)
expect(spam_logs[0].title).to eq('new issue')
+ expect(spam_logs[0].description).to eq('content here')
expect(spam_logs[0].user).to eq(user)
expect(spam_logs[0].noteable_type).to eq('Issue')
expect(spam_logs[0].project_id).to eq(project.id)