]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'pull/5579'
authorAnton Khorev <tony29@yandex.ru>
Tue, 4 Feb 2025 13:42:00 +0000 (16:42 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 4 Feb 2025 13:42:00 +0000 (16:42 +0300)
app/helpers/note_helper.rb
app/models/note.rb
app/views/api/notes/_note.rss.builder
app/views/notes/index.html.erb
app/views/notes/show.html.erb
config/locales/en.yml

index 2e9850aef060f2b6549de5cdecac599d95fbdd9a..0ba5032288b7c7b7ebb9803a00fc230506372775 100644 (file)
@@ -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",
index 376516e9b4e8841a0ef9f132102d41ec2fd04c36..d37b863e53b5a77224375fc48990860144171cfe 100644 (file)
@@ -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 @@ class Note < ApplicationRecord
 
   # 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
index fa70536f79227a5cdaa4a5954c6c5076022c6125..0bfdb385de41cafda4fbb1bfcb96f06b6bc13c92 100644 (file)
@@ -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
index f805a10402b413aa295875010a051b7ecbbef76f..0b39234a93e61f2eaf222b0e221906f48bf8c567 100644 (file)
@@ -48,7 +48,7 @@
       </td>
       <td><%= link_to note.id, note %></td>
       <td><%= note_author(note.author) %></td>
-      <td><%= note.description.to_html %></td>
+      <td><%= note_description(note.author, note.description).to_html %></td>
       <td><%= friendly_date_ago(note.created_at) %></td>
       <td><%= friendly_date_ago(note.updated_at) %></td>
     </tr>
index a320240488e716224a8908bbed5b612988e7907e..3d9b4a9bace5aafa7d1a378abc6da3ed1a0bf54e 100644 (file)
@@ -5,7 +5,7 @@
 <div>
   <h4><%= t(".description") %></h4>
   <div class="overflow-hidden ms-2">
-    <%= h(@note.description.to_html) %>
+    <%= h(note_description(@note.author, @note.description).to_html) %>
   </div>
 
   <div class="details" data-coordinates="<%= @note.lat %>,<%= @note.lon %>" data-status="<%= @note.status %>">
index a4910a544d4cf705e1cdb85de650a6399b403e57..40b4bfa142997eaa20c2eabba88093012d753dee 100644 (file)
@@ -3069,6 +3069,7 @@ en:
       open_title: "Unresolved note #%{note_name}"
       closed_title: "Resolved note #%{note_name}"
       hidden_title: "Hidden note #%{note_name}"
+      description_when_author_is_deleted: "deleted"
       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}"