You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.4 KiB

  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_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 confirmed
  27. object.user_confirmed?
  28. end
  29. def disabled
  30. object.user_disabled?
  31. end
  32. def approved
  33. object.user_approved?
  34. end
  35. def account
  36. object
  37. end
  38. def locale
  39. object.user_locale
  40. end
  41. def created_by_application_id
  42. object.user&.created_by_application_id&.to_s&.presence
  43. end
  44. def invite_request
  45. object.user&.invite_request&.text
  46. end
  47. def invited_by_account_id
  48. object.user&.invite&.user&.account_id&.to_s&.presence
  49. end
  50. def invited?
  51. object.user&.invited?
  52. end
  53. def created_by_application?
  54. object.user&.created_by_application_id&.present?
  55. end
  56. def ips
  57. object.user&.ips
  58. end
  59. def ip
  60. ips&.first
  61. end
  62. end