account_serializer.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. class REST::Admin::AccountSerializer < ActiveModel::Serializer
  3. attributes :id, :username, :domain, :created_at,
  4. :email, :ip, :confirmed, :suspended,
  5. :silenced, :sensitized, :disabled, :approved, :locale,
  6. :invite_request
  7. attribute :created_by_application_id, if: :created_by_application?
  8. attribute :invited_by_account_id, if: :invited?
  9. has_many :ips, serializer: REST::Admin::IpSerializer
  10. has_one :account, serializer: REST::AccountSerializer
  11. has_one :role, serializer: REST::RoleSerializer
  12. def id
  13. object.id.to_s
  14. end
  15. def email
  16. object.user_email
  17. end
  18. def role
  19. object.user_role
  20. end
  21. def suspended
  22. object.suspended?
  23. end
  24. def silenced
  25. object.silenced?
  26. end
  27. def sensitized
  28. object.sensitized?
  29. end
  30. def confirmed
  31. object.user_confirmed?
  32. end
  33. def disabled
  34. object.user_disabled?
  35. end
  36. def approved
  37. object.user_approved?
  38. end
  39. def account
  40. object
  41. end
  42. def locale
  43. object.user_locale
  44. end
  45. def created_by_application_id
  46. object.user&.created_by_application_id&.to_s&.presence
  47. end
  48. def invite_request
  49. object.user&.invite_request&.text
  50. end
  51. def invited_by_account_id
  52. object.user&.invite&.user&.account_id&.to_s&.presence
  53. end
  54. def invited?
  55. object.user&.invited?
  56. end
  57. def created_by_application?
  58. object.user&.created_by_application_id&.present?
  59. end
  60. def ips
  61. object.user&.ips
  62. end
  63. def ip
  64. ips&.first&.ip
  65. end
  66. end