summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Jankovski <marin@gitlab.com>2015-03-03 21:57:00 +0000
committerMarin Jankovski <marin@gitlab.com>2015-03-03 21:57:00 +0000
commit66fa4b09edd5e347882aa2d5646b5faeeac3b37d (patch)
tree784e2bbcd919b98672c900c636fb98a2adc0af9d
parent8c47a72a4ed3df2327104e029307b5d804525886 (diff)
parentb8c9257fb1dc70cd65a14cb7dec62455ea54e394 (diff)
downloadgitlab-ce-66fa4b09edd5e347882aa2d5646b5faeeac3b37d.tar.gz
Merge branch 'fix-edit-note-with-votes' into 'master'
Fix server error when editing a note to "+1" or "-1" ### Summary If a user edits a comment with "+1" or "-1" in the beginning, the POST returns an Internal Server error. (issue #1151). This merge request resolves that error. ### Steps to reproduce 1. Comment on an issue with "Test comment". 2. Edit the issue. 3. Write "+1" and click "Save Comment". ### Expected behavior The edited note should be saved and refreshed. Any previous upvotes/downvotes from the user should contain a strikethrough. ### Observed behavior Internal Error ### Relevant logs ``` Started PUT "/avocode/avocode-manager/notes/4996" for 185.33.136.107 at 2015-02-28 17:11:53 +0100 Processing by Projects::NotesController#update as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"*removed*", "note"=>{"note"=>"+1\r\n\r\nYes"}, "commit"=>"Save Comment", "project_id"=>"avocode/avocode-manager", "id"=>"4996"} Completed 500 Internal Server Error in 86ms ActionView::Template::Error (undefined method `each' for nil:NilClass): 28: %span.note-last-update 29: = note_timestamp(note) 30: 31: - if note.superceded?(@notes) 32: - if note.upvote? 33: %span.vote.upvote.label.label-gray.strikethrough 34: %i.fa.fa-thumbs-up app/models/note.rb:495:in `superceded?' app/views/projects/notes/_note.html.haml:31:in `_app_views_projects_notes__note_html_haml___812277000516355462_69988235638820' app/controllers/projects/notes_controller.rb:71:in `note_to_html' app/controllers/projects/notes_controller.rb:103:in `render_note_json' app/controllers/projects/notes_controller.rb:39:in `block (2 levels) in update' app/controllers/projects/notes_controller.rb:38:in `update' ``` ### Fix It turns out no tests were present for the "Edit Issue" functionality. I added spinach tests to exercise this and reproduced the error. Most of the routes in `notes_controller.rb` appear to render all notes for the given discussion. `_form.html.haml` needs the full list of notes commented by the user to add strikethroughs for older upvotes/downvotes. However, only the `index` route appeared to obtain this information. The fix is to add a `before_filter` to obtain all the user's notes beforehand, except in the delete case where this information is not needed. Things to watch: `NotesFinder` needs `target_type` and `target_id` to determine what to do. I'm not sure if there is a conscious effort to phase these keywords out in favor of `noteable_type` and `noteable_id`. See merge request !360
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/projects/notes_controller.rb8
-rw-r--r--app/helpers/notes_helper.rb6
-rw-r--r--app/views/projects/notes/_edit_form.html.haml1
-rw-r--r--app/views/projects/notes/_form.html.haml2
-rw-r--r--features/project/commits/comments.feature6
-rw-r--r--features/project/issues/issues.feature9
-rw-r--r--features/steps/shared/note.rb17
8 files changed, 45 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 4a7a7d9457c..3b3baf56706 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 7.9.0 (unreleased)
- Fix merge request URL passed to Webhooks. (Stan Hu)
+ - Fix bug that caused a server error when editing a comment to "+1" or "-1" (Stan Hu)
- Move labels/milestones tabs to sidebar
- Upgrade Rails gem to version 4.1.9.
- Improve error messages for file edit failures
diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb
index 2f1d631c14a..868629a0bc4 100644
--- a/app/controllers/projects/notes_controller.rb
+++ b/app/controllers/projects/notes_controller.rb
@@ -3,10 +3,10 @@ class Projects::NotesController < Projects::ApplicationController
before_filter :authorize_read_note!
before_filter :authorize_write_note!, only: [:create]
before_filter :authorize_admin_note!, only: [:update, :destroy]
+ before_filter :find_current_user_notes, except: [:destroy, :delete_attachment]
def index
current_fetched_at = Time.now.to_i
- @notes = NotesFinder.new.execute(project, current_user, params)
notes_json = { notes: [], last_fetched_at: current_fetched_at }
@@ -116,4 +116,10 @@ class Projects::NotesController < Projects::ApplicationController
:attachment, :line_code, :commit_id
)
end
+
+ private
+
+ def find_current_user_notes
+ @notes = NotesFinder.new.execute(project, current_user, params)
+ end
end
diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index 92ecb2abe4d..ab44fa6ee43 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -4,9 +4,9 @@ module NotesHelper
(@noteable.class.name == note.noteable_type && !note.for_diff_line?)
end
- def note_target_fields
- hidden_field_tag(:target_type, @target_type) +
- hidden_field_tag(:target_id, @target_id)
+ def note_target_fields(note)
+ hidden_field_tag(:target_type, note.noteable.class.name.underscore) +
+ hidden_field_tag(:target_id, note.noteable.id)
end
def link_to_commit_diff_line_note(note)
diff --git a/app/views/projects/notes/_edit_form.html.haml b/app/views/projects/notes/_edit_form.html.haml
index b51ca795418..acb3991d294 100644
--- a/app/views/projects/notes/_edit_form.html.haml
+++ b/app/views/projects/notes/_edit_form.html.haml
@@ -1,5 +1,6 @@
.note-edit-form
= form_for note, url: namespace_project_note_path(@project.namespace, @project, note), method: :put, remote: true, authenticity_token: true do |f|
+ = note_target_fields(note)
= render layout: 'projects/md_preview', locals: { preview_class: "note-text" } do
= render 'projects/zen', f: f, attr: :note,
classes: 'note_text js-note-text'
diff --git a/app/views/projects/notes/_form.html.haml b/app/views/projects/notes/_form.html.haml
index 4476337cb10..be96c302143 100644
--- a/app/views/projects/notes/_form.html.haml
+++ b/app/views/projects/notes/_form.html.haml
@@ -1,5 +1,5 @@
= form_for [@project.namespace.becomes(Namespace), @project, @note], remote: true, html: { :'data-type' => 'json', multipart: true, id: nil, class: "new_note js-new-note-form common-note-form gfm-form" }, authenticity_token: true do |f|
- = note_target_fields
+ = note_target_fields(@note)
= f.hidden_field :commit_id
= f.hidden_field :line_code
= f.hidden_field :noteable_id
diff --git a/features/project/commits/comments.feature b/features/project/commits/comments.feature
index afcf0fdbb07..c41075d7ad4 100644
--- a/features/project/commits/comments.feature
+++ b/features/project/commits/comments.feature
@@ -41,3 +41,9 @@ Feature: Project Commits Comments
Given I leave a comment like "XML attached"
And I delete a comment
Then I should not see a comment saying "XML attached"
+
+ @javascript
+ Scenario: I can edit a comment with +1
+ Given I leave a comment like "XML attached"
+ And I edit the last comment with a +1
+ Then I should see +1 in the description
diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature
index 28ea44530fe..283979204db 100644
--- a/features/project/issues/issues.feature
+++ b/features/project/issues/issues.feature
@@ -139,6 +139,15 @@ Feature: Project Issues
And I leave a comment with task markdown
Then I should not see task checkboxes in the comment
+ @javascript
+ Scenario: Issue notes should be editable with +1
+ Given project "Shop" has "Tasks-open" open issue with task markdown
+ When I visit issue page "Tasks-open"
+ And I leave a comment with a header containing "Comment with a header"
+ Then The comment with the header should not have an ID
+ And I edit the last comment with a +1
+ Then I should see +1 in the description
+
# Task status in issues list
Scenario: Issues list should display task status
diff --git a/features/steps/shared/note.rb b/features/steps/shared/note.rb
index 45773056953..583746d4475 100644
--- a/features/steps/shared/note.rb
+++ b/features/steps/shared/note.rb
@@ -135,4 +135,21 @@ module SharedNote
'li.note div.timeline-content input[type="checkbox"]'
)
end
+
+ step 'I edit the last comment with a +1' do
+ find(".note").hover
+ find('.js-note-edit').click
+
+ within(".current-note-edit-form") do
+ fill_in 'note[note]', with: '+1 Awesome!'
+ click_button 'Save Comment'
+ sleep 0.05
+ end
+ end
+
+ step 'I should see +1 in the description' do
+ within(".note") do
+ page.should have_content("+1 Awesome!")
+ end
+ end
end