account_serializer.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, :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_one :account, serializer: REST::AccountSerializer
  10. def id
  11. object.id.to_s
  12. end
  13. def email
  14. object.user_email
  15. end
  16. def ip
  17. object.user_current_sign_in_ip.to_s.presence
  18. end
  19. def role
  20. object.user_role
  21. end
  22. def suspended
  23. object.suspended?
  24. end
  25. def silenced
  26. object.silenced?
  27. end
  28. def confirmed
  29. object.user_confirmed?
  30. end
  31. def disabled
  32. object.user_disabled?
  33. end
  34. def approved
  35. object.user_approved?
  36. end
  37. def account
  38. object
  39. end
  40. def locale
  41. object.user_locale
  42. end
  43. def created_by_application_id
  44. object.user&.created_by_application_id&.to_s&.presence
  45. end
  46. def invite_request
  47. object.user&.invite_request&.text
  48. end
  49. def invited_by_account_id
  50. object.user&.invite&.user&.account_id&.to_s&.presence
  51. end
  52. def invited?
  53. object.user&.invited?
  54. end
  55. def created_by_application?
  56. object.user&.created_by_application_id&.present?
  57. end
  58. end