Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug when deleted user's note lacks comments #5609

Merged
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
4 changes: 4 additions & 0 deletions app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def show
@note = Note.visible.find(params[:id])
@note_comments = @note.comments
end

@note_includes_anonymous = @note.author.nil? || @note_comments.find { |comment| comment.author.nil? }

@note_comments = @note_comments.drop(1) unless !@note.author.nil? && @note.author.status == "deleted"
rescue ActiveRecord::RecordNotFound
render :template => "browse/not_found", :status => :not_found
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def freshly_closed_until
# Return the note's description, derived from the first comment
def description
if user_ip.nil? && user_id.nil?
comments.first.body
all_comments.first.body
else
RichText.new("text", super)
end
Expand All @@ -103,7 +103,7 @@ def description
# Return the note's author object, derived from the first comment
def author
if user_ip.nil? && user_id.nil?
comments.first.author
all_comments.first.author
else
super
end
Expand Down
6 changes: 3 additions & 3 deletions app/views/notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</p>
</div>

<% if @note_comments.find { |comment| comment.author.nil? } -%>
<% if @note_includes_anonymous -%>
<p class='alert alert-warning'><%= t ".anonymous_warning" %></p>
<% end -%>

Expand Down Expand Up @@ -52,10 +52,10 @@
<% end %>
</div>

<% if @note_comments.length > 1 %>
<% if @note_comments.length > 0 %>
<div class='note-comments'>
<ul class="list-unstyled">
<% @note_comments.drop(1).each do |comment| %>
<% @note_comments.each do |comment| %>
<li id="c<%= comment.id %>">
<small class='text-body-secondary'><%= note_event(comment.event, comment.created_at, comment.author) %></small>
<div class="mx-2">
Expand Down