account_serializer.rb 1.4 KB

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