mirror of
https://github.com/internetee/registry.git
synced 2025-07-27 13:06:18 +02:00
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
module Serializers
|
|
module Repp
|
|
class ApiUser
|
|
attr_reader :user
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
def to_json(obj = user)
|
|
json = {
|
|
id: obj.id,
|
|
name: obj.username,
|
|
password: obj.plain_text_password,
|
|
identity_code: obj.identity_code,
|
|
roles: obj.roles.join(', '),
|
|
active: obj.active,
|
|
accredited: obj.accredited?,
|
|
accreditation_expired: obj.accreditation_expired?,
|
|
accreditation_expire_date: obj.accreditation_expire_date,
|
|
created_at: obj.created_at,
|
|
updated_at: obj.updated_at,
|
|
creator: obj.creator_str,
|
|
updator: obj.updator_str,
|
|
}
|
|
json[:certificates] = certificates
|
|
json
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
private
|
|
|
|
def certificates
|
|
user.certificates.map do |x|
|
|
subject = x.csr ? x.parsed_csr.try(:subject) : x.parsed_crt.try(:subject)
|
|
{ subject: subject.to_s, status: x.status }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|