]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5712'
authorTom Hughes <tom@compton.nu>
Fri, 21 Feb 2025 18:00:06 +0000 (18:00 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 21 Feb 2025 18:00:06 +0000 (18:00 +0000)
app/controllers/notes_controller.rb
app/helpers/note_helper.rb
app/models/note.rb
app/views/notes/index.html.erb
app/views/notes/show.html.erb
config/locales/en.yml
test/controllers/notes_controller_test.rb

index 5d817c9c6cf3f525d4669de10174332978f3e6f0..fbeb01b76425b890f4b69dd603ddf96e255abf8c 100644 (file)
@@ -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
index 0ba5032288b7c7b7ebb9803a00fc230506372775..7a75a4ff53c22ea2b0da5816978e03bf8846ea1a 100644 (file)
@@ -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
index b7215d6f7706084318ecefcd845d303771f14fc9..0a1f4abd7fed5594c0560180d5c77163a4066a02 100644 (file)
@@ -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
index 0b39234a93e61f2eaf222b0e221906f48bf8c567..4bd7d499d3da7acec77a8996842a450e662c5e26 100644 (file)
@@ -48,7 +48,7 @@
       </td>
       <td><%= link_to note.id, note %></td>
       <td><%= note_author(note.author) %></td>
-      <td><%= note_description(note.author, note.description).to_html %></td>
+      <td><%= note_description(note.author, note.description, current_user&.moderator? ? note.comments.unscope(:where => :visible).first : note.comments.first).to_html %></td>
       <td><%= friendly_date_ago(note.created_at) %></td>
       <td><%= friendly_date_ago(note.updated_at) %></td>
     </tr>
index b65926b5f9df335fd7abbcfda573cfef93ad8c8c..d0dcdeb1b9417354c01f5e9830011b8d980a876b 100644 (file)
@@ -5,7 +5,7 @@
 <div>
   <h4><%= t(".description") %></h4>
   <div class="overflow-hidden ms-2">
-    <%= 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 %>
   </div>
 
   <div class="details" data-coordinates="<%= @note.lat %>,<%= @note.lon %>" data-status="<%= @note.status %>">
index dd7ae4033841195b001ab689f0757bdc5d50bd32..f03a6eeb1f6ae418100d83b6c16aa4e8fae4be19 100644 (file)
@@ -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}"
index a70bb32cd7789d33ae680e2d7a52693aaae68667..0185c67413141d954b88951e220800e72518ed24 100644 (file)
@@ -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