serializable_agent.rb 1.4 KB
Newer Older
hellekin's avatar
hellekin committed
1 2
# frozen_string_literal: true

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# SerializableAgent is a special case of SerializableResource since an Agent's
# Agent is itself. So we don't inherit from SerializableResource to avoid
# complicating things. Beware though of changes in Resource model that might
# affect Agent as well.
class SerializableAgent < SerializableIncommonResource
  type 'agents'

  id { @object.uuid }

  # attribute :id

  # Mobility translations
  attribute :name
  attribute :summary
  attribute :description

hellekin's avatar
hellekin committed
19
  attribute :visible
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  # attribute :translations
  attribute :type
  # attribute :uuid

  attribute :created_at
  attribute :updated_at

  has_many :collections, unless: -> { restricted? }
  has_many :users,       if:     -> { leader? }

  has_many :roles do
    meta do
      {
        editor_count: @object.editors.count,
        maintainer_count: @object.maintainers.count,
        leader_count: @object.leaders.count,
        observer_count: @object.observers.count,
      }
    end
  end
  with_options if: -> { leader? } do
    has_many :editors
    has_many :maintainers
    has_many :observers
    has_many :leaders
  end

  with_options if: -> { maintainer? } do
    has_many :resource_addresses
    has_many :resource_emails
    has_many :resource_links
    has_many :origins
    has_many :resource_phones
    has_many :taxonomies
  end
hellekin's avatar
hellekin committed
55 56 57 58

  link :self do
    @url_helpers.api_agent_url(@object)
  end
59 60 61 62

  meta do
    meta_current
  end
hellekin's avatar
hellekin committed
63
end