@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
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
# 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
# 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
</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>
<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 %>">
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}"
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