2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-23 03:53:08 +08:00
|
|
|
class ApiKeySerializer < ApplicationSerializer
|
|
|
|
attributes :id,
|
2019-10-09 21:24:14 +08:00
|
|
|
:key,
|
2019-12-12 19:45:00 +08:00
|
|
|
:truncated_key,
|
2019-11-05 22:10:23 +08:00
|
|
|
:description,
|
2019-10-09 21:24:14 +08:00
|
|
|
:last_used_at,
|
2019-11-05 22:10:23 +08:00
|
|
|
:created_at,
|
|
|
|
:updated_at,
|
|
|
|
:revoked_at
|
2013-10-23 03:53:08 +08:00
|
|
|
|
|
|
|
has_one :user, serializer: BasicUserSerializer, embed: :objects
|
2020-07-17 02:51:24 +08:00
|
|
|
has_many :api_key_scopes, serializer: ApiKeyScopeSerializer, embed: :objects
|
2013-10-23 03:53:08 +08:00
|
|
|
|
|
|
|
def include_user_id?
|
|
|
|
!object.user_id.nil?
|
|
|
|
end
|
|
|
|
|
2019-12-12 19:45:00 +08:00
|
|
|
def include_key?
|
|
|
|
# Only available when first created. Not stored in db
|
|
|
|
object.key_available?
|
|
|
|
end
|
2013-10-23 03:53:08 +08:00
|
|
|
end
|