Skip to content

Commit

Permalink
Added optional using records from notes table
Browse files Browse the repository at this point in the history
Added using records (description, user_id, user_ip) from notes table if migration is done, otherwise, use values from note's first comment.
  • Loading branch information
nenad-vujicic committed Jan 15, 2025
1 parent 7a72208 commit 7a38f64
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,48 @@ def freshly_closed_until
closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
end

# Return the author object, derived from the first comment
# Return the note's description,
# derived from the first comment if migration is not performed,
# otherwise from DB record
def description
if self[:user_id].nil? && self[:user_ip].nil?
comments.first.body
else
RichText.new("text", self[:description])
end
end

# Return the note's author object,
# derived from the first comment if migration is not performed,
# otherwise using appropriate DB record
def author
comments.first.author
if self[:user_id].nil? && self[:user_ip].nil?
comments.first.author
else
author
end
end

# Return the note's author ID,
# derived from the first comment if migration is not performed,
# otherwise from DB record
def author_id
if self[:user_id].nil? && self[:user_ip].nil?
comments.first.author_id
else
self[:user_id]
end
end

# Return the author IP address, derived from the first comment
# Return the note's author IP address,
# derived from the first comment if migration is not performed,
# otherwise from DB record
def author_ip
comments.first.author_ip
if self[:user_id].nil? && self[:user_ip].nil?
comments.first.author_ip
else
self[:user_ip]
end
end

private
Expand Down

0 comments on commit 7a38f64

Please sign in to comment.