Skip to content

Commit

Permalink
Adds optional use of notes records
Browse files Browse the repository at this point in the history
Adds use of description, user_id, user_ip from notes table if data-migration is done, otherwise use body, author_id, author_ip from note's first comment. Decision procedure "data-migration is done" is defined with "is user_ip or user_id not nil?".
  • Loading branch information
nenad-vujicic committed Jan 17, 2025
1 parent 3eccf65 commit eb32ddd
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,39 @@ def freshly_closed_until
closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
end

# Return the note's description, derived from the first comment
# 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?
comments.first.body
else
RichText.new("text", description)
end
end

# Return the note's author object, derived from the first comment
def author
comments.first.author
end

# Return the note's author ID, derived from the first comment
# Return the note's author ID, unless record is unavailable and
# it will be derived from the first comment
def author_id
comments.first.author_id
if user_ip.nil? && user_id.nil?
comments.first.author_id
else
user_id
end
end

# Return the note's author IP address, derived from the first comment
# Return the note's author IP address, unless record is unavailable and
# it will be derived from the first comment
def author_ip
comments.first.author_ip
if user_ip.nil? && user_id.nil?
comments.first.author_ip
else
user_ip
end
end

private
Expand Down

0 comments on commit eb32ddd

Please sign in to comment.