Class: Pageflow::Editor::FilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pageflow/editor/files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/pageflow/editor/files_controller.rb', line 17

def create
  entry = DraftEntry.find(params[:entry_id])
  authorize!(:edit, entry.to_model)
  verify_edit_lock!(entry)

  @file = entry.create_file!(file_type, create_params)
  @file.publish! if params[:no_upload]

  respond_with(:editor, @file)
rescue ActiveRecord::RecordInvalid, DraftEntry::InvalidForeignKeyCustomAttributeError => e
  debug_log_with_backtrace(e)
  head :unprocessable_entity
end

#destroyObject



80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/pageflow/editor/files_controller.rb', line 80

def destroy
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:edit, entry.to_model)
  verify_edit_lock!(entry)
  entry.remove_file(file)

  head(:no_content)
end

#indexObject



8
9
10
11
12
13
14
15
# File 'app/controllers/pageflow/editor/files_controller.rb', line 8

def index
  entry = DraftEntry.find(params[:entry_id])

  authorize!(:use_files, entry.to_model)
  @files = entry.find_files(file_type.model)

  respond_with(:editor, @files)
end

#publishObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/pageflow/editor/files_controller.rb', line 60

def publish
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:update, file.to_model)
  file.publish!

  head(:no_content)
end

#retryObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/pageflow/editor/files_controller.rb', line 46

def retry
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:retry, file.to_model)
  file.retry!

  respond_with(:editor,
               file,
               location: editor_entry_file_url(file,
                                               entry,
                                               collection_name: params[:collection_name]))
end

#reuseObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/pageflow/editor/files_controller.rb', line 31

def reuse
  entry = DraftEntry.find(params[:entry_id])
  other_entry = DraftEntry.find(file_reuse_params[:other_entry_id])

  file_reuse = FileReuse.new(entry, other_entry, file_type, file_reuse_params[:file_id])

  authorize!(:edit, entry.to_model)
  authorize!(:use, file_reuse.file.to_model)
  verify_edit_lock!(entry)

  file_reuse.save!

  redirect_to(editor_entry_url(entry))
end

#updateObject



70
71
72
73
74
75
76
77
78
# File 'app/controllers/pageflow/editor/files_controller.rb', line 70

def update
  entry = DraftEntry.find(params[:entry_id])
  file = entry.find_file(file_type.model, params[:id])

  authorize!(:update, file.to_model)
  file.update_attributes!(update_params)

  head(:no_content)
end