-
Notifications
You must be signed in to change notification settings - Fork 344
/
csv_controller.rb
67 lines (49 loc) · 1.46 KB
/
csv_controller.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Admin
class CsvController < ApplicationController
before_action :authenticate_admin!
before_action :authorize_admin
# The CSV content for each action is defined in
# app/views/admin/csv/{action_name}.csv.shaper
def addresses; end
def contacts; end
def holiday_schedules; end
def locations; end
def mail_addresses; end
def organizations; end
def phones; end
def programs; end
def regular_schedules; end
def services; end
def all
redirect_to :back,
notice: I18n.t('admin.notices.zip_file_generation')
ZipDownloadJob.perform_in(2, tmp_file_name, url_prefix)
end
def download_zip
if File.exist?(tmp_file_name)
send_file tmp_file_name,
type: 'application/zip',
filename: zip_file_name,
x_sendfile: true
ZipDeleteJob.perform_in(60, tmp_file_name)
else
redirect_to admin_dashboard_url,
notice: I18n.t('admin.notices.wait_for_zip_file')
end
end
private
def authorize_admin
return if current_admin.super_admin?
user_not_authorized
end
def tmp_file_name
@tmp_file_name ||= Rails.root.join('tmp', 'archive.zip')
end
def zip_file_name
"archive-#{Time.zone.today.to_formatted_s}.zip"
end
def url_prefix
@url_prefix ||= "#{admin_dashboard_url(subdomain: ENV['ADMIN_SUBDOMAIN'])}/csv/"
end
end
end