diff --git a/app/models/note.rb b/app/models/note.rb index fefee9b85c..8be2b0c28f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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