From: Tom Hughes Date: Fri, 21 Feb 2025 18:00:06 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5712' X-Git-Tag: live~183 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/4482ed6d27f096f99e6badc97c74f312391add49?hp=51a2d85053b67b2bc842fa45ac8eb998f8585add Merge remote-tracking branch 'upstream/pull/5712' --- diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 5d817c9c6..fbeb01b76 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -43,7 +43,7 @@ class NotesController < ApplicationController @note_includes_anonymous = @note.author.nil? || @note_comments.find { |comment| comment.author.nil? } - @note_comments = @note_comments.drop(1) if @note.author.nil? || @note.author.active? + @note_comments = @note_comments.drop(1) if @note_comments.first&.event == "opened" rescue ActiveRecord::RecordNotFound render :template => "browse/not_found", :status => :not_found end diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 0ba503228..7a75a4ff5 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -1,9 +1,11 @@ module NoteHelper include ActionView::Helpers::TranslationHelper - def note_description(author, description) + def note_description(author, description, first_comment) if !author.nil? && author.status == "deleted" RichText.new("text", t("notes.show.description_when_author_is_deleted")) + elsif first_comment&.event != "opened" + RichText.new("text", t("notes.show.description_when_there_is_no_opening_comment")) else description end diff --git a/app/models/note.rb b/app/models/note.rb index b7215d6f7..0a1f4abd7 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -95,7 +95,7 @@ class Note < ApplicationRecord # Return the note's description, derived from the first comment def description if user_ip.nil? && user_id.nil? - all_comments.first.body + all_comments.first.body if all_comments.first&.event == "opened" else RichText.new("text", super) end @@ -104,7 +104,7 @@ class Note < ApplicationRecord # Return the note's author object, derived from the first comment def author if user_ip.nil? && user_id.nil? - all_comments.first.author + all_comments.first.author if all_comments.first&.event == "opened" else super end diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 0b39234a9..4bd7d499d 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -48,7 +48,7 @@ <%= link_to note.id, note %> <%= note_author(note.author) %> - <%= note_description(note.author, note.description).to_html %> + <%= note_description(note.author, note.description, current_user&.moderator? ? note.comments.unscope(:where => :visible).first : note.comments.first).to_html %> <%= friendly_date_ago(note.created_at) %> <%= friendly_date_ago(note.updated_at) %> diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index b65926b5f..d0dcdeb1b 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -5,7 +5,7 @@

<%= t(".description") %>

- <%= note_description(@note.author, @note.description).to_html %> + <%= note_description(@note.author, @note.description, current_user&.moderator? ? @note.comments.unscope(:where => :visible).first : @note.comments.first).to_html %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index dd7ae4033..f03a6eeb1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3095,6 +3095,7 @@ en: closed_title: "Resolved note #%{note_name}" hidden_title: "Hidden note #%{note_name}" description_when_author_is_deleted: "deleted" + description_when_there_is_no_opening_comment: "unknown" event_opened_by_html: "Created by %{user} %{time_ago}" event_opened_by_anonymous_html: "Created by anonymous %{time_ago}" event_commented_by_html: "Comment from %{user} %{time_ago}" diff --git a/test/controllers/notes_controller_test.rb b/test/controllers/notes_controller_test.rb index a70bb32cd..0185c6741 100644 --- a/test/controllers/notes_controller_test.rb +++ b/test/controllers/notes_controller_test.rb @@ -164,7 +164,7 @@ class NotesControllerTest < ActionDispatch::IntegrationTest def test_read_note_suspended_opener_and_comment note = create(:note) create(:note_comment, :note => note, :author => create(:user, :suspended)) - create(:note_comment, :note => note) + create(:note_comment, :note => note, :event => "commented") sidebar_browse_check :note_path, note.id, "notes/show" assert_select "div.note-comments ul li", :count => 1