Merge remote-tracking branch 'upstream/pull/4462'

This commit is contained in:
Tom Hughes 2024-01-17 18:41:16 +00:00
commit 9387df9141
4 changed files with 129 additions and 24 deletions

View file

@ -52,20 +52,18 @@ OSM.Note = function (map) {
OSM.loadSidebarContent(path, function () {
initialize(path, id, moveToNote);
});
},
error: function (xhr) {
$(form).find("#comment-error")
.text(xhr.responseText)
.prop("hidden", false);
updateButtons(form);
}
});
});
content.find("textarea").on("input", function (e) {
var form = e.target.form;
if ($(e.target).val() === "") {
$(form.close).val($(form.close).data("defaultActionText"));
$(form.comment).prop("disabled", true);
} else {
$(form.close).val($(form.close).data("commentActionText"));
$(form.comment).prop("disabled", false);
}
updateButtons(e.target.form);
});
content.find("textarea").val("").trigger("input");
@ -84,6 +82,17 @@ OSM.Note = function (map) {
if (callback) callback();
}
function updateButtons(form) {
$(form).find("input[type=submit]").prop("disabled", false);
if ($(form.text).val() === "") {
$(form.close).val($(form.close).data("defaultActionText"));
$(form.comment).prop("disabled", true);
} else {
$(form.close).val($(form.close).data("commentActionText"));
$(form.comment).prop("disabled", false);
}
}
function moveToNote() {
var data = $(".details").data();
if (!data) return;

View file

@ -49,6 +49,8 @@
<div class="mb-3">
<textarea class="form-control" name="text" cols="40" rows="5" maxlength="2000"></textarea>
</div>
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
</div>
<div class="btn-wrapper">
<% if current_user.moderator? -%>
<%= submit_tag t(".hide"), :name => "hide", :class => "btn btn-light",
@ -73,6 +75,8 @@
<% else %>
<form class="mb-3" action="#">
<input type="hidden" name="text" value="" autocomplete="off">
<div id="comment-error" class="alert alert-danger p-2 mb-3" hidden>
</div>
<div class="btn-wrapper">
<% if @note.status != "hidden" and current_user and current_user.moderator? -%>
<input type="submit" name="hide" value="<%= t(".hide") %>" class="btn btn-light" data-method="DELETE" data-url="<%= api_note_url(@note, "json") %>">

View file

@ -21,4 +21,10 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
Settings.reload!
super
end
private
def within_sidebar(&block)
within "#sidebar_content", &block
end
end

View file

@ -5,18 +5,22 @@ class NoteCommentsTest < ApplicationSystemTestCase
note = create(:note_with_comments)
visit note_path(note)
within_sidebar do
assert_no_button "Resolve"
assert_no_button "Comment"
assert_link "Log in to comment on this note", :href => login_path(:referer => note_path(note))
end
end
test "closed note has no login notice" do
note = create(:note_with_comments, :closed)
visit note_path(note)
within_sidebar do
assert_no_button "Reactivate"
assert_no_link "Log in to comment on this note"
end
end
def test_add_comment
note = create(:note_with_comments)
@ -24,6 +28,7 @@ class NoteCommentsTest < ApplicationSystemTestCase
sign_in_as(user)
visit note_path(note)
within_sidebar do
assert_no_content "Comment from #{user.display_name}"
assert_no_content "Some newly added note comment"
assert_button "Resolve"
@ -39,4 +44,85 @@ class NoteCommentsTest < ApplicationSystemTestCase
assert_content "Comment from #{user.display_name}"
assert_content "Some newly added note comment"
end
end
test "can't add a comment when blocked" do
note = create(:note_with_comments)
user = create(:user)
sign_in_as(user)
visit note_path(note)
block = create(:user_block, :user => user)
within_sidebar do
fill_in "text", :with => "Comment that won't be added while blocked"
assert_no_text "Comment from #{user.display_name}"
assert_no_text "Comment that won't be added while blocked"
assert_no_text "Your access to the API has been blocked"
assert_button "Comment & Resolve", :disabled => false
assert_button "Comment", :disabled => false
click_on "Comment"
assert_no_text "Comment from #{user.display_name}"
assert_no_text "Comment that won't be added while blocked"
assert_text "Your access to the API has been blocked"
assert_button "Comment & Resolve", :disabled => false
assert_button "Comment", :disabled => false
block.revoke! block.creator
click_on "Comment"
assert_text "Comment from #{user.display_name}"
assert_text "Comment that won't be added while blocked"
assert_no_text "Your access to the API has been blocked"
end
end
test "can't resolve a note when blocked" do
note = create(:note_with_comments)
user = create(:user)
sign_in_as(user)
visit note_path(note)
create(:user_block, :user => user)
within_sidebar do
assert_text "Unresolved note"
assert_no_text "Resolved note"
assert_no_text "Your access to the API has been blocked"
assert_button "Resolve", :disabled => false
assert_button "Comment", :disabled => true
click_on "Resolve"
assert_text "Unresolved note"
assert_no_text "Resolved note"
assert_text "Your access to the API has been blocked"
assert_button "Resolve", :disabled => false
assert_button "Comment", :disabled => true
end
end
test "can't reactivate a note when blocked" do
note = create(:note_with_comments, :closed)
user = create(:user)
sign_in_as(user)
visit note_path(note)
create(:user_block, :user => user)
within_sidebar do
assert_no_text "Unresolved note"
assert_text "Resolved note"
assert_no_text "Your access to the API has been blocked"
assert_button "Reactivate", :disabled => false
click_on "Reactivate"
assert_no_text "Unresolved note"
assert_text "Resolved note"
assert_text "Your access to the API has been blocked"
assert_button "Reactivate", :disabled => false
end
end
end