2017-06-21 12:56:38 -04:00
|
|
|
require_relative 'post_item_excerpt'
|
|
|
|
|
2017-06-20 14:41:41 -04:00
|
|
|
class AdminUserActionSerializer < ApplicationSerializer
|
2017-06-21 12:56:38 -04:00
|
|
|
include PostItemExcerpt
|
2017-06-20 14:41:41 -04:00
|
|
|
|
|
|
|
attributes(
|
|
|
|
:id,
|
|
|
|
:created_at,
|
|
|
|
:post_number,
|
2017-06-20 15:45:26 -04:00
|
|
|
:post_id,
|
2017-06-20 14:41:41 -04:00
|
|
|
:name,
|
|
|
|
:username,
|
|
|
|
:avatar_template,
|
|
|
|
:topic_id,
|
|
|
|
:slug,
|
|
|
|
:title,
|
|
|
|
:category_id,
|
2017-06-20 15:45:26 -04:00
|
|
|
:truncated,
|
2017-06-20 14:41:41 -04:00
|
|
|
:hidden,
|
|
|
|
:moderator_action,
|
|
|
|
:deleted,
|
|
|
|
:deleted_at,
|
|
|
|
:deleted_by,
|
|
|
|
:reply_to_post_number,
|
|
|
|
:action_type
|
|
|
|
)
|
|
|
|
|
2017-06-20 15:45:26 -04:00
|
|
|
def post_id
|
|
|
|
object.id
|
|
|
|
end
|
|
|
|
|
2017-06-20 14:41:41 -04:00
|
|
|
def deleted
|
|
|
|
deleted_at.present?
|
|
|
|
end
|
2014-07-16 15:04:55 -04:00
|
|
|
|
|
|
|
def name
|
|
|
|
object.user.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_name?
|
|
|
|
SiteSetting.enable_names?
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
object.user.username
|
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_template
|
|
|
|
object.user.avatar_template
|
|
|
|
end
|
|
|
|
|
2017-06-20 14:41:41 -04:00
|
|
|
def slug
|
2014-07-16 15:04:55 -04:00
|
|
|
topic.slug
|
|
|
|
end
|
|
|
|
|
2017-06-20 14:41:41 -04:00
|
|
|
def title
|
2014-07-16 15:04:55 -04:00
|
|
|
topic.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def category_id
|
|
|
|
topic.category_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def moderator_action
|
2015-07-24 16:39:03 -04:00
|
|
|
object.post_type == Post.types[:moderator_action] || object.post_type == Post.types[:small_action]
|
2014-07-16 15:04:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def deleted_by
|
|
|
|
BasicUserSerializer.new(object.deleted_by, root: false).as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_deleted_by?
|
|
|
|
object.trashed?
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_type
|
|
|
|
object.user_actions.select { |ua| ua.user_id = object.user_id }
|
2017-07-27 21:20:09 -04:00
|
|
|
.select { |ua| [UserAction::REPLY, UserAction::RESPONSE].include? ua.action_type }
|
|
|
|
.first.try(:action_type)
|
2014-07-16 15:04:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# we need this to handle deleted topics which aren't loaded via the .includes(:topic)
|
|
|
|
# because Rails 4 "unscoped" support is bugged (cf. https://github.com/rails/rails/issues/13775)
|
|
|
|
def topic
|
|
|
|
return @topic if @topic
|
|
|
|
@topic = object.topic || Topic.with_deleted.find(object.topic_id)
|
|
|
|
@topic
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|