discourse/app/serializers/user_action_serializer.rb

89 lines
2.0 KiB
Ruby
Raw Normal View History

class UserActionSerializer < ApplicationSerializer
attributes :action_type,
:created_at,
:excerpt,
:avatar_template,
:acting_avatar_template,
:slug,
:topic_id,
:target_user_id,
:target_name,
:target_username,
:post_number,
:reply_to_post_number,
:username,
:name,
:user_id,
:acting_username,
:acting_name,
:acting_user_id,
:title,
:deleted,
2013-07-19 05:24:51 +08:00
:hidden,
2013-12-12 10:41:34 +08:00
:moderator_action,
:edit_reason
def excerpt
PrettyText.excerpt(object.cooked, 300) if object.cooked
end
def avatar_template
2013-08-06 04:25:44 +08:00
avatar_for(
object.user_id,
2013-08-06 04:25:44 +08:00
object.email,
object.use_uploaded_avatar,
object.uploaded_avatar_template,
object.uploaded_avatar_id
)
end
def acting_avatar_template
2013-08-06 04:25:44 +08:00
avatar_for(
object.acting_user_id,
object.acting_email,
object.acting_use_uploaded_avatar,
object.acting_uploaded_avatar_template,
object.acting_uploaded_avatar_id
2013-08-06 04:25:44 +08:00
)
end
def include_name?
SiteSetting.enable_names?
end
def include_target_name?
include_name?
end
def include_acting_name?
include_name?
end
def slug
Slug.for(object.title)
end
2013-07-19 05:24:51 +08:00
def moderator_action
object.post_type == Post.types[:moderator_action]
end
def edit_reason
object.edit_reason if object.action_type == UserAction::EDIT
end
2013-08-06 04:25:44 +08:00
private
def avatar_for(user_id, email, use_uploaded_avatar, uploaded_avatar_template, uploaded_avatar_id)
2013-08-06 04:25:44 +08:00
# NOTE: id is required for cases where the template is blank (during initial population)
User.new(
id: user_id,
2013-08-06 04:25:44 +08:00
email: email,
use_uploaded_avatar: use_uploaded_avatar,
uploaded_avatar_template: uploaded_avatar_template,
uploaded_avatar_id: uploaded_avatar_id
).avatar_template
end
end