diff --git a/app/helpers/note_helper.rb b/app/helpers/note_helper.rb index 2e9850aef0..0ba5032288 100644 --- a/app/helpers/note_helper.rb +++ b/app/helpers/note_helper.rb @@ -1,6 +1,14 @@ module NoteHelper include ActionView::Helpers::TranslationHelper + def note_description(author, description) + if !author.nil? && author.status == "deleted" + RichText.new("text", t("notes.show.description_when_author_is_deleted")) + else + description + end + end + def note_event(event, at, by) if by.nil? t("notes.show.event_#{event}_by_anonymous_html", diff --git a/app/models/note.rb b/app/models/note.rb index 376516e9b4..d37b863e53 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -28,6 +28,8 @@ class Note < ApplicationRecord include GeoRecord + belongs_to :author, :class_name => "User", :foreign_key => "user_id", :optional => true + has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id has_many :all_comments, -> { left_joins(:author).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id, :inverse_of => :note has_many :subscriptions, :class_name => "NoteSubscription" @@ -91,12 +93,20 @@ def freshly_closed_until # Return the note's description, derived from the first comment def description - comments.first.body + if user_ip.nil? && user_id.nil? + comments.first.body + else + RichText.new("text", super) + end end # Return the note's author object, derived from the first comment def author - comments.first.author + if user_ip.nil? && user_id.nil? + comments.first.author + else + super + end end private diff --git a/app/views/api/notes/_note.rss.builder b/app/views/api/notes/_note.rss.builder index fa70536f79..0bfdb385de 100644 --- a/app/views/api/notes/_note.rss.builder +++ b/app/views/api/notes/_note.rss.builder @@ -13,7 +13,7 @@ xml.item do xml.guid api_note_url(note) xml.description render(:partial => "description", :object => note, :formats => [:html]) - xml.dc :creator, note.author.display_name if note.author + xml.dc :creator, note.author.display_name unless note.author.nil? || note.author.status == "deleted" xml.pubDate note.created_at.to_fs(:rfc822) xml.geo :lat, note.lat diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index f805a10402..0b39234a93 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -48,7 +48,7 @@