From 690d392bd866a411bed93aded9b18f884bcfcc21 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 23 Jan 2025 16:24:04 +0100 Subject: [PATCH 1/6] Adds optional using of notes records Adds author association and optional use of note's records. If data-migration is done, real note's author (description) is returned, otherwise if data-migration is not done, first note's comment author (body) is returned. Adds method author_deleted? for encapsulating checking if note's author is deleted. --- app/models/note.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index 376516e9b4..625b3f118c 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" @@ -89,14 +91,28 @@ def freshly_closed_until closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT end - # Return the note's description, derived from the first comment + def author_deleted? + !author.nil? && author.status == "deleted" + end + + # Return the note's description, unless record is unavailable and + # it will be derived from the first comment def description - comments.first.body + if user_ip.nil? && user_id.nil? + all_comments.first.body + else + RichText.new("text", super) + end end - # Return the note's author object, derived from the first comment + # Return the note's author object, unless record is unavailable and + # it will be derived from the first comment def author - comments.first.author + if user_ip.nil? && user_id.nil? + all_comments.first.author + else + super + end end private From 9e70276e1997d22e7e4cf496b87157749bb9e468 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 23 Jan 2025 16:16:51 +0100 Subject: [PATCH 2/6] Adds helper routine note_description Adds new helper routine note_description for retrieving note's description. Helper routine returns "deleted" if author is deleted, first comment's body if data-migration is not done or note's description record if data-migration is done. --- app/helpers/note_helper.rb | 8 ++++++++ config/locales/en.yml | 1 + 2 files changed, 9 insertions(+) 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/config/locales/en.yml b/config/locales/en.yml index a4910a544d..40b4bfa142 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}" From 38fde849ca894f1d8f21118bf2c7730c76c178a2 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 23 Jan 2025 16:18:36 +0100 Subject: [PATCH 3/6] Replaces using description with note_description Replaces using note's description method with note_description helper routine. --- app/views/notes/index.html.erb | 2 +- app/views/notes/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 @@ <%= link_to note.id, note %> <%= note_author(note.author) %> - <%= note.description.to_html %> + <%= note_description(note.author, note.description).to_html %> <%= friendly_date_ago(note.created_at) %> <%= friendly_date_ago(note.updated_at) %> diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index a320240488..3d9b4a9bac 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -5,7 +5,7 @@

<%= t(".description") %>

- <%= h(@note.description.to_html) %> + <%= h(note_description(@note.author, @note.description).to_html) %>
From ce61e316e3678709922c3feaf4ec461aab235409 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 23 Jan 2025 16:31:20 +0100 Subject: [PATCH 4/6] Removes note's author from RSS Removes writing note's author to note's RSS if note's author is deleted. --- app/views/api/notes/_note.rss.builder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/notes/_note.rss.builder b/app/views/api/notes/_note.rss.builder index fa70536f79..3deca386e5 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_deleted? xml.pubDate note.created_at.to_fs(:rfc822) xml.geo :lat, note.lat From 0e60e2e71579dff7b7b163f08bafd278deb9caae Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Fri, 24 Jan 2025 12:46:35 +0100 Subject: [PATCH 5/6] Removes dropping note's first comment Removes dropping note's first visible comment in case of deleted note's author. After adding displaying "deleted" as note's description, first visible comment is now displayed as note's comments. --- app/views/notes/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/notes/show.html.erb b/app/views/notes/show.html.erb index 3d9b4a9bac..4a52e9b375 100644 --- a/app/views/notes/show.html.erb +++ b/app/views/notes/show.html.erb @@ -52,10 +52,10 @@ <% end %>
- <% if @note_comments.length > 1 %> + <% if @note_comments.length > (@note.author_deleted? ? 0 : 1) %>
    - <% @note_comments.drop(1).each do |comment| %> + <% @note_comments.drop(@note.author_deleted? ? 0 : 1).each do |comment| %>
  • <%= note_event(comment.event, comment.created_at, comment.author) %>
    From 3d2870c146803e52269b6a9cb6ebede89fecb8c4 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 30 Jan 2025 11:57:25 +0100 Subject: [PATCH 6/6] Don't add title to note marker if note has no visible comments Based on #3617. --- app/assets/javascripts/index/layers/notes.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/index/layers/notes.js b/app/assets/javascripts/index/layers/notes.js index 24bf969b33..5391f3ef77 100644 --- a/app/assets/javascripts/index/layers/notes.js +++ b/app/assets/javascripts/index/layers/notes.js @@ -44,10 +44,13 @@ OSM.initializeNotesLayer = function (map) { marker.setIcon(noteIcons[feature.properties.status]); } else { let title; - const description = feature.properties.comments[0]; - if (description?.action === "opened") { - title = description.text; + if (feature.properties.comments.length > 0) { + const description = feature.properties.comments[0]; + + if (description?.action === "opened") { + title = description.text; + } } marker = L.marker(feature.geometry.coordinates.reverse(), {