• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

benwbrum / fromthepage / 24104516157

07 Apr 2026 09:08PM UTC coverage: 69.659% (-2.1%) from 71.79%
24104516157

push

github

web-flow
Merge pull request #5410 from benwbrum/5400-zero-byte-bulk-export-fix-part-1

5400 - Zero byte bulk export fix part 1

2404 of 3965 branches covered (60.63%)

Branch coverage included in aggregate %.

14 of 17 new or added lines in 5 files covered. (82.35%)

324 existing lines in 8 files now uncovered.

9932 of 13744 relevant lines covered (72.26%)

150.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.51
/app/controllers/bulk_export_controller.rb
1
class BulkExportController < ApplicationController
1✔
2
  before_action :require_logged_in
1✔
3
  before_action :set_bulk_export, only: [:show, :edit, :download]
1✔
4
  before_action :authorized?, except: [:new, :create, :create_for_work, :create_for_work_ajax, :create_for_owner]
1✔
5
  before_action :authorize_collection, only: [:new, :create, :create_for_work_ajax, :create_for_owner]
1✔
6

7
  PAGES_PER_SCREEN = 20
1✔
8

9
  def index
1✔
10
    @bulk_exports = BulkExport.all.order('id DESC').paginate page: params[:page], per_page: PAGES_PER_SCREEN
2✔
11
  end
12

13
  def show
1✔
14
  end
15

16
  def new
1✔
17
    @bulk_export = BulkExport.new
1✔
18
    if @collection.is_a? DocumentSet
1!
19
      @bulk_export.document_set = @collection
×
20
      @bulk_export.collection = @collection.collection
×
21
    else
1✔
22
      @bulk_export.collection = @collection
1✔
23
    end
24
    @uploaded_filename_available = @collection.works.where.not(uploaded_filename: nil).exists?
1✔
25
  end
26

27
  def create
1✔
28
    @bulk_export = BulkExport.new(bulk_export_params)
1✔
29
    if @collection.is_a? DocumentSet
1!
30
      @bulk_export.document_set = @collection
×
31
      @bulk_export.collection = @collection.collection
×
32
    else
1✔
33
      @bulk_export.collection = @collection
1✔
34
    end
35
    @bulk_export.work = @work if params[:work_id]
1!
36
    @bulk_export.user = current_user
1✔
37
    @bulk_export.status = :queued
1✔
38
    @bulk_export.report_arguments = bulk_export_params[:report_arguments].to_h
1✔
39

40
    if @bulk_export.save!
1!
41
      @bulk_export.submit_export_process
1✔
42

43
      # TODO: Once solid_queue worker contexts are figured out, bring this back
44
      # BulkExport::ProcessJob.perform_later(user_id: current_user.id, bulk_export_id: @bulk_export.id)
45

46
      flash[:info] = t('.export_running_message', email: (current_user.email))
1✔
47
    end
48
    redirect_to dashboard_exports_path
1✔
49
  end
50

51
  def create_for_work
1✔
52
    # i18n-tasks isn't smart enough to follow the method call here so we need to do this to get tests to pass
53
    throwaway = t('.export_running_message', email: (current_user.email))
×
54
    create_for_work_actual
×
55
    redirect_to dashboard_exports_path
×
56
  end
57

58

59
  def create_for_work_ajax
1✔
60
    create_for_work_actual
×
61
    ajax_redirect_to dashboard_exports_path
×
62
  end
63

64
  def create_for_owner
1✔
65
    @bulk_export = BulkExport.new(bulk_export_params)
×
66
    @bulk_export.user = current_user
×
67
    @bulk_export.status = :queued
×
68
    if bulk_export_params[:report_arguments]
×
69
      @bulk_export.report_arguments = bulk_export_params[:report_arguments].to_h
×
70
    end
71

72
    if @bulk_export.save
×
NEW
73
      @bulk_export.submit_export_process
×
74

75
      # TODO: Once solid_queue worker contexts are figured out, bring this back
76
      # BulkExport::ProcessJob.perform_later(user_id: current_user.id, bulk_export_id: @bulk_export.id)
