discourse/app/serializers/post_revision_serializer.rb

52 lines
903 B
Ruby
Raw Normal View History

2013-12-12 10:41:34 +08:00
class PostRevisionSerializer < ApplicationSerializer
attributes :post_id,
:version,
:revisions_count,
:username,
:display_username,
:avatar_template,
:created_at,
:edit_reason,
:body_changes,
:title_changes,
:category_changes
def include_title_changes?
object.has_topic_data?
end
def include_category_changes?
object.has_topic_data?
end
2013-12-12 10:41:34 +08:00
def version
object.number
end
def revisions_count
object.post.version
end
def username
user.username_lower
2013-12-12 10:41:34 +08:00
end
def display_username
user.username
2013-12-12 10:41:34 +08:00
end
def avatar_template
user.avatar_template
2013-12-12 10:41:34 +08:00
end
def edit_reason
object.lookup("edit_reason", 1)
2013-12-12 10:41:34 +08:00
end
def user
# if stuff goes pear shape attribute to system
object.user || Discourse.system_user
2013-12-12 10:41:34 +08:00
end
end