2013-09-11 09:21:16 +08:00
|
|
|
class UserHistorySerializer < ApplicationSerializer
|
2013-08-08 04:04:12 +08:00
|
|
|
attributes :action_name,
|
|
|
|
:details,
|
|
|
|
:context,
|
|
|
|
:ip_address,
|
|
|
|
:email,
|
2013-08-20 04:58:38 +08:00
|
|
|
:created_at,
|
|
|
|
:subject,
|
|
|
|
:previous_value,
|
|
|
|
:new_value
|
2013-08-08 04:04:12 +08:00
|
|
|
|
2013-09-11 09:21:16 +08:00
|
|
|
has_one :acting_user, serializer: BasicUserSerializer, embed: :objects
|
2013-08-08 04:04:12 +08:00
|
|
|
has_one :target_user, serializer: BasicUserSerializer, embed: :objects
|
|
|
|
|
|
|
|
def action_name
|
2013-09-11 09:21:16 +08:00
|
|
|
UserHistory.actions.key(object.action).to_s
|
2013-08-08 04:04:12 +08:00
|
|
|
end
|
2013-08-21 22:49:35 +08: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
|
2013-08-08 04:04:12 +08:00
|
|
|
end
|