Class: Decidim::CollaborativeTexts::DocumentsType

Inherits:
Decidim::Core::ComponentType show all
Defined in:
decidim-collaborative_texts/lib/decidim/api/documents_type.rb

Instance Method Summary collapse

Methods inherited from Decidim::Core::ComponentType

authorized?

Methods inherited from Api::Types::BaseObject

allowed_to?, authorized?, determine_subject_name, local_context, permission_chain

Instance Method Details

#collaborative_text(id:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'decidim-collaborative_texts/lib/decidim/api/documents_type.rb', line 27

def collaborative_text(id:)
  scope =
    if context[:current_user]&.admin?
      Document
    else
      Document.published
    end

  Decidim::Core::ComponentFinderBase.new(model_class: scope).call(object, { id: }, context)
end

#collaborative_texts(filter: {}, order: {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'decidim-collaborative_texts/lib/decidim/api/documents_type.rb', line 18

def collaborative_texts(filter: {}, order: {})
  base_query = Decidim::Core::ComponentListBase.new(model_class: Document).call(object, { filter:, order: }, context)
  if context[:current_user]&.admin?
    base_query
  else
    base_query.published
  end
end