2013-05-26 20:22:37 -04:00
|
|
|
class UserActionSerializer < ApplicationSerializer
|
|
|
|
|
2013-05-28 10:20:19 -04:00
|
|
|
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,
|
2013-06-11 21:14:08 -04:00
|
|
|
:title,
|
|
|
|
:deleted,
|
2013-07-18 17:24:51 -04:00
|
|
|
:hidden,
|
2013-12-11 21:41:34 -05:00
|
|
|
:moderator_action,
|
2014-05-26 13:49:57 -04:00
|
|
|
:edit_reason,
|
|
|
|
:category_id
|
2013-05-26 20:22:37 -04:00
|
|
|
|
|
|
|
def excerpt
|
2013-12-27 10:59:50 -05:00
|
|
|
PrettyText.excerpt(object.cooked, 300) if object.cooked
|
2013-05-26 20:22:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_template
|
2013-08-05 16:25:44 -04:00
|
|
|
avatar_for(
|
2014-01-29 12:17:58 -05:00
|
|
|
object.user_id,
|
2013-08-05 16:25:44 -04:00
|
|
|
object.email,
|
|
|
|
object.use_uploaded_avatar,
|
|
|
|
object.uploaded_avatar_template,
|
|
|
|
object.uploaded_avatar_id
|
|
|
|
)
|
2013-05-26 20:22:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def acting_avatar_template
|
2013-08-05 16:25:44 -04:00
|
|
|
avatar_for(
|
2014-01-29 12:17:58 -05:00
|
|
|
object.acting_user_id,
|
2013-12-27 10:59:50 -05:00
|
|
|
object.acting_email,
|
|
|
|
object.acting_use_uploaded_avatar,
|
|
|
|
object.acting_uploaded_avatar_template,
|
|
|
|
object.acting_uploaded_avatar_id
|
2013-08-05 16:25:44 -04:00
|
|
|
)
|
2013-05-26 20:22:37 -04:00
|
|
|
end
|
|
|
|
|
2013-12-08 09:01:25 -05:00
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_target_name?
|
|
|
|
include_name?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_acting_name?
|
|
|
|
include_name?
|
|
|
|
end
|
|
|
|
|
2013-05-26 20:22:37 -04:00
|
|
|
def slug
|
|
|
|
Slug.for(object.title)
|
|
|
|
end
|
|
|
|
|
2013-07-18 17:24:51 -04:00
|
|
|
def moderator_action
|
|
|
|
object.post_type == Post.types[:moderator_action]
|
|
|
|
end
|
|
|
|
|
2014-05-09 11:49:39 -04:00
|
|
|
def include_reply_to_post_number?
|
|
|
|
object.action_type == UserAction::REPLY
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_edit_reason?
|
|
|
|
object.action_type == UserAction::EDIT
|
2013-12-27 10:59:50 -05:00
|
|
|
end
|
|
|
|
|
2013-08-05 16:25:44 -04:00
|
|
|
private
|
2013-12-27 10:59:50 -05:00
|
|
|
|
2014-01-29 12:17:58 -05:00
|
|
|
def avatar_for(user_id, email, use_uploaded_avatar, uploaded_avatar_template, uploaded_avatar_id)
|
2013-08-05 16:25:44 -04:00
|
|
|
# NOTE: id is required for cases where the template is blank (during initial population)
|
|
|
|
User.new(
|
2014-01-29 12:17:58 -05:00
|
|
|
id: user_id,
|
2013-08-05 16:25:44 -04:00
|
|
|
email: email,
|
|
|
|
use_uploaded_avatar: use_uploaded_avatar,
|
|
|
|
uploaded_avatar_template: uploaded_avatar_template,
|
|
|
|
uploaded_avatar_id: uploaded_avatar_id
|
|
|
|
).avatar_template
|
|
|
|
end
|
|
|
|
|
2013-05-26 20:22:37 -04:00
|
|
|
end
|