aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin_controller.rb3
-rw-r--r--app/controllers/application_controller.rb13
-rw-r--r--app/controllers/request_controller.rb16
-rw-r--r--app/models/info_request.rb34
4 files changed, 41 insertions, 25 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 0bccd3358..0d83c9251 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -29,8 +29,7 @@ class AdminController < ApplicationController
FileUtils.rm_rf(cache_subpath)
# Remove any download zips
- download_dir = request_download_zip_dir(info_request)
- FileUtils.rm_rf(download_dir)
+ FileUtils.rm_rf(info_request.download_zip_dir)
# Remove the database caches of body / attachment text (the attachment text
# one is after privacy rules are applied)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 88b107861..902b43215 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -214,19 +214,6 @@ class ApplicationController < ActionController::Base
end
end
- def request_dirs(info_request)
- first_three_digits = info_request.id.to_s()[0..2]
- File.join(first_three_digits.to_s, info_request.id.to_s)
- end
-
- def request_download_zip_dir(info_request)
- File.join(download_zip_dir, "download", request_dirs(info_request))
- end
-
- def download_zip_dir()
- File.join(Rails.root, '/cache/zips/')
- end
-
# get the local locale
def locale_from_params(*args)
if params[:show_locale]
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 8b978cc01..e1fbb6a68 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -879,17 +879,13 @@ class RequestController < ApplicationController
if !@info_request.user_can_view?(@user)
return render_hidden
end
- @url_path = File.join("/download",
- request_dirs(@info_request),
- @info_request.last_update_hash,
- "#{params[:url_title]}.zip")
- file_path = File.expand_path(File.join(download_zip_dir(), @url_path))
- if !File.exists?(file_path)
- FileUtils.mkdir_p(File.dirname(file_path))
- make_request_zip(info_request, file_path)
- File.chmod(0644, file_path)
+ cache_file_path = @info_request.make_zip_cache_path(@user)
+ if !File.exists?(cache_file_path)
+ FileUtils.mkdir_p(File.dirname(cache_file_path))
+ make_request_zip(@info_request, cache_file_path)
+ File.chmod(0644, cache_file_path)
end
- redirect_to @url_path
+ send_file(cache_file_path, :filename => "#{@info_request.url_title}.zip")
end
end
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index cc3b58d2b..32e651ff9 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -958,6 +958,36 @@ public
find(:all, params)
end
+ def InfoRequest.download_zip_dir()
+ File.join(Rails.root, "cache", "zips", "#{Rails.env}")
+ end
+
+ def request_dirs
+ first_three_digits = id.to_s()[0..2]
+ File.join(first_three_digits.to_s, id.to_s)
+ end
+
+ def download_zip_dir
+ File.join(InfoRequest.download_zip_dir, "download", request_dirs)
+ end
+
+ def make_zip_cache_path(user)
+ cache_file_dir = File.join(InfoRequest.download_zip_dir(),
+ "download",
+ request_dirs,
+ last_update_hash)
+ cache_file_suffix = if all_can_view_all_correspondence?
+ ""
+ elsif Ability.can_view_with_prominence?('hidden', self, user)
+ "_hidden"
+ elsif Ability.can_view_with_prominence?('requester_only', self, user)
+ "_requester_only"
+ else
+ ""
+ end
+ File.join(cache_file_dir, "#{url_title}#{cache_file_suffix}.zip")
+ end
+
def is_old_unclassified?
!is_external? && awaiting_description && url_title != 'holding_pen' && get_last_response_event &&
Time.now > get_last_response_event.created_at + OLD_AGE_IN_DAYS
@@ -1031,6 +1061,10 @@ public
return false
end
+ def all_can_view_all_correspondence?
+ all_can_view? && incoming_messages.all?{ |message| message.all_can_view? }
+ end
+
def indexed_by_search?
if self.prominence == 'backpage' || self.prominence == 'hidden' || self.prominence == 'requester_only'
return false