Module: Collavre::Concerns::Exportable

Extended by:
ActiveSupport::Concern
Included in:
Collavre::CreativesController
Defined in:
app/controllers/collavre/concerns/exportable.rb

Instance Method Summary collapse

Instance Method Details

#export_markdownObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/collavre/concerns/exportable.rb', line 6

def export_markdown
  creatives = if params[:parent_id]
    parent_creative = Creative.find(params[:parent_id])
    effective_origin = parent_creative.effective_origin
    unless parent_creative.has_permission?(Current.user, :read) &&
           effective_origin.has_permission?(Current.user, :read)
      render plain: t("collavre.creatives.errors.no_permission"), status: :forbidden and return
    end
    [ effective_origin ]
  else
    Creative.where(parent_id: nil).map(&:effective_origin).uniq.select do |creative|
      creative.has_permission?(Current.user, :read)
    end
  end

  if creatives.empty?
    render plain: t("collavre.creatives.errors.no_permission"), status: :forbidden and return
  end

  markdown = helpers.render_creative_tree_markdown(creatives)
  send_data markdown, filename: "creatives.md", type: "text/markdown"
end