aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/import_resources_controller.rb
blob: 46f8f03379a0f4de8b7ec6ebaefe6ab189bc2496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class ImportResourcesController < ChouetteController
  defaults resource_class: Import::Resource, collection_name: 'import_resources', instance_name: 'import_resource'
  respond_to :html
  belongs_to :import, :parent_class => Import::Base

  def index
    index! do |format|
      format.html {
        @import_resources = decorate_import_resources(@import_resources)
      }
    end
  end

  def download
    if params[:token] == resource.token_download
      send_file resource.file.path
    else
      user_not_authorized
    end
  end

  protected
  def collection
    @import_resources ||= parent.resources
  end

  def resource
    @import ||= Import::Base.find params[:import_id]
    @import_resource ||= begin
      import_resource = Import::Resource.find params[:id]
      raise ActiveRecord::RecordNotFound unless import_resource.import == @import
      import_resource
    end
  end

  private

  def decorate_import_resources(import_resources)
    ImportResourcesDecorator.decorate(import_resources)
  end
end