Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/assets/javascripts/index/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ OSM.Note = function (map) {
const resolveButton = content.find("button[name='close']");
const commentButton = content.find("button[name='comment']");

content.find("button[name]").prop("disabled", false);
if (content.find("textarea").val() === "") {
resolveButton.text(resolveButton.data("defaultActionText"));
resolveButton.prop("disabled", !resolveButton.data("canResolveWithoutComment"));
commentButton.prop("disabled", true);
} else {
resolveButton.text(resolveButton.data("commentActionText"));
content.find("button[name]").prop("disabled", false);
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/helpers/note_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ def soft_anonymous_notes_limit_reached?(anonymous_notes_count)
def hard_anonymous_notes_limit_reached?(anonymous_notes_count)
!current_user && anonymous_notes_count >= 10
end

def can_resolve_without_comment?(current_user, note)
current_user.changesets_count.positive? || (note.comments.length > 1 && note.comments.last.author == current_user)
end
end
20 changes: 15 additions & 5 deletions app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,21 @@
:data => { :method => "DELETE",
:url => api_note_url(@note, "json") } %>
<% end -%>
<%= button_tag t(".resolve"), :name => "close", :class => "btn btn-primary",
:data => { :method => "POST",
:url => close_api_note_url(@note, "json"),
:default_action_text => t(".resolve"),
:comment_action_text => t(".comment_and_resolve") } %>
<% if can_resolve_without_comment?(current_user, @note) -%>
<%= button_tag t(".resolve"), :name => "close", :class => "btn btn-primary",
:data => { :method => "POST",
:url => close_api_note_url(@note, "json"),
:default_action_text => t(".resolve"),
:comment_action_text => t(".comment_and_resolve"),
:can_resolve_without_comment => true } %>
<% else -%>
<%= button_tag t(".comment_and_resolve"), :name => "close", :class => "btn btn-primary",
:disabled => true,
:data => { :method => "POST",
:url => close_api_note_url(@note, "json"),
:default_action_text => t(".comment_and_resolve"),
:comment_action_text => t(".comment_and_resolve") } %>
<% end -%>
<%= button_tag t(".comment"), :name => "comment", :class => "btn btn-primary", :disabled => true,
:data => { :method => "POST",
:url => comment_api_note_url(@note, "json") } %>
Expand Down
3 changes: 2 additions & 1 deletion test/system/note_comments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class NoteCommentsTest < ApplicationSystemTestCase
within_sidebar do
assert_no_content "Comment from #{user.display_name}"
assert_no_content "Some newly added note comment"
assert_button "Resolve"
assert_no_button "Resolve"
assert_button "Comment & Resolve", :disabled => true
assert_button "Comment", :disabled => true

fill_in "text", :with => "Some newly added note comment"
Expand Down
29 changes: 29 additions & 0 deletions test/system/resolve_note_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ResolveNoteTest < ApplicationSystemTestCase
test "can resolve an open note" do
note = create(:note_with_comments)
user = create(:user)
create(:changeset, :user => user, :num_changes => 1)
sign_in_as(user)
visit note_path(note)

Expand All @@ -23,6 +24,7 @@ class ResolveNoteTest < ApplicationSystemTestCase
test "can resolve an open note with a comment" do
note = create(:note_with_comments)
user = create(:user)
create(:changeset, :user => user, :num_changes => 1)
sign_in_as(user)
visit note_path(note)

Expand All @@ -42,6 +44,32 @@ class ResolveNoteTest < ApplicationSystemTestCase
end
end

test "can't resolve an open note without map edits" do
note = create(:note)
user = create(:user)
sign_in_as(user)
visit note_path(note)

within_sidebar do
assert_no_button "Resolve"
assert_button "Comment & Resolve", :disabled => true
assert_button "Comment", :disabled => true
end
end

test "can resolve an open note when user authored the last comment" do
note = create(:note_with_comments)
user = create(:user)
create(:note_comment, :note => note, :author => user, :event => "commented")
sign_in_as(user)
visit note_path(note)

within_sidebar do
assert_button "Resolve"
assert_no_button "Comment & Resolve"
end
end

test "can reactivate a closed note" do
note = create(:note_with_comments, :closed)
user = create(:user)
Expand Down Expand Up @@ -95,6 +123,7 @@ class ResolveNoteTest < ApplicationSystemTestCase
test "can't resolve a note when blocked" do
note = create(:note_with_comments)
user = create(:user)
create(:changeset, :user => user, :num_changes => 1)
sign_in_as(user)
visit note_path(note)
create(:user_block, :user => user)
Expand Down