2013-12-11 21:41:34 -05:00
|
|
|
class PostRevisionSerializer < ApplicationSerializer
|
|
|
|
attributes :post_id,
|
|
|
|
:version,
|
|
|
|
:revisions_count,
|
|
|
|
:username,
|
|
|
|
:display_username,
|
|
|
|
:avatar_template,
|
|
|
|
:created_at,
|
|
|
|
:edit_reason,
|
2014-03-07 02:59:47 -05:00
|
|
|
:body_changes,
|
|
|
|
:title_changes,
|
2014-03-27 21:28:14 -04:00
|
|
|
:category_changes,
|
2014-05-13 08:53:11 -04:00
|
|
|
:user_changes,
|
|
|
|
:wiki_changes
|
2014-03-07 02:59:47 -05:00
|
|
|
|
|
|
|
def include_title_changes?
|
|
|
|
object.has_topic_data?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_category_changes?
|
|
|
|
object.has_topic_data?
|
|
|
|
end
|
2013-12-11 21:41:34 -05:00
|
|
|
|
|
|
|
def version
|
|
|
|
object.number
|
|
|
|
end
|
|
|
|
|
|
|
|
def revisions_count
|
|
|
|
object.post.version
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
2014-03-07 02:59:47 -05:00
|
|
|
user.username_lower
|
2013-12-11 21:41:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_username
|
2014-03-07 02:59:47 -05:00
|
|
|
user.username
|
2013-12-11 21:41:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_template
|
2014-03-07 02:59:47 -05:00
|
|
|
user.avatar_template
|
2013-12-11 21:41:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit_reason
|
2014-03-14 12:25:02 -04:00
|
|
|
object.lookup("edit_reason", 1)
|
2013-12-11 21:41:34 -05:00
|
|
|
end
|
|
|
|
|
2014-03-27 21:28:14 -04:00
|
|
|
def user_changes
|
|
|
|
obj = object.user_changes
|
|
|
|
return unless obj
|
|
|
|
# same as below - if stuff is messed up, default to system
|
|
|
|
prev = obj[:previous_user] || Discourse.system_user
|
|
|
|
new = obj[:current_user] || Discourse.system_user
|
|
|
|
{
|
|
|
|
previous: {
|
|
|
|
username: prev.username_lower,
|
|
|
|
display_username: prev.username,
|
|
|
|
avatar_template: prev.avatar_template
|
|
|
|
},
|
|
|
|
current: {
|
|
|
|
username: new.username_lower,
|
|
|
|
display_username: new.username,
|
|
|
|
avatar_template: new.avatar_template
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-03-07 02:59:47 -05:00
|
|
|
def user
|
|
|
|
# if stuff goes pear shape attribute to system
|
|
|
|
object.user || Discourse.system_user
|
2013-12-11 21:41:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|