77

78
      flash[:info] = t('.export_running_message', email: (current_user.email))
×
79
    end
80
    redirect_to dashboard_exports_path
×
81
  end
82

83
  # TODO: Deprecate
84
  # Keep for now for backsupport
85
  def download
1✔
86
    if @bulk_export.status.to_sym == :finished
×
87
      # read and spew the file
×
88
      send_file(@bulk_export.zip_file_name,
×
89
        filename: 'fromthepage_export.zip',
90
        content_type: 'application/zip')
91
      cookies['download_finished'] = 'true'
×
92
    else
×
93
      flash[:info] = t('.download_cleaned_message')
×
94
      redirect_to collection_export_path(@bulk_export.collection.owner, @bulk_export.collection)
×
95
    end
96
  end
97

98
  private
1✔
99

100
  # Use callbacks to share common setup or constraints between actions.
101
  def set_bulk_export
1✔
102
    @bulk_export = BulkExport.find(params[:bulk_export_id])
3✔
103
  end
104

105
  # Only allow a trusted parameter "white list" through.
106
  def bulk_export_params
1✔
107
    params.require(:bulk_export).permit(
2✔
108
      :user_id,
109
      :collection_id,
110
      :plaintext_verbatim_page,
111
      :plaintext_verbatim_work,
112
      :plaintext_emended_page,
113
      :plaintext_emended_work,
114
      :plaintext_searchable_page,
115
      :plaintext_searchable_work,
116
      :plaintext_verbatim_zero_index_page,
117
      :tei_work,
118
      :html_page,
119
      :html_work,
120
      :subject_csv_collection,
121
      :subject_details_csv_collection,
122
      :table_csv_work,
123
      :table_csv_collection,
124
      :work_metadata_csv,
125
      :facing_edition_work,
126
      :text_docx_work,
127
      :text_pdf_work,
128
      :text_only_pdf_work,
129
      :organization,
130
      :use_uploaded_filename,
131
      :static,
132
      :owner_mailing_list,
133
      :owner_detailed_activity,
134
      :collection_activity,
135
      :collection_contributors,
136
      :preserve_linebreaks,
137
      :work_id,
138
      :include_metadata,
139
      :include_contributors,
140
      :include_notes,
141
      :notes_csv,
142
      :admin_searches,
143
      :page_details_csv_work,
144
      :page_details_csv_collection,
145
      report_arguments: [
146
        :start_date,
147
        :end_date,
148
        :preserve_linebreaks,
149
        :include_metadata,
150
        :include_contributors,
151
        :include_notes
152
      ]
153
    )
154
  end
155

156
  def create_for_work_actual
1✔
157
    @bulk_export = BulkExport.new(bulk_export_params)
×
158
    if @collection.is_a? DocumentSet
×
159
      @bulk_export.document_set = @collection
×
160
      @bulk_export.collection = @collection.collection
×
161
    else
×
162
      @bulk_export.collection = @collection
×
163
    end
164
    @bulk_export.work = @work
×
165
    @bulk_export.user = current_user
×
166
    @bulk_export.status = :queued
×
167
    if bulk_export_params[:report_arguments]
×
168
      @bulk_export.report_arguments = bulk_export_params[:report_arguments].to_h
×
169
    end
170

171
    if @bulk_export.save
×
NEW
172
      @bulk_export.submit_export_process
×
173

174
      # TODO: Once solid_queue worker contexts are figured out, bring this back
175
      # BulkExport::ProcessJob.perform_later(user_id: current_user.id, bulk_export_id: @bulk_export.id)
176

177
      flash[:info] = t('.export_running_message', email: (current_user.email))
×
178
    end
179
  end
180

181
  def authorized?
1✔
182
    unless current_user.admin || @bulk_export&.user_id == current_user.id
6✔
183
      redirect_to main_app.dashboard_path
2✔
184
    end
185
  end
186

187
  def require_logged_in
1✔
188
    redirect_to main_app.dashboard_path unless user_signed_in?
10✔
189
  end
190
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc