2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-09-10 21:21:16 -04:00
|
|
|
class UserHistorySerializer < ApplicationSerializer
|
2013-08-07 16:04:12 -04:00
|
|
|
attributes :action_name,
|
|
|
|
:details,
|
|
|
|
:context,
|
|
|
|
:ip_address,
|
|
|
|
:email,
|
2013-08-19 16:58:38 -04:00
|
|
|
:created_at,
|
|
|
|
:subject,
|
|
|
|
:previous_value,
|
2014-10-01 11:40:13 -04:00
|
|
|
:new_value,
|
|
|
|
:topic_id,
|
2015-02-05 14:34:57 -05:00
|
|
|
:post_id,
|
2015-09-17 03:51:32 -04:00
|
|
|
:category_id,
|
2015-02-05 14:34:57 -05:00
|
|
|
:action,
|
2017-04-12 10:52:52 -04:00
|
|
|
:custom_type,
|
|
|
|
:id
|
2013-08-07 16:04:12 -04:00
|
|
|
|
2013-09-10 21:21:16 -04:00
|
|
|
has_one :acting_user, serializer: BasicUserSerializer, embed: :objects
|
2013-08-07 16:04:12 -04:00
|
|
|
has_one :target_user, serializer: BasicUserSerializer, embed: :objects
|
|
|
|
|
|
|
|
def action_name
|
2015-02-05 14:34:57 -05:00
|
|
|
key = UserHistory.actions.key(object.action)
|
|
|
|
%i[custom custom_staff].include?(key) ? object.custom_type : key.to_s
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|
2013-08-21 10:49:35 -04:00
|
|
|
|
|
|
|
def new_value
|
|
|
|
if object.new_value
|
|
|
|
object.new_value_is_json? ? ::JSON.parse(object.new_value) : object.new_value
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_value
|
|
|
|
if object.previous_value
|
|
|
|
object.previous_value_is_json? ? ::JSON.parse(object.previous_value) : object.previous_value
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2014-10-01 11:40:13 -04:00
|
|
|
end
|