Skip to content

Commit 58971ce

Browse files
committed
Adds optional use of notes records
Adds use of description and author from notes table if data-migration is done, otherwise use body and author from note's first comment. Decision procedure "data-migration is done" is defined with "is user_ip or user_id not nil?". If author is deleted, "deleted" is displayed.
1 parent 7b19ba5 commit 58971ce

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

app/models/note.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
class Note < ApplicationRecord
2929
include GeoRecord
3030

31+
belongs_to :author, :class_name => "User", :foreign_key => "user_id", :optional => true
32+
3133
has_many :comments, -> { left_joins(:author).where(:visible => true, :users => { :status => [nil, "active", "confirmed"] }).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id
3234
has_many :all_comments, -> { left_joins(:author).order(:created_at) }, :class_name => "NoteComment", :foreign_key => :note_id, :inverse_of => :note
3335
has_many :subscriptions, :class_name => "NoteSubscription"
@@ -89,24 +91,27 @@ def freshly_closed_until
8991
closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
9092
end
9193

92-
# Return the note's description, derived from the first comment
94+
# Return the note's description, unless record is unavailable and
95+
# it will be derived from the first comment. If note's author is
96+
# deleted, "deleted" will be returned
9397
def description
94-
comments.first.body
98+
if !author.nil? && author.status == "deleted"
99+
RichText.new("text", I18n.t("notes.show.description_when_author_is_deleted"))
100+
elsif user_ip.nil? && user_id.nil?
101+
comments.first.body
102+
else
103+
RichText.new("text", self[:description])
104+
end
95105
end
96106

97-
# Return the note's author object, derived from the first comment
107+
# Return the note's author object, unless record is unavailable and
108+
# it will be derived from the first comment
98109
def author
99-
comments.first.author
100-
end
101-
102-
# Return the note's author ID, derived from the first comment
103-
def author_id
104-
comments.first.author_id
105-
end
106-
107-
# Return the note's author IP address, derived from the first comment
108-
def author_ip
109-
comments.first.author_ip
110+
if user_ip.nil? && user_id.nil?
111+
all_comments.first.author
112+
else
113+
self[:author]
114+
end
110115
end
111116

112117
private

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,7 @@ en:
30613061
open_title: "Unresolved note #%{note_name}"
30623062
closed_title: "Resolved note #%{note_name}"
30633063
hidden_title: "Hidden note #%{note_name}"
3064+
description_when_author_is_deleted: "deleted"
30643065
event_opened_by_html: "Created by %{user} %{time_ago}"
30653066
event_opened_by_anonymous_html: "Created by anonymous %{time_ago}"
30663067
event_commented_by_html: "Comment from %{user} %{time_ago}"

0 commit comments

Comments
 (0